Function freya_components::Checkbox

source ·
pub fn Checkbox(_: CheckboxProps) -> Element
Expand description

Controlled Checkbox component.

§Styling

Inherits the CheckboxTheme theme.

§Example

#[derive(PartialEq, Eq, Hash)]
enum Choice {
    First,
    Second,
}

fn app() -> Element {
    let mut selected = use_signal::<HashSet<Choice>>(HashSet::default);
    rsx!(
        Tile {
            onselect: move |_| {
                if selected.read().contains(&Choice::First) {
                    selected.write().remove(&Choice::First);
                } else {
                    selected.write().insert(Choice::First);
                }
            },
            leading: rsx!(
                Checkbox {
                    selected: selected.read().contains(&Choice::First),
                }
            )
            label { "First choice" }
        }
        Tile {
            onselect: move |_| {
                if selected.read().contains(&Choice::Second) {
                    selected.write().remove(&Choice::Second);
                } else {
                    selected.write().insert(Choice::Second);
                }
            },
            leading: rsx!(
                Checkbox {
                    selected: selected.read().contains(&Choice::Second),
                }
            ),
            label { "Second choice" }
        }
    )
}

§Props

For details, see the props struct definition.

  • selected : bool

    Indicate whether this checkbox is selected or not.

  • theme : Option<CheckboxThemeWith>

    Theme override.