example: Fix modal example button id. (#747)

Ref #740

- Fix modal example button id.
- Fix switch example to allow check.
This commit is contained in:
Jason Lee 2025-03-27 11:24:06 +08:00 committed by GitHub
parent e8f89e04d6
commit 05fea87ec4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 6 deletions

View file

@ -686,7 +686,7 @@ impl Render for ModalStory {
})), })),
) )
.child( .child(
Button::new("show-notify-warning") Button::new("show-notify-with-title")
.label("Notification with Title") .label("Notification with Title")
.on_click(cx.listener(|_, _, window, cx| { .on_click(cx.listener(|_, _, window, cx| {
struct TestNotification; struct TestNotification;

View file

@ -23,6 +23,8 @@ pub struct SwitchStory {
check1: bool, check1: bool,
check2: bool, check2: bool,
check3: bool, check3: bool,
check4: bool,
check5: bool,
radio_check1: bool, radio_check1: bool,
radio_check2: bool, radio_check2: bool,
radio_group_checked: Option<usize>, radio_group_checked: Option<usize>,
@ -56,9 +58,11 @@ impl SwitchStory {
check1: false, check1: false,
check2: false, check2: false,
check3: true, check3: true,
check4: false,
check5: false,
radio_check1: false, radio_check1: false,
radio_check2: true, radio_check2: true,
radio_group_checked: None, radio_group_checked: Some(1),
} }
} }
} }
@ -208,15 +212,20 @@ impl Render for SwitchStory {
.child( .child(
Checkbox::new("longlong-checkbox") Checkbox::new("longlong-checkbox")
.w(px(300.)) .w(px(300.))
.checked(self.check4)
.label("The long long label text.") .label("The long long label text.")
.child(div().text_color(cx.theme().muted_foreground).child( .child(div().text_color(cx.theme().muted_foreground).child(
"This is a long long label text that \ "This is a long long label text that \
should wrap when the text is too long.", should wrap when the text is too long.",
)), ))
.on_click(cx.listener(|v, _, _, _| {
v.check4 = !v.check4;
})),
) )
.child( .child(
Checkbox::new("longlong-markdown-checkbox") Checkbox::new("longlong-markdown-checkbox")
.w(px(300.)) .w(px(300.))
.checked(self.check5)
.label("Label with description") .label("Label with description")
.child(div().text_color(cx.theme().muted_foreground).child( .child(div().text_color(cx.theme().muted_foreground).child(
TextView::markdown( TextView::markdown(
@ -225,7 +234,10 @@ impl Render for SwitchStory {
text used markdown, \ text used markdown, \
it should wrap when the text is too long.", it should wrap when the text is too long.",
), ),
)), ))
.on_click(cx.listener(|v, _, _, _| {
v.check5 = !v.check5;
})),
), ),
), ),
) )
@ -298,8 +310,9 @@ impl Render for SwitchStory {
RadioGroup::horizontal() RadioGroup::horizontal()
.children(["One", "Two", "Three"]) .children(["One", "Two", "Three"])
.selected_index(self.radio_group_checked) .selected_index(self.radio_group_checked)
.on_change(cx.listener(|this, selected_ix: &usize, _, _| { .on_change(cx.listener(|this, selected_ix: &usize, _, cx| {
this.radio_group_checked = Some(*selected_ix); this.radio_group_checked = Some(*selected_ix);
cx.notify();
})), })),
), ),
) )
@ -319,8 +332,9 @@ impl Render for SwitchStory {
.child(Radio::new("one3").label("Mexico")) .child(Radio::new("one3").label("Mexico"))
.selected_index(self.radio_group_checked) .selected_index(self.radio_group_checked)
.on_change(cx.listener( .on_change(cx.listener(
|this, selected_ix: &usize, _, _| { |this, selected_ix: &usize, _, cx| {
this.radio_group_checked = Some(*selected_ix); this.radio_group_checked = Some(*selected_ix);
cx.notify();
}, },
)), )),
), ),