dioxus_nox_select/types.rs
1use std::sync::atomic::{AtomicU32, Ordering};
2
3use dioxus_nox_collection::ListItem;
4
5pub(crate) static INSTANCE_COUNTER: AtomicU32 = AtomicU32::new(0);
6
7pub(crate) fn next_instance_id() -> u32 {
8 INSTANCE_COUNTER.fetch_add(1, Ordering::Relaxed)
9}
10
11// ── AutoComplete ────────────────────────────────────────────────────────────
12
13/// Controls the autocomplete behaviour of an editable combobox.
14#[derive(Clone, Copy, Default, PartialEq, Debug)]
15pub enum AutoComplete {
16 /// No autocomplete. Popup shows all items regardless of input.
17 #[default]
18 None,
19 /// Filter the list based on input text.
20 List,
21 /// Filter the list AND provide inline completion in the input.
22 Both,
23}
24
25impl AutoComplete {
26 /// Value for the `aria-autocomplete` attribute.
27 pub fn as_aria_attr(&self) -> &'static str {
28 match self {
29 Self::None => "none",
30 Self::List => "list",
31 Self::Both => "both",
32 }
33 }
34}
35
36// ── ItemEntry ───────────────────────────────────────────────────────────────
37
38/// Registration entry for a single select option.
39#[derive(Clone, PartialEq, Debug)]
40pub struct ItemEntry {
41 /// Unique value identifying this option.
42 pub value: String,
43 /// Human-readable label used for display and fuzzy matching.
44 pub label: String,
45 /// Additional keywords for fuzzy matching (space-separated).
46 pub keywords: String,
47 /// Whether this option is disabled.
48 pub disabled: bool,
49 /// Optional group this option belongs to.
50 pub group_id: Option<String>,
51}
52
53impl ListItem for ItemEntry {
54 fn value(&self) -> &str {
55 &self.value
56 }
57 fn label(&self) -> &str {
58 &self.label
59 }
60 fn keywords(&self) -> &str {
61 &self.keywords
62 }
63 fn disabled(&self) -> bool {
64 self.disabled
65 }
66 fn group_id(&self) -> Option<&str> {
67 self.group_id.as_deref()
68 }
69}
70
71// ── GroupEntry ───────────────────────────────────────────────────────────────
72
73/// Registration entry for an option group.
74#[derive(Clone, PartialEq, Debug)]
75pub struct GroupEntry {
76 /// Unique group identifier.
77 pub id: String,
78 /// Optional heading for the group.
79 pub label: Option<String>,
80}
81
82// ── ScoredItem & CustomFilter ────────────────────────────────────────────────
83
84// Re-exported from dioxus-nox-collection.
85pub use dioxus_nox_collection::{CustomFilter, ScoredItem};