Skip to main content

adam_web_ui/components/checkbox/
component.rs

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