singlestage/components/badge/
mod.rs

1use leptos::prelude::*;
2
3#[component]
4pub fn Badge(
5    children: Children,
6
7    // GLOBAL ATTRIBUTES
8    //
9    /// A space separated list of keys to focus this element. The first key available on the user's
10    /// keyboard layout is used.
11    #[prop(optional, into)]
12    accesskey: MaybeProp<String>,
13    /// Sets whether the input value should be capitalized and how. If a parent `<form>` has
14    /// `autocapitalize` rules set, it will override any rules set here.
15    ///
16    /// Accepted values: "none" or "off" | "sentences" or "on" | "words" | "characters".
17    #[prop(optional, into)]
18    autocapitalize: MaybeProp<String>,
19    /// Grabs focus once the page has finished loading. Only one element on the page can be focused
20    /// at a time.
21    #[prop(optional, into)]
22    autofocus: MaybeProp<bool>,
23    /// Apply classes to the element.
24    #[prop(optional, into)]
25    class: MaybeProp<String>,
26    /// Allows client-side editing of the element by the user.
27    ///
28    /// Accepted values: "true" | "false" | "plaintext-only"
29    #[prop(optional, into)]
30    contenteditable: MaybeProp<String>,
31    /// Indicate directionality of the element's text.
32    ///
33    /// Accepted values: "ltr" | "rtl" | "auto"
34    #[prop(optional, into)]
35    dir: MaybeProp<String>,
36    /// Toggle whether the element can be dragged.
37    #[prop(optional, into)]
38    draggable: MaybeProp<bool>,
39    /// Modifies the appearance of the enter key on virtual keyboards.
40    #[prop(optional, into)]
41    enterkeyhint: MaybeProp<String>,
42    /// Expose elements in the shadow DOM to be manipulated by the DOM.
43    #[prop(optional, into)]
44    exportparts: MaybeProp<String>,
45    /// Controls hidden status of the element.
46    #[prop(optional, into)]
47    hidden: MaybeProp<String>,
48    /// Set the id of this element.
49    #[prop(optional, into)]
50    id: MaybeProp<String>,
51    /// Toggle if the browser reacts to input events from this element.
52    #[prop(optional, into)]
53    inert: MaybeProp<bool>,
54    /// Hints to the browser of what type of virtual keyboard to display when editing this element
55    /// or its children.
56    #[prop(optional, into)]
57    inputmode: MaybeProp<String>,
58    /// Used to render a standard element as a custom element.
59    #[prop(optional, into)]
60    is: MaybeProp<String>,
61    /// Unique global identifier of an item.
62    #[prop(optional, into)]
63    itemid: MaybeProp<String>,
64    /// Used to add properties to an item.
65    #[prop(optional, into)]
66    itemprop: MaybeProp<String>,
67    /// Used to associate an item with a related non-parent element that's using `itemscope`.
68    #[prop(optional, into)]
69    itemref: MaybeProp<String>,
70    /// Used to declare that children elements are related to a particular item.
71    #[prop(optional, into)]
72    itemscope: MaybeProp<String>,
73    /// URL of data used to define `itemprops`.
74    #[prop(optional, into)]
75    itemtype: MaybeProp<String>,
76    /// Defines the language of an element.
77    #[prop(optional, into)]
78    lang: MaybeProp<String>,
79    /// Cryptographic "number used once".
80    #[prop(optional, into)]
81    nonce: MaybeProp<String>,
82    /// List of the part names of the element.
83    #[prop(optional, into)]
84    part: MaybeProp<String>,
85    /// Designate an element as a popover element.
86    #[prop(optional, into)]
87    popover: MaybeProp<String>,
88    /// Define the semantic meaning of content.
89    #[prop(optional, into)]
90    role: MaybeProp<String>,
91    /// Assigns a slot to an element.
92    #[prop(optional, into)]
93    slot: MaybeProp<String>,
94    /// Toggle spellcheck for this input.
95    ///
96    /// Accepted values: "default" | "true" | "false".
97    #[prop(optional, into)]
98    spellcheck: MaybeProp<String>,
99    /// Define CSS to be applied to the element.
100    #[prop(optional, into)]
101    style: MaybeProp<String>,
102    /// Controls how an element behaves when a user navigates using the tab key.
103    #[prop(optional, into)]
104    tabindex: MaybeProp<usize>,
105    /// Describes the content of the element to screen readers.
106    #[prop(optional, into)]
107    title: MaybeProp<String>,
108    /// Defines localization behavior for the element.
109    #[prop(optional, into)]
110    translate: MaybeProp<String>,
111
112    /// Define the badge variant. Defaults to `"primary"`.
113    /// Variants: "primary" | "secondary" | "destructive" | "outline"
114    #[prop(optional, into)]
115    variant: MaybeProp<String>,
116) -> impl IntoView {
117    let global_attrs_1 = view! {
118        <{..}
119            accesskey=move || accesskey.get()
120            autocapitalize=move || autocapitalize.get()
121            autofocus=move || autofocus.get()
122            // class=move || class.get()
123            contenteditable=move || contenteditable.get()
124            dir=move || dir.get()
125            draggable=move || draggable.get()
126            enterkeyhint=move || enterkeyhint.get()
127            exportparts=move || exportparts.get()
128            hidden=move || hidden.get()
129            id=move || id.get()
130            inert=move || inert.get()
131            inputmode=move || inputmode.get()
132            is=move || is.get()
133            itemid=move || itemid.get()
134        />
135    };
136
137    let global_attrs_2 = view! {
138        <{..}
139            itemprop=move || itemprop.get()
140            itemref=move || itemref.get()
141            itemscope=move || itemscope.get()
142            itemtype=move || itemtype.get()
143            lang=move || lang.get()
144            nonce=move || nonce.get()
145            part=move || part.get()
146            popover=move || popover.get()
147            role=move || role.get()
148            slot=move || slot.get()
149            spellcheck=move || spellcheck.get()
150            style=move || style.get()
151            tabindex=move || tabindex.get()
152            title=move || title.get()
153            translate=move || translate.get()
154        />
155    };
156
157    view! {
158        <span
159            class=move || {
160                format!(
161                    "{} {}",
162                    match variant.get().unwrap_or_default().as_str() {
163                        "primary" => "singlestage-badge-primary",
164                        "secondary" => "singlestage-badge-secondary",
165                        "destructive" => "singlestage-badge-destructive",
166                        "outline" => "singlestage-badge-outline",
167                        _ => "singlestage-badge-primary",
168                    },
169                    class.get().unwrap_or_default(),
170                )
171            }
172
173            {..global_attrs_1}
174            {..global_attrs_2}
175        >
176            {children()}
177        </span>
178    }
179}