use super::*;
#[component]
pub fn euv_command(node: VirtualNode<EuvCommandProps>) -> VirtualNode {
let EuvCommandProps {
value: _value,
label,
}: EuvCommandProps = node.try_get_props().unwrap_or_default();
let children: VirtualNode = node.get_children().into();
let base_class: &Css = c_euv_command();
html! {
div {
role: "group"
"aria-label": label
class: base_class
"data-slot": "command"
children
}
}
}
#[component]
pub fn euv_command_input(node: VirtualNode<EuvCommandInputProps>) -> VirtualNode {
let EuvCommandInputProps {
value,
placeholder,
disabled,
}: EuvCommandInputProps = node.try_get_props().unwrap_or_default();
let disabled_signal: Signal<bool> = Signal::create(disabled);
let text: String = value.get();
html! {
div {
class: c_euv_command_input_wrapper()
"data-slot": "command-input-wrapper"
input {
type: "text"
role: "combobox"
"aria-expanded": "true"
value: text
placeholder: placeholder
disabled: disabled_signal
class: c_euv_command_input()
"data-slot": "command-input"
oninput: on_command_input(value)
}
}
}
}
fn on_command_input(value: Signal<String>) -> Option<Rc<dyn Fn(Event)>> {
Some(Rc::new(move |event: Event| {
let Some(target) = event.target() else {
return;
};
let Ok(input) = target.dyn_into::<HtmlInputElement>() else {
return;
};
value.set(input.value());
}))
}
#[component]
pub fn euv_command_list(node: VirtualNode<EuvCommandListProps>) -> VirtualNode {
let EuvCommandListProps { label }: EuvCommandListProps =
node.try_get_props().unwrap_or_default();
let children: VirtualNode = node.get_children().into();
html! {
div {
role: "listbox"
"aria-label": label
class: c_euv_command_list()
"data-slot": "command-list"
children
}
}
}
#[component]
pub fn euv_command_empty(node: VirtualNode<EuvCommandEmptyProps>) -> VirtualNode {
let EuvCommandEmptyProps { text }: EuvCommandEmptyProps =
node.try_get_props().unwrap_or_default();
html! {
div {
class: c_euv_command_empty()
"data-slot": "command-empty"
{
text
}
}
}
}
#[component]
pub fn euv_command_group(node: VirtualNode<EuvCommandGroupProps>) -> VirtualNode {
let EuvCommandGroupProps { heading }: EuvCommandGroupProps =
node.try_get_props().unwrap_or_default();
let children: VirtualNode = node.get_children().into();
html! {
div {
role: "group"
class: c_euv_command_group()
"data-slot": "command-group"
div {
class: c_euv_command_group_heading()
{
heading
}
}
children
}
}
}
#[component]
pub fn euv_command_item(node: VirtualNode<EuvCommandItemProps>) -> VirtualNode {
let EuvCommandItemProps {
value,
label,
selected,
disabled,
on_select,
}: EuvCommandItemProps = node.try_get_props().unwrap_or_default();
let children: VirtualNode = node.get_children().into();
let item_class: fn() -> &'static Css = if disabled {
c_euv_command_item_disabled
} else if selected {
c_euv_command_item_selected
} else {
c_euv_command_item
};
let on_click: Option<Rc<dyn Fn(Event)>> = if disabled {
None
} else {
Some(Rc::new(move |_: Event| {
if let Some(callback) = &on_select {
callback(value);
}
}))
};
html! {
div {
role: "option"
"aria-selected": if selected { "true" } else { "false" }
"aria-disabled": if disabled { "true" } else { "false" }
class: command_item_class(item_class)
"data-slot": "command-item"
onclick: on_click
{ label }
children
}
}
}
#[component]
pub fn euv_command_separator(node: VirtualNode<EuvCommandSeparatorProps>) -> VirtualNode {
let EuvCommandSeparatorProps { label }: EuvCommandSeparatorProps =
node.try_get_props().unwrap_or_default();
html! {
div {
role: "separator"
class: c_euv_command_separator()
"data-slot": "command-separator"
"aria-label": label
}
}
}
#[component]
pub fn euv_command_shortcut(node: VirtualNode<EuvCommandShortcutProps>) -> VirtualNode {
let EuvCommandShortcutProps { text }: EuvCommandShortcutProps =
node.try_get_props().unwrap_or_default();
html! {
span {
class: c_euv_command_shortcut()
"data-slot": "command-shortcut"
{
text
}
}
}
}
fn command_item_class(state_class: fn() -> &'static Css) -> String {
let base_class: &str = c_euv_command_item().get_name();
let mut class_name: String = String::with_capacity(64);
class_name.push_str(base_class);
class_name.push(' ');
class_name.push_str(state_class().get_name());
class_name
}