Skip to content

Commit

Permalink
docs: Add on change handles to Checkbox page
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Nov 24, 2023
1 parent 555c790 commit 606d153
Showing 1 changed file with 40 additions and 6 deletions.
46 changes: 40 additions & 6 deletions crates/zu-docs/src/views/inputs/checkbox_page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ fn form_group_section() -> Html {
let antoine = use_state(|| true);
let error = use_state(|| false);

let gilad_changed = {
let gilad_clone = gilad.clone();
Callback::from(move |checked: bool| {
gilad_clone.set(checked);
log::info!("gilad old state: {}, new state: {checked}", *gilad_clone);
})
};
let jason_changed = {
let jason_clone = jason.clone();
Callback::from(move |checked: bool| jason_clone.set(checked))
};
let antoine_changed = {
let antoine_clone = antoine.clone();
Callback::from(move |checked: bool| antoine_clone.set(checked))
};

html! {
<>
<h2>{"FormGroup"}</h2>
Expand All @@ -170,19 +186,28 @@ fn form_group_section() -> Html {
<FormGroup>
<FormControlLabel
control={html!{
<Checkbox checked={*gilad} name="gilad" />
<Checkbox
checked={*gilad}
name="gilad"
on_change={gilad_changed.clone()} />
}}
label="Gilad Gray"
/>
<FormControlLabel
control={html!{
<Checkbox checked={*jason} name="jason" />
<Checkbox
checked={*jason}
name="jason"
on_change={jason_changed.clone()} />
}}
label="Jason Killian"
/>
<FormControlLabel
control={html!{
<Checkbox checked={*antoine} name="antoine" />
<Checkbox
checked={*antoine}
name="antoine"
on_change={antoine_changed.clone()} />
}}
label="Antoine Llorca"
/>
Expand All @@ -199,19 +224,28 @@ fn form_group_section() -> Html {
<FormGroup>
<FormControlLabel
control={html!{
<Checkbox checked={*gilad} name="gilad" />
<Checkbox
checked={*gilad}
name="gilad"
on_change={gilad_changed} />
}}
label="Gilad Gray"
/>
<FormControlLabel
control={html!{
<Checkbox checked={*jason} name="jason" />
<Checkbox
checked={*jason}
name="jason"
on_change={jason_changed} />
}}
label="Jason Killian"
/>
<FormControlLabel
control={html!{
<Checkbox checked={*antoine} name="antoine" />
<Checkbox
checked={*antoine}
name="antoine"
on_change={antoine_changed} />
}}
label="Antoine Llorca"
/>
Expand Down

0 comments on commit 606d153

Please sign in to comment.