1
//! Data attribute definitions for autocomplete components.
2
//!
3
//! This module provides a single source of truth for HTML data attribute names
4
//! used by autocomplete components. Both the WASM frontend (reader) and the web
5
//! server templates (writer) use these definitions to ensure consistency.
6

            
7
/// Attribute names for autocomplete components.
8
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9
pub enum AutocompleteAttr {
10
    /// The type of autocomplete (e.g., "account", "tag-name", "tag-value")
11
    Type,
12
    /// URL to fetch suggestions from
13
    FetchUrl,
14
    /// ID of the visible display input field
15
    DisplayInput,
16
    /// ID of the hidden value input field
17
    HiddenInput,
18
    /// ID of the dependency input (for dependent autocompletes like tag-value)
19
    DependsOn,
20
    /// Marker attribute indicating the component is initialized
21
    Initialized,
22
    /// Index for suggestion items in the dropdown
23
    Index,
24
}
25

            
26
impl AutocompleteAttr {
27
    /// Returns the HTML attribute name as a string slice.
28
    #[must_use]
29
7
    pub const fn as_str(self) -> &'static str {
30
7
        match self {
31
1
            Self::Type => "data-autocomplete",
32
1
            Self::FetchUrl => "data-fetch-url",
33
1
            Self::DisplayInput => "data-display-input",
34
1
            Self::HiddenInput => "data-hidden-input",
35
1
            Self::DependsOn => "data-depends-on",
36
1
            Self::Initialized => "data-initialized",
37
1
            Self::Index => "data-index",
38
        }
39
7
    }
40
}
41

            
42
/// CSS selectors used by autocomplete components.
43
pub mod selectors {
44
    /// Selector for the autocomplete results container
45
    pub const RESULTS_CONTAINER: &str = ".autocomplete-results";
46
}
47

            
48
/// Values for the autocomplete type attribute.
49
pub mod autocomplete_type {
50
    /// Account autocomplete type
51
    pub const ACCOUNT: &str = "account";
52
    /// Tag name autocomplete type
53
    pub const TAG_NAME: &str = "tag-name";
54
    /// Tag value autocomplete type (depends on tag-name)
55
    pub const TAG_VALUE: &str = "tag-value";
56
}
57

            
58
#[cfg(test)]
59
#[path = "data_attrs_tests.rs"]
60
mod tests;