use crate::icons::lucide_icon::LucideIcon;
#[derive(Clone, Debug)]
pub struct CommandItem {
pub group: String,
pub group_icon: LucideIcon,
pub label: String,
pub icon: LucideIcon,
}
impl From<(String, String)> for CommandItem {
fn from((group, label): (String, String)) -> Self {
Self {
group,
group_icon: LucideIcon::Component,
label,
icon: LucideIcon::Component,
}
}
}
#[must_use]
pub struct Command {
pub(crate) items: Vec<CommandItem>,
pub(crate) placeholder: String,
}
impl Command {
pub fn new(items: Vec<(String, String)>) -> Self {
Self {
items: items.into_iter().map(CommandItem::from).collect(),
placeholder: "Type a command or search...".to_owned(),
}
}
pub fn with_items(items: Vec<CommandItem>) -> Self {
Self {
items,
placeholder: "Type a command or search...".to_owned(),
}
}
pub fn placeholder(mut self, text: impl Into<String>) -> Self {
self.placeholder = text.into();
self
}
}
#[must_use]
pub struct CommandValue<T: Clone> {
pub(crate) entries: Vec<(T, CommandItem)>,
pub(crate) placeholder: String,
}
impl<T: Clone> CommandValue<T> {
pub fn new(entries: Vec<(T, CommandItem)>) -> Self {
Self {
entries,
placeholder: "Type a command or search...".to_owned(),
}
}
pub fn placeholder(mut self, text: impl Into<String>) -> Self {
self.placeholder = text.into();
self
}
}