Skip to main content

euv_ui/component/select/view/
struct.rs

1use super::*;
2
3/// One entry of the [`euv_select`] option list.
4///
5/// Carries the machine value written into the selection signal, the label
6/// the user reads, the caption of the group the option belongs to, and
7/// whether the option can be picked at all.
8#[derive(Clone, Copy, CustomDebug, Data, Default, New)]
9pub struct EuvSelectOption {
10    /// The machine value written into the selection signal when picked.
11    #[get(type(copy))]
12    pub value: &'static str,
13    /// The display label shown for this option.
14    #[get(type(copy))]
15    pub label: &'static str,
16    /// The caption of the group this option belongs to.
17    ///
18    /// An empty caption places the option in the ungrouped block at the
19    /// top of the panel, which is rendered without a caption row.
20    #[get(type(copy))]
21    pub group: &'static str,
22    /// Whether the option is disabled.
23    ///
24    /// A disabled option is drawn with the muted treatment and cannot be
25    /// picked, so it never writes into the selection signal.
26    #[get(type(copy))]
27    pub disabled: bool,
28}
29
30/// Props for the [`euv_select`] component.
31///
32/// The selection lives in a caller-owned `Signal<String>` so the select
33/// takes part in two-way binding with the rest of the page. The open state
34/// of the option panel is owned by the component itself, so the caller
35/// never has to wire it up.
36#[derive(Clone, CustomDebug, Default)]
37pub struct EuvSelectProps {
38    /// The signal holding the currently selected option value.
39    pub value: Signal<String>,
40    /// The options rendered in the panel, in display order.
41    pub options: Vec<EuvSelectOption>,
42    /// The text shown in the trigger while no option is selected.
43    pub placeholder: &'static str,
44    /// The group label above the trigger; an empty label renders no label.
45    pub label: &'static str,
46    /// Whether the whole control is disabled.
47    pub disabled: bool,
48    /// Optional callback receiving the value of the picked option.
49    #[debug(skip)]
50    pub on_change: Option<Rc<dyn Fn(&'static str)>>,
51}