Skip to main content

adam_web_ui/components/switch/
component.rs

1//! Styled upstream switch implementation; see `../UPSTREAM.md`.
2use dioxus::prelude::*;
3use dioxus_primitives::switch::{self, SwitchProps};
4
5include!(concat!(env!("OUT_DIR"), "/switch-styles.rs"));
6
7/// Renders the official switch with controlled state and accessible interaction.
8///
9/// - Complexity: O(attributes + children) render work.
10///
11/// # Examples
12/// ```
13/// use adam_web_ui::components::switch::Switch;
14/// use dioxus::prelude::*;
15/// fn app() -> Element { rsx! { Switch { aria_label: "Enabled" } } }
16/// ```
17#[component]
18pub fn Switch(props: SwitchProps) -> Element {
19    crate::components::styles::use_control_styles();
20    rsx! {
21        switch::Switch {
22            class: Styles::dx_switch,
23            checked: props.checked,
24            default_checked: props.default_checked,
25            disabled: props.disabled,
26            required: props.required,
27            name: props.name,
28            value: props.value,
29            on_checked_change: props.on_checked_change,
30            attributes: props.attributes,
31            switch::SwitchThumb { class: Styles::dx_switch_thumb }
32        }
33    }
34}