euv_ui/component/dropdown/view/struct.rs
1use super::*;
2
3/// Geometry supplied by the selected menu class, independent of the DOM.
4#[cfg(any(target_arch = "wasm32", test))]
5#[derive(Clone, Copy, CustomDebug, Data)]
6pub(crate) struct DropdownGeometryPolicy {
7 /// Align the popup's leading edge rather than its trailing edge.
8 #[get(pub(crate), type(copy))]
9 pub(crate) align_start: bool,
10 /// Use the trigger instead of the encompassing root for horizontal placement.
11 #[get(pub(crate), type(copy))]
12 pub(crate) anchor_trigger: bool,
13 /// Size to the content instead of matching the horizontal anchor.
14 #[get(pub(crate), type(copy))]
15 pub(crate) content_width: bool,
16 /// Distance from the trigger in viewport pixels.
17 #[get(pub(crate), type(copy))]
18 pub(crate) gap: f64,
19}
20
21/// One entry of the [`euv_dropdown`] menu.
22///
23/// Carries the display label and the opaque value handed to `on_select`.
24#[derive(Clone, Copy, CustomDebug, Data, Default, New)]
25pub struct EuvDropdownItem {
26 /// The display label.
27 #[get(type(copy))]
28 pub label: &'static str,
29 /// The opaque value passed to the select callback.
30 #[get(type(copy))]
31 pub value: &'static str,
32 /// Whether this item is the currently selected value.
33 ///
34 /// Drives the `_active` class: the accent fill and the `text-on-accent`
35 /// label colour, matching how `euv_sidebar` marks the current page.
36 /// Defaults to `false`, so existing call sites keep the neutral look.
37 #[get(type(copy))]
38 pub active: bool,
39 /// Whether this row is unavailable for focus and selection.
40 #[get(type(copy))]
41 pub disabled: bool,
42}
43
44/// Props for the [`euv_dropdown`] component.
45///
46/// The open state is owned by the caller so the trigger (passed as children)
47/// can toggle it; selecting an item closes the menu.
48#[derive(Clone, CustomDebug, Default)]
49pub struct EuvDropdownProps {
50 /// The open state signal toggled by the trigger children.
51 pub open: Signal<bool>,
52 /// The menu items.
53 pub items: Vec<EuvDropdownItem>,
54 /// Optional select callback receiving the chosen item value.
55 #[debug(skip)]
56 pub on_select: Option<Rc<dyn Fn(&'static str)>>,
57}
58
59/// Props for a composable dropdown root. Use the same signal for its trigger and content.
60#[derive(Clone, CustomDebug, Default)]
61pub struct EuvDropdownMenuProps {
62 /// Whether the owning menu is open.
63 pub open: Signal<bool>,
64 /// Optional owning surface state; closing it resets this menu and its descendants.
65 /// This lifecycle parent is not a menu level and is never dismissed by menu actions.
66 pub parent_open: Option<Signal<bool>>,
67}
68
69/// Props for the always-mounted composable dropdown popup.
70#[derive(Clone, CustomDebug, Default)]
71pub struct EuvDropdownMenuContentProps {
72 /// The open state shared with the root and trigger.
73 pub open: Signal<bool>,
74}
75
76/// Props of the [`euv_dropdown_trigger`] component.
77///
78/// The trigger carries the open state of the menu it opens, so it can
79/// report that state to a reader.
80#[derive(Clone, CustomDebug, Default)]
81pub struct EuvDropdownTriggerProps {
82 /// Whether the menu is open.
83 pub open: Signal<bool>,
84}
85
86/// Props of the [`euv_dropdown_menu_group`] component.
87///
88/// The group holds the rows that belong to one heading.
89#[derive(Clone, Copy, CustomDebug, Default)]
90pub struct EuvDropdownMenuGroupProps {
91 /// The accessible name of the group.
92 pub label: &'static str,
93}
94
95/// Props of the [`euv_dropdown_menu_checkbox_item`] component.
96///
97/// The row carries a box the reader ticks.
98#[derive(Clone, CustomDebug, Default)]
99pub struct EuvDropdownMenuCheckboxItemProps {
100 /// The label shown inside the row.
101 pub label: &'static str,
102 /// Whether the box is ticked.
103 pub checked: Signal<bool>,
104 /// Whether the row ignores focus and activation.
105 pub disabled: bool,
106 /// The owning menu's open state when close-on-click is requested.
107 pub open: Signal<bool>,
108 /// Whether activation closes the owning menu. Defaults to false.
109 pub close_on_click: bool,
110 /// Called once with the new checked value after activation.
111 #[debug(skip)]
112 pub on_checked_change: Option<Rc<dyn Fn(bool)>>,
113}
114
115/// Props of the [`euv_dropdown_menu_radio_group`] component.
116///
117/// The group holds the rows that share one radio selection.
118#[derive(Clone, CustomDebug, Default)]
119pub struct EuvDropdownMenuRadioGroupProps {
120 /// The accessible name of the group.
121 pub label: &'static str,
122 /// Shared selection handle, also passed explicitly to every radio item.
123 pub selection: EuvDropdownMenuRadioGroupState,
124}
125
126/// Explicit shared selection created by [`use_dropdown_menu_radio_group`].
127///
128/// Clone this handle into the group and each item; no inherited context is used.
129#[derive(Clone, CustomDebug, Default)]
130pub struct EuvDropdownMenuRadioGroupState {
131 /// The single source of truth for this group's selected value.
132 pub value: Signal<String>,
133 /// Whether only the caller may update the value signal.
134 pub controlled: bool,
135 /// Requests a different value, after updating an uncontrolled signal.
136 #[debug(skip)]
137 pub on_value_change: Option<Rc<dyn Fn(String)>>,
138}
139
140/// Props of the [`euv_dropdown_menu_radio_item`] component.
141///
142/// The row carries a dot the reader moves.
143#[derive(Clone, CustomDebug, Default)]
144pub struct EuvDropdownMenuRadioItemProps {
145 /// The label shown inside the row.
146 pub label: &'static str,
147 /// Unique value within the containing group.
148 pub value: &'static str,
149 /// The same handle passed to the containing radio group.
150 pub selection: EuvDropdownMenuRadioGroupState,
151 /// Whether activation and keyboard navigation skip this item.
152 pub disabled: bool,
153 /// The owning dropdown's open signal.
154 pub open: Signal<bool>,
155 /// Whether activation closes the menu, even for the selected value. Defaults to false.
156 pub close_on_click: bool,
157}
158
159/// Props of the [`euv_dropdown_menu_sub`] component.
160///
161/// The sub-menu holds the rows of a nested menu.
162#[derive(Clone, Copy, CustomDebug, Default)]
163pub struct EuvDropdownMenuSubProps {
164 /// Optional descriptive label retained for compatibility.
165 pub label: &'static str,
166 /// This submenu's distinct controlled open state.
167 pub open: Signal<bool>,
168 /// Immediate parent popup state; closing it resets this entire branch.
169 pub parent_open: Signal<bool>,
170}
171
172/// Props of the [`euv_dropdown_menu_sub_trigger`] component.
173#[derive(Clone, Copy, CustomDebug)]
174pub struct EuvDropdownMenuSubTriggerProps {
175 /// The label shown inside the row.
176 pub label: &'static str,
177 /// Whether the sub-menu is open.
178 pub open: Signal<bool>,
179 /// Whether native activation and menu navigation skip this trigger.
180 pub disabled: bool,
181 /// Whether a hover-capable pointer opens this submenu. Defaults to true.
182 pub open_on_hover: bool,
183 /// Hover entry delay in milliseconds. Defaults to 100.
184 pub delay_ms: u32,
185 /// Hover dismissal delay in milliseconds. Defaults to zero.
186 pub close_delay_ms: u32,
187}
188
189/// Props of the [`euv_dropdown_menu_sub_content`] component.
190#[derive(Clone, Copy, CustomDebug, Default)]
191pub struct EuvDropdownMenuSubContentProps {
192 /// Whether the sub-menu is open.
193 pub open: Signal<bool>,
194}
195
196/// Props of the [`euv_dropdown_menu_item`] component.
197///
198/// A menu item is the leaf of a menu: it carries the label the reader
199/// sees, the key hint shown at its trailing edge, and the value handed
200/// back when it is chosen.
201#[derive(Clone, CustomDebug, Data, New)]
202pub struct EuvDropdownMenuItemProps {
203 /// The label shown inside the item.
204 #[get(type(copy))]
205 pub label: &'static str,
206 /// The key hint shown at the trailing edge of the item.
207 #[get(type(copy))]
208 pub shortcut: &'static str,
209 /// The opaque value handed to the select callback.
210 #[get(type(copy))]
211 pub value: &'static str,
212 /// Whether the item is disabled.
213 #[get(type(copy))]
214 pub disabled: bool,
215 /// Optional select callback receiving the chosen value.
216 #[debug(skip)]
217 pub on_select: Option<Rc<dyn Fn(&'static str)>>,
218 /// The owning root menu's open state, including for recursive submenu actions.
219 /// Share this root signal with all action rows; submenu signals control panels only.
220 pub open: Signal<bool>,
221 /// Whether activation closes the owning menu. Defaults to true.
222 #[get(type(copy))]
223 pub close_on_click: bool,
224}
225
226/// Props of the [`euv_dropdown_menu_label`] component.
227#[derive(Clone, Copy, CustomDebug, Data, Default, New)]
228pub struct EuvDropdownMenuLabelProps {
229 /// The text of the group heading.
230 #[get(type(copy))]
231 pub text: &'static str,
232}
233
234/// Props of the [`euv_dropdown_menu_separator`] component.
235#[derive(Clone, Copy, CustomDebug, Data, Default, New)]
236pub struct EuvDropdownMenuSeparatorProps {
237 /// The label reported to assistive technology, if any.
238 #[get(type(copy))]
239 pub label: &'static str,
240}
241
242/// Props of the [`euv_dropdown_menu_shortcut`] component.
243#[derive(Clone, Copy, CustomDebug, Data, Default, New)]
244pub struct EuvDropdownMenuShortcutProps {
245 /// The key hint text.
246 #[get(type(copy))]
247 pub text: &'static str,
248}
249
250/// Lifecycle-owned submenu hover controller. All asynchronous callbacks hold Weak handles.
251#[cfg(target_arch = "wasm32")]
252#[derive(Data)]
253pub(super) struct DropdownSubHover {
254 #[get(pub(super))]
255 #[set(pub(super))]
256 #[get_mut(pub(super))]
257 pub(super) open: Signal<bool>,
258 #[get(pub(super))]
259 #[set(pub(super))]
260 #[get_mut(pub(super))]
261 pub(super) parent: Rc<Cell<Signal<bool>>>,
262 #[get(pub(super))]
263 #[set(pub(super))]
264 #[get_mut(pub(super))]
265 pub(super) target: NodeRef<Element>,
266 #[get(pub(super))]
267 #[set(pub(super))]
268 #[get_mut(pub(super))]
269 pub(super) options: Cell<(bool, bool, u32, u32)>,
270 #[get(pub(super))]
271 #[set(pub(super))]
272 #[get_mut(pub(super))]
273 pub(super) mounted: Cell<bool>,
274 #[get(pub(super))]
275 #[set(pub(super))]
276 #[get_mut(pub(super))]
277 pub(super) timer: Cell<Option<i32>>,
278 #[get(pub(super))]
279 #[set(pub(super))]
280 #[get_mut(pub(super))]
281 pub(super) intent: Cell<Option<bool>>,
282 #[get(pub(super))]
283 #[set(pub(super))]
284 #[get_mut(pub(super))]
285 pub(super) anchor: Cell<Option<(f64, f64)>>,
286 #[get(pub(super))]
287 #[set(pub(super))]
288 #[get_mut(pub(super))]
289 pub(super) callback: RefCell<Option<Closure<dyn FnMut()>>>,
290}