euv_ui/component/auto_complete/view/struct.rs
1use super::*;
2
3/// One suggestion offered by the [`euv_auto_complete`] component.
4///
5/// The `value` is what lands in the field when the suggestion is picked,
6/// while the `label` is what the user reads in the suggestion list.
7#[derive(Clone, Copy, CustomDebug, Data, Default, New)]
8pub struct EuvAutoCompleteOption {
9 /// The value written into the field when the option is picked.
10 #[get(type(copy))]
11 pub value: &'static str,
12 /// The text shown in the suggestion list.
13 #[get(type(copy))]
14 pub label: &'static str,
15}
16
17/// Props for the [`euv_auto_complete`] component.
18///
19/// The text in the field lives in a caller-owned [`Signal`] so the component
20/// takes part in two-way binding; the open state of the suggestion panel is
21/// owned by the component itself.
22#[derive(Clone, CustomDebug, Default)]
23pub struct EuvAutoCompleteProps {
24 /// The suggestions offered to the user.
25 pub options: Vec<EuvAutoCompleteOption>,
26 /// The text currently held by the field.
27 pub value: Signal<String>,
28 /// The placeholder shown while the field is empty.
29 pub placeholder: &'static str,
30 /// The label rendered above the field.
31 ///
32 /// An empty string renders the field without a label.
33 pub label: &'static str,
34 /// The callback invoked with the typed text after every change.
35 ///
36 /// The text is handed over as a `'static` slice, so the component
37 /// leaks one small string per distinct value the user types.
38 #[debug(skip)]
39 pub on_change: Option<Rc<dyn Fn(&'static str)>>,
40 /// The callback invoked with the value of the picked suggestion.
41 #[debug(skip)]
42 pub on_select: Option<Rc<dyn Fn(&'static str)>>,
43}