Function freya::components::Checkbox
pub fn Checkbox(__props: CheckboxProps) -> Option<VNode>
Expand description
Controlled Checkbox
component.
§Styling
Inherits the CheckboxTheme
theme.
§Example
#[derive(PartialEq, Eq, Hash)]
enum Choice {
FirstChoice,
SecondChoice,
}
fn app() -> Element {
let mut selected = use_signal::<HashSet<Choice>>(HashSet::default);
rsx!(
Tile {
onselect: move |_| {
if selected.read().contains(&Choice::FirstChoice) {
selected.write().remove(&Choice::FirstChoice);
} else {
selected.write().insert(Choice::FirstChoice);
}
},
leading: rsx!(
Checkbox {
selected: selected.read().contains(&Choice::FirstChoice),
},
),
label { "First choice" }
}
Tile {
onselect: move |_| {
if selected.read().contains(&Choice::SecondChoice) {
selected.write().remove(&Choice::SecondChoice);
} else {
selected.write().insert(Choice::SecondChoice);
}
},
leading: rsx!(
Checkbox {
selected: selected.read().contains(&Choice::SecondChoice),
},
),
label { "Second choice" }
}
)
}