feat(button): Remove track_focus (#282)

This commit is contained in:
Floyd Wang 2024-09-27 14:39:48 +08:00 committed by GitHub
parent 2c1119a7bd
commit c5b4505560
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 157 additions and 181 deletions

View file

@ -310,7 +310,7 @@ impl Render for StoryWorkspace {
.gap_2()
.child(self.theme_color_picker.clone())
.child(
Button::new("theme-mode", cx)
Button::new("theme-mode")
.map(|this| {
if cx.theme().mode.is_dark() {
this.icon(IconName::Sun)
@ -331,7 +331,7 @@ impl Render for StoryWorkspace {
)
.child(self.locale_selector.clone())
.child(
Button::new("github", cx)
Button::new("github")
.icon(IconName::GitHub)
.small()
.ghost()
@ -343,7 +343,7 @@ impl Render for StoryWorkspace {
div()
.relative()
.child(
Button::new("bell", cx)
Button::new("bell")
.small()
.ghost()
.compact()
@ -403,7 +403,7 @@ impl Render for LocaleSelector {
.track_focus(&focus_handle)
.on_action(cx.listener(Self::on_select_locale))
.child(
Button::new("btn", cx)
Button::new("btn")
.small()
.ghost()
.icon(IconName::Globe)

View file

@ -133,7 +133,7 @@ impl Render for ButtonStory {
.child(
section("Normal Button", cx)
.child(
Button::new("button-1", cx)
Button::new("button-1")
.primary()
.label("Primary Button")
.disabled(disabled)
@ -143,7 +143,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-2", cx)
Button::new("button-2")
.label("Secondary Button")
.disabled(disabled)
.selected(selected)
@ -152,7 +152,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-4", cx)
Button::new("button-4")
.danger()
.label("Danger Button")
.disabled(disabled)
@ -162,7 +162,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-5", cx)
Button::new("button-5")
.outline()
.label("Outline Button")
.disabled(disabled)
@ -172,7 +172,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-5-ghost", cx)
Button::new("button-5-ghost")
.ghost()
.label("Ghost Button")
.disabled(disabled)
@ -182,7 +182,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-5-link", cx)
Button::new("button-5-link")
.link()
.label("Link Button")
.disabled(disabled)
@ -192,7 +192,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-5-text", cx)
Button::new("button-5-text")
.text()
.label("Text Button")
.disabled(disabled)
@ -202,7 +202,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-6-custom", cx)
Button::new("button-6-custom")
.custom(
ButtonCustomStyle::new(cx)
.color(if cx.theme().mode.is_dark() {
@ -242,7 +242,7 @@ impl Render for ButtonStory {
.child(
section("Button with Icon", cx)
.child(
Button::new("button-icon-1", cx)
Button::new("button-icon-1")
.primary()
.label("Confirm")
.icon(IconName::Check)
@ -253,7 +253,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-icon-2", cx)
Button::new("button-icon-2")
.label("Abort")
.icon(IconName::Close)
.disabled(disabled)
@ -263,7 +263,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-icon-3", cx)
Button::new("button-icon-3")
.label("Maximize")
.icon(Icon::new(IconName::Maximize))
.disabled(disabled)
@ -273,7 +273,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-icon-4", cx)
Button::new("button-icon-4")
.primary()
.child(
h_flex()
@ -290,7 +290,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-icon-5-ghost", cx)
Button::new("button-icon-5-ghost")
.ghost()
.icon(IconName::Check)
.label("Confirm")
@ -301,7 +301,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-icon-6-link", cx)
Button::new("button-icon-6-link")
.link()
.icon(IconName::Check)
.label("Link")
@ -312,7 +312,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-icon-6-text", cx)
Button::new("button-icon-6-text")
.text()
.icon(IconName::Check)
.label("Text Button")
@ -330,7 +330,7 @@ impl Render for ButtonStory {
.child(
section("Small Size", cx)
.child(
Button::new("button-6", cx)
Button::new("button-6")
.label("Primary Button")
.primary()
.small()
@ -342,7 +342,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-7", cx)
Button::new("button-7")
.label("Secondary Button")
.small()
.disabled(disabled)
@ -352,7 +352,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-8", cx)
Button::new("button-8")
.label("Danger Button")
.danger()
.small()
@ -363,7 +363,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-8-outline", cx)
Button::new("button-8-outline")
.label("Outline Button")
.outline()
.small()
@ -374,7 +374,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-8-ghost", cx)
Button::new("button-8-ghost")
.label("Ghost Button")
.ghost()
.small()
@ -385,7 +385,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-8-link", cx)
Button::new("button-8-link")
.label("Link Button")
.link()
.small()
@ -399,7 +399,7 @@ impl Render for ButtonStory {
.child(
section("XSmall Size", cx)
.child(
Button::new("button-xs-1", cx)
Button::new("button-xs-1")
.label("Primary Button")
.primary()
.xsmall()
@ -410,7 +410,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-xs-2", cx)
Button::new("button-xs-2")
.label("Secondary Button")
.xsmall()
.loading(true)
@ -421,7 +421,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-xs-3", cx)
Button::new("button-xs-3")
.label("Danger Button")
.danger()
.xsmall()
@ -432,7 +432,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-xs-3-ghost", cx)
Button::new("button-xs-3-ghost")
.label("Ghost Button")
.ghost()
.xsmall()
@ -443,7 +443,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-xs-3-outline", cx)
Button::new("button-xs-3-outline")
.label("Outline Button")
.outline()
.xsmall()
@ -454,7 +454,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-xs-3-link", cx)
Button::new("button-xs-3-link")
.label("Link Button")
.link()
.xsmall()
@ -473,7 +473,7 @@ impl Render for ButtonStory {
.small()
.disabled(disabled)
.child(
Button::new("button-one", cx)
Button::new("button-one")
.label("One")
.disabled(disabled)
.selected(selected)
@ -481,7 +481,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-two", cx)
Button::new("button-two")
.label("Two")
.disabled(disabled)
.selected(selected)
@ -489,7 +489,7 @@ impl Render for ButtonStory {
.on_click(Self::on_click),
)
.child(
Button::new("button-three", cx)
Button::new("button-three")
.label("Three")
.disabled(disabled)
.selected(selected)
@ -515,22 +515,22 @@ impl Render for ButtonStory {
.compact()
.multiple(toggle_multiple)
.child(
Button::new("disabled-toggle-button", cx)
Button::new("disabled-toggle-button")
.label("Disabled")
.selected(disabled),
)
.child(
Button::new("loading-toggle-button", cx)
Button::new("loading-toggle-button")
.label("Loading")
.selected(loading),
)
.child(
Button::new("selected-toggle-button", cx)
Button::new("selected-toggle-button")
.label("Selected")
.selected(selected),
)
.child(
Button::new("compact-toggle-button", cx)
Button::new("compact-toggle-button")
.label("Compact")
.selected(compact),
)
@ -547,7 +547,7 @@ impl Render for ButtonStory {
.child(
section("Icon Button", cx)
.child(
Button::new("icon-button-primary", cx)
Button::new("icon-button-primary")
.icon(IconName::Search)
.loading_icon(IconName::LoaderCircle)
.primary()
@ -557,7 +557,7 @@ impl Render for ButtonStory {
.when(compact, |this| this.compact()),
)
.child(
Button::new("icon-button-secondary", cx)
Button::new("icon-button-secondary")
.icon(IconName::Info)
.loading(true)
.disabled(disabled)
@ -566,7 +566,7 @@ impl Render for ButtonStory {
.when(compact, |this| this.compact()),
)
.child(
Button::new("icon-button-danger", cx)
Button::new("icon-button-danger")
.icon(IconName::Close)
.danger()
.disabled(disabled)
@ -575,7 +575,7 @@ impl Render for ButtonStory {
.when(compact, |this| this.compact()),
)
.child(
Button::new("icon-button-small-primary", cx)
Button::new("icon-button-small-primary")
.icon(IconName::Search)
.small()
.primary()
@ -585,7 +585,7 @@ impl Render for ButtonStory {
.when(compact, |this| this.compact()),
)
.child(
Button::new("icon-button-outline", cx)
Button::new("icon-button-outline")
.icon(IconName::Search)
.outline()
.disabled(disabled)
@ -594,7 +594,7 @@ impl Render for ButtonStory {
.when(compact, |this| this.compact()),
)
.child(
Button::new("icon-button-ghost", cx)
Button::new("icon-button-ghost")
.icon(IconName::ArrowLeft)
.loading_icon(IconName::LoaderCircle)
.ghost()
@ -607,7 +607,7 @@ impl Render for ButtonStory {
.child(
section("Icon Button", cx)
.child(
Button::new("icon-button-4", cx)
Button::new("icon-button-4")
.icon(IconName::Info)
.small()
.disabled(disabled)
@ -616,7 +616,7 @@ impl Render for ButtonStory {
.when(compact, |this| this.compact()),
)
.child(
Button::new("icon-button-5", cx)
Button::new("icon-button-5")
.icon(IconName::Close)
.small()
.danger()
@ -626,7 +626,7 @@ impl Render for ButtonStory {
.when(compact, |this| this.compact()),
)
.child(
Button::new("icon-button-6", cx)
Button::new("icon-button-6")
.icon(IconName::Search)
.small()
.primary()
@ -636,7 +636,7 @@ impl Render for ButtonStory {
.when(compact, |this| this.compact()),
)
.child(
Button::new("icon-button-7", cx)
Button::new("icon-button-7")
.icon(IconName::Info)
.xsmall()
.disabled(disabled)
@ -645,7 +645,7 @@ impl Render for ButtonStory {
.when(compact, |this| this.compact()),
)
.child(
Button::new("icon-button-8", cx)
Button::new("icon-button-8")
.icon(IconName::Close)
.xsmall()
.danger()
@ -655,7 +655,7 @@ impl Render for ButtonStory {
.when(compact, |this| this.compact()),
)
.child(
Button::new("icon-button-9", cx)
Button::new("icon-button-9")
.icon(IconName::Heart)
.size(px(24.))
.ghost()

View file

@ -61,7 +61,7 @@ impl Render for IconStory {
)
.child(Icon::new(IconName::Maximize).size(px(55.)))
.child(
Button::new("like1", cx)
Button::new("like1")
.icon(
Icon::new(IconName::Heart)
.text_color(ui::gray_500())
@ -70,7 +70,7 @@ impl Render for IconStory {
.style(ButtonStyle::Ghost),
)
.child(
Button::new("like2", cx)
Button::new("like2")
.icon(
Icon::new(IconName::HeartOff)
.text_color(ui::red_500())

View file

@ -301,14 +301,14 @@ impl Render for InputStory {
.w_full()
.gap_3()
.child(
Button::new("btn-submit", cx)
Button::new("btn-submit")
.w_full()
.style(ui::button::ButtonStyle::Primary)
.label("Submit")
.on_click(cx.listener(|_, _, cx| cx.dispatch_action(Box::new(Tab)))),
)
.child(
Button::new("btn-cancel", cx)
Button::new("btn-cancel")
.w_full()
.label("Cancel")
.into_element(),

View file

@ -79,8 +79,8 @@ impl ListDelegate for ListItemDeletegate {
.justify_between()
.child(item.to_string()),
)
.suffix(|cx| {
Button::new("like", cx)
.suffix(|_| {
Button::new("like")
.icon(IconName::Heart)
.style(ButtonStyle::Ghost)
.size(px(18.))
@ -311,15 +311,12 @@ impl ModalStory {
h_flex()
.gap_6()
.items_center()
.child(
Button::new("confirm", cx)
.primary()
.label("Confirm")
.on_click(|_, cx| {
cx.close_drawer();
}),
)
.child(Button::new("cancel", cx).label("Cancel").on_click(|_, cx| {
.child(Button::new("confirm").primary().label("Confirm").on_click(
|_, cx| {
cx.close_drawer();
},
))
.child(Button::new("cancel").label("Cancel").on_click(|_, cx| {
cx.close_drawer();
})),
)
@ -340,7 +337,7 @@ impl ModalStory {
let dropdown = self.dropdown.clone();
let view = cx.view().clone();
cx.open_modal(move |modal, cx| {
cx.open_modal(move |modal, _| {
modal
.title("Form Modal")
.overlay(overlay)
@ -359,44 +356,37 @@ impl ModalStory {
h_flex()
.gap_6()
.items_center()
.child(
Button::new("confirm", cx)
.primary()
.label("Confirm")
.on_click({
let view = view.clone();
let input1 = input1.clone();
let date_picker = date_picker.clone();
move |_, cx| {
cx.close_modal();
.child(Button::new("confirm").primary().label("Confirm").on_click({
let view = view.clone();
let input1 = input1.clone();
let date_picker = date_picker.clone();
move |_, cx| {
cx.close_modal();
view.update(cx, |view, cx| {
view.selected_value = Some(
format!(
"Hello, {}, date: {}",
input1.read(cx).text(),
date_picker.read(cx).date()
)
.into(),
)
});
}
}),
)
view.update(cx, |view, cx| {
view.selected_value = Some(
format!(
"Hello, {}, date: {}",
input1.read(cx).text(),
date_picker.read(cx).date()
)
.into(),
)
});
}
}))
.child(Button::new("new-modal").label("Open Other Modal").on_click(
move |_, cx| {
cx.open_modal(move |modal, _| {
modal
.title("Other Modal")
.child("This is another modal.")
.min_h(px(300.))
});
},
))
.child(
Button::new("new-modal", cx)
.label("Open Other Modal")
.on_click(move |_, cx| {
cx.open_modal(move |modal, _| {
modal
.title("Other Modal")
.child("This is another modal.")
.min_h(px(300.))
});
}),
)
.child(
Button::new("cancel", cx)
Button::new("cancel")
.label("Cancel")
.on_click(move |_, cx| {
cx.close_modal();
@ -467,7 +457,7 @@ impl Render for ModalStory {
.child("Test Focus Back")
.child(self.input2.clone())
.child(
Button::new("test-action", cx)
Button::new("test-action")
.label("Test Dispatch Action")
.on_click(|_, cx| {
cx.dispatch_action(Box::new(TestAction));
@ -479,28 +469,28 @@ impl Render for ModalStory {
.items_start()
.gap_3()
.child(
Button::new("show-drawer-left", cx)
Button::new("show-drawer-left")
.label("Left Drawer...")
.on_click(cx.listener(|this, _, cx| {
this.open_drawer_at(Placement::Left, cx)
})),
)
.child(
Button::new("show-drawer-top", cx)
Button::new("show-drawer-top")
.label("Top Drawer...")
.on_click(cx.listener(|this, _, cx| {
this.open_drawer_at(Placement::Top, cx)
})),
)
.child(
Button::new("show-drawer", cx)
Button::new("show-drawer")
.label("Right Drawer...")
.on_click(cx.listener(|this, _, cx| {
this.open_drawer_at(Placement::Right, cx)
})),
)
.child(
Button::new("show-drawer", cx)
Button::new("show-drawer")
.label("Bottom Drawer...")
.on_click(cx.listener(|this, _, cx| {
this.open_drawer_at(Placement::Bottom, cx)
@ -517,7 +507,7 @@ impl Render for ModalStory {
)
})
.child(
Button::new("show-modal", cx)
Button::new("show-modal")
.label("Open Modal...")
.on_click(cx.listener(|this, _, cx| this.show_modal(cx))),
)
@ -525,7 +515,7 @@ impl Render for ModalStory {
h_flex()
.gap_3()
.child(
Button::new("show-notify-info", cx)
Button::new("show-notify-info")
.label("Info Notify...")
.on_click(cx.listener(|_, _, cx| {
cx.push_notification(
@ -534,7 +524,7 @@ impl Render for ModalStory {
})),
)
.child(
Button::new("show-notify-error", cx)
Button::new("show-notify-error")
.label("Error Notify...")
.on_click(cx.listener(|_, _, cx| {
cx.push_notification((
@ -544,7 +534,7 @@ impl Render for ModalStory {
})),
)
.child(
Button::new("show-notify-success", cx)
Button::new("show-notify-success")
.label("Success Notify...")
.on_click(cx.listener(|_, _, cx| {
cx.push_notification((
@ -554,7 +544,7 @@ impl Render for ModalStory {
})),
)
.child(
Button::new("show-notify-warning", cx)
Button::new("show-notify-warning")
.label("Warning Notify...")
.on_click(cx.listener(|_, _, cx| {
struct WarningNotification;
@ -564,7 +554,7 @@ impl Render for ModalStory {
})),
)
.child(
Button::new("show-notify-warning", cx)
Button::new("show-notify-warning")
.label("Notification with Title")
.on_click(cx.listener(|_, _, cx| {
struct TestNotification;

View file

@ -64,7 +64,7 @@ impl Render for Form {
.child("This is a form container.")
.child(self.input1.clone())
.child(
Button::new("submit", cx)
Button::new("submit")
.label("Submit")
.primary()
.on_click(cx.listener(|_, _, cx| cx.emit(DismissEvent))),
@ -200,17 +200,17 @@ impl Render for PopupStory {
.child(
v_flex().gap_4().child(
Popover::new("info-top-left")
.trigger(Button::new("info-top-left", cx).label("Top Left"))
.trigger(Button::new("info-top-left").label("Top Left"))
.content(|cx| {
cx.new_view(|cx| {
PopoverContent::new(cx, |cx| {
PopoverContent::new(cx, |_| {
v_flex()
.gap_4()
.child("Hello, this is a Popover.")
.w(px(400.))
.child(Divider::horizontal())
.child(
Button::new("info1", cx)
Button::new("info1")
.label("Yes")
.w(px(80.))
.small(),
@ -225,17 +225,17 @@ impl Render for PopupStory {
.child(
Popover::new("info-top-right")
.anchor(AnchorCorner::TopRight)
.trigger(Button::new("info-top-right", cx).label("Top Right"))
.trigger(Button::new("info-top-right").label("Top Right"))
.content(|cx| {
cx.new_view(|cx| {
PopoverContent::new(cx, |cx| {
PopoverContent::new(cx, |_| {
v_flex()
.gap_4()
.w_96()
.child("Hello, this is a Popover on the Top Right.")
.child(Divider::horizontal())
.child(
Button::new("info1", cx)
Button::new("info1")
.label("Yes")
.w(px(80.))
.small(),
@ -250,7 +250,7 @@ impl Render for PopupStory {
h_flex()
.gap_3()
.child(
Button::new("popup-menu-1", cx)
Button::new("popup-menu-1")
.icon(IconName::Ellipsis)
.popup_menu(move |this, cx| {
this.menu("Copy", Box::new(Copy))
@ -288,20 +288,14 @@ impl Render for PopupStory {
.child(
Popover::new("info-bottom-left")
.anchor(AnchorCorner::BottomLeft)
.trigger(
Button::new("pop", cx).label("Popup with Form").w(px(300.)),
)
.trigger(Button::new("pop").label("Popup with Form").w(px(300.)))
.content(move |_| form.clone()),
)
.child(
Popover::new("info-bottom-right")
.anchor(AnchorCorner::BottomRight)
.mouse_button(MouseButton::Right)
.trigger(
Button::new("pop", cx)
.label("Mouse Right Click")
.w(px(300.)),
)
.trigger(Button::new("pop").label("Mouse Right Click").w(px(300.)))
.content(|cx| {
cx.new_view(|cx| {
PopoverContent::new(cx, |cx| {
@ -315,7 +309,7 @@ impl Render for PopupStory {
h_flex()
.gap_4()
.child(
Button::new("info1", cx)
Button::new("info1")
.label("Ok")
.w(px(80.))
.small()
@ -329,7 +323,7 @@ impl Render for PopupStory {
)),
)
.child(
Button::new("close", cx)
Button::new("close")
.label("Cancel")
.small()
.on_click(cx.listener(

View file

@ -92,28 +92,28 @@ impl Render for ProgressStory {
h_flex()
.gap_x_2()
.child(
Button::new("button-1", cx)
Button::new("button-1")
.label("0%")
.on_click(cx.listener(|this, _, _| {
this.set_value(0.);
})),
)
.child(
Button::new("button-2", cx)
Button::new("button-2")
.label("25%")
.on_click(cx.listener(|this, _, _| {
this.set_value(25.);
})),
)
.child(
Button::new("button-3", cx)
Button::new("button-3")
.label("75%")
.on_click(cx.listener(|this, _, _| {
this.set_value(75.);
})),
)
.child(
Button::new("button-4", cx)
Button::new("button-4")
.label("100%")
.on_click(cx.listener(|this, _, _| {
this.set_value(100.);
@ -125,14 +125,14 @@ impl Render for ProgressStory {
h_flex()
.gap_x_2()
.child(
Button::new("button-5", cx)
Button::new("button-5")
.icon(IconName::Minus)
.on_click(cx.listener(|this, _, _| {
this.set_value((this.value - 1.).max(0.));
})),
)
.child(
Button::new("button-6", cx)
Button::new("button-6")
.icon(IconName::Plus)
.on_click(cx.listener(|this, _, _| {
this.set_value((this.value + 1.).min(100.));

View file

@ -93,28 +93,28 @@ impl Render for ScrollableStory {
h_flex()
.gap_2()
.child(
Button::new("test-0", cx)
Button::new("test-0")
.label("Size 0")
.on_click(cx.listener(|view, _, cx| {
view.change_test_cases(0, cx);
})),
)
.child(
Button::new("test-1", cx)
Button::new("test-1")
.label("Size 1")
.on_click(cx.listener(|view, _, cx| {
view.change_test_cases(1, cx);
})),
)
.child(
Button::new("test-2", cx)
Button::new("test-2")
.label("Size 2")
.on_click(cx.listener(|view, _, cx| {
view.change_test_cases(2, cx);
})),
)
.child(
Button::new("test-3", cx)
Button::new("test-3")
.label("Size 3")
.on_click(cx.listener(|view, _, cx| {
view.change_test_cases(3, cx);
@ -122,7 +122,7 @@ impl Render for ScrollableStory {
)
.child(Divider::vertical().px_2())
.child(
Button::new("test-axis-both", cx)
Button::new("test-axis-both")
.label("Both Scrollbar")
.on_click(
cx.listener(|view, _, cx| {
@ -131,14 +131,14 @@ impl Render for ScrollableStory {
),
)
.child(
Button::new("test-axis-vertical", cx)
Button::new("test-axis-vertical")
.label("Vertical")
.on_click(cx.listener(|view, _, cx| {
view.change_axis(ScrollbarAxis::Vertical, cx)
})),
)
.child(
Button::new("test-axis-horizontal", cx)
Button::new("test-axis-horizontal")
.label("Horizontal")
.on_click(cx.listener(|view, _, cx| {
view.change_axis(ScrollbarAxis::Horizontal, cx)

View file

@ -117,7 +117,7 @@ impl Render for TextStory {
h_flex()
.child(Label::new("9,182,1 USD").text_2xl().masked(self.masked))
.child(
Button::new("btn-mask", cx)
Button::new("btn-mask")
.style(ButtonStyle::Ghost)
.icon(if self.masked {
IconName::EyeOff

View file

@ -47,7 +47,7 @@ impl gpui::FocusableView for TooltipStory {
}
}
impl Render for TooltipStory {
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> impl gpui::IntoElement {
fn render(&mut self, _: &mut gpui::ViewContext<Self>) -> impl gpui::IntoElement {
v_flex()
.p_4()
.gap_5()
@ -55,7 +55,7 @@ impl Render for TooltipStory {
div()
.cursor(CursorStyle::PointingHand)
.child(
Button::new("button", cx)
Button::new("button")
.label("Hover me")
.style(ButtonStyle::Primary),
)

View file

@ -103,7 +103,7 @@ impl Render for WebViewStory {
.gap_2()
.items_center()
.child(
Button::new("go-back", cx)
Button::new("go-back")
.icon(IconName::ArrowLeft)
.on_click(cx.listener(Self::go_back)),
)

View file

@ -7,8 +7,8 @@ use crate::{
};
use gpui::{
div, prelude::FluentBuilder as _, px, relative, AnyElement, ClickEvent, Corners, Div, Edges,
ElementId, FocusHandle, Hsla, InteractiveElement, IntoElement, MouseButton, ParentElement,
Pixels, RenderOnce, SharedString, StatefulInteractiveElement as _, Styled, WindowContext,
ElementId, Hsla, InteractiveElement, IntoElement, MouseButton, ParentElement, Pixels,
RenderOnce, SharedString, StatefulInteractiveElement as _, Styled, WindowContext,
};
pub enum ButtonRounded {
@ -147,7 +147,6 @@ impl ButtonStyle {
pub struct Button {
pub base: Div,
id: ElementId,
focus_handle: FocusHandle,
icon: Option<Icon>,
label: Option<SharedString>,
children: Vec<AnyElement>,
@ -173,10 +172,9 @@ impl From<Button> for AnyElement {
}
impl Button {
pub fn new(id: impl Into<ElementId>, cx: &mut WindowContext) -> Self {
pub fn new(id: impl Into<ElementId>) -> Self {
Self {
base: div(),
focus_handle: cx.focus_handle(),
id: id.into(),
icon: None,
label: None,
@ -311,7 +309,6 @@ impl RenderOnce for Button {
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
let style: ButtonStyle = self.style;
let normal_style = style.normal(cx);
let focused = self.focus_handle.is_focused(cx);
let icon_size = match self.size {
Size::Size(v) => Size::Size(v * 0.75),
_ => self.size,
@ -326,7 +323,6 @@ impl RenderOnce for Button {
self.base
.id(self.id)
.track_focus(&self.focus_handle)
.flex()
.items_center()
.justify_center()
@ -402,7 +398,6 @@ impl RenderOnce for Button {
.text_color(active_style.fg)
})
})
.when(focused, |this| this.border_color(cx.theme().ring))
.when_some(
self.on_click.filter(|_| !self.disabled && !self.loading),
|this, on_click| {

View file

@ -95,7 +95,7 @@ impl Element for Clipboard {
.items_center()
.when_some(content_element, |this, element| this.child(element))
.child(
Button::new(clipboard_id, cx)
Button::new(clipboard_id)
.icon(if copide_value {
IconName::Check
} else {

View file

@ -259,7 +259,7 @@ impl TabPanel {
.items_center()
.when(self.is_zoomed, |this| {
this.child(
Button::new("zoom", cx)
Button::new("zoom")
.icon(IconName::Minimize)
.xsmall()
.ghost()
@ -270,7 +270,7 @@ impl TabPanel {
)
})
.child(
Button::new("menu", cx)
Button::new("menu")
.icon(IconName::Ellipsis)
.xsmall()
.ghost()

View file

@ -178,7 +178,7 @@ impl RenderOnce for Drawer {
.w_full()
.child(self.title.unwrap_or(div().into_any_element()))
.child(
Button::new("close", cx)
Button::new("close")
.small()
.ghost()
.icon(IconName::Close)

View file

@ -8,8 +8,8 @@ use crate::{
pub(crate) struct ClearButton {}
impl ClearButton {
pub fn new(cx: &mut WindowContext) -> Button {
Button::new("clean", cx)
pub fn new(_: &mut WindowContext) -> Button {
Button::new("clean")
.icon(IconName::CircleX)
.ghost()
.with_size(px(14.))

View file

@ -208,20 +208,17 @@ impl RenderOnce for Modal {
})
.when(self.show_close, |this| {
this.child(
Button::new(
SharedString::from(format!("modal-close-{layer_ix}")),
cx,
)
.absolute()
.top_2()
.right_2()
.small()
.ghost()
.icon(IconName::Close)
.on_click(move |_, cx| {
on_close(&ClickEvent::default(), cx);
cx.close_modal();
}),
Button::new(SharedString::from(format!("modal-close-{layer_ix}")))
.absolute()
.top_2()
.right_2()
.small()
.ghost()
.icon(IconName::Close)
.on_click(move |_, cx| {
on_close(&ClickEvent::default(), cx);
cx.close_modal();
}),
)
})
.child(self.content)

View file

@ -251,7 +251,7 @@ impl Render for Notification {
.invisible()
.group_hover("", |this| this.visible())
.child(
Button::new("close", cx)
Button::new("close")
.icon(IconName::Close)
.ghost()
.xsmall()

View file

@ -470,7 +470,7 @@ impl Calendar {
.justify_between()
.items_center()
.child(
Button::new("prev", cx)
Button::new("prev")
.icon(IconName::ArrowLeft)
.ghost()
.disabled(disabled)
@ -488,7 +488,7 @@ impl Calendar {
.justify_center()
.gap_3()
.child(
Button::new("month", cx)
Button::new("month")
.ghost()
.label(self.month_name(0))
.selected(self.view_mode.is_month())
@ -503,7 +503,7 @@ impl Calendar {
})),
)
.child(
Button::new("year", cx)
Button::new("year")
.ghost()
.label(current_year.to_string())
.compact()
@ -531,7 +531,7 @@ impl Calendar {
))
})
.child(
Button::new("next", cx)
Button::new("next")
.icon(IconName::ArrowRight)
.ghost()
.disabled(disabled)