button: Rename ButtonStyle to ButtonVariant. (#460)

This is a breaking changes, we need refactor exist code by this:

- `ButtonStyled` -> `ButtonVariants`
- `.style` -> `.with_variant`
- `ButtonStyle` -> `ButtonVariant`
- `ButtonCustomStyle` -> `ButtonCustomVariant`
This commit is contained in:
Jason Lee 2024-12-03 19:22:28 +08:00 committed by GitHub
parent 7560542659
commit 23f9352295
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 132 additions and 127 deletions

View file

@ -9,7 +9,7 @@ use story::{
SidebarStory, StoryContainer, SwitchStory, TableStory, TextStory, TooltipStory, SidebarStory, StoryContainer, SwitchStory, TableStory, TextStory, TooltipStory,
}; };
use ui::{ use ui::{
button::{Button, ButtonStyled as _}, button::{Button, ButtonVariants as _},
color_picker::{ColorPicker, ColorPickerEvent}, color_picker::{ColorPicker, ColorPickerEvent},
dock::{DockArea, DockAreaState, DockEvent, DockItem, DockPlacement}, dock::{DockArea, DockAreaState, DockEvent, DockItem, DockPlacement},
h_flex, h_flex,

View file

@ -4,7 +4,7 @@ use gpui::{
}; };
use ui::{ use ui::{
button::{Button, ButtonCustomStyle, ButtonStyled as _}, button::{Button, ButtonCustomVariant, ButtonVariants as _},
button_group::ButtonGroup, button_group::ButtonGroup,
checkbox::Checkbox, checkbox::Checkbox,
h_flex, h_flex,
@ -204,7 +204,7 @@ impl Render for ButtonStory {
.child( .child(
Button::new("button-6-custom") Button::new("button-6-custom")
.custom( .custom(
ButtonCustomStyle::new(cx) ButtonCustomVariant::new(cx)
.color(if cx.theme().mode.is_dark() { .color(if cx.theme().mode.is_dark() {
ui::green_900() ui::green_900()
} else { } else {

View file

@ -2,7 +2,7 @@ use gpui::{
px, rems, ParentElement, Render, Styled, View, ViewContext, VisualContext as _, WindowContext, px, rems, ParentElement, Render, Styled, View, ViewContext, VisualContext as _, WindowContext,
}; };
use ui::{ use ui::{
button::{Button, ButtonStyle}, button::{Button, ButtonVariant, ButtonVariants},
h_flex, h_flex,
theme::ActiveTheme as _, theme::ActiveTheme as _,
v_flex, Icon, IconName, v_flex, Icon, IconName,
@ -63,7 +63,7 @@ impl Render for IconStory {
.text_color(ui::gray_500()) .text_color(ui::gray_500())
.size_6(), .size_6(),
) )
.style(ButtonStyle::Ghost), .with_variant(ButtonVariant::Ghost),
) )
.child( .child(
Button::new("like2") Button::new("like2")
@ -72,7 +72,7 @@ impl Render for IconStory {
.text_color(ui::red_500()) .text_color(ui::red_500())
.size_6(), .size_6(),
) )
.style(ButtonStyle::Ghost), .with_variant(ButtonVariant::Ghost),
) )
.child( .child(
Icon::new(IconName::Plus) Icon::new(IconName::Plus)

View file

@ -7,7 +7,7 @@ use regex::Regex;
use crate::section; use crate::section;
use ui::{ use ui::{
button::Button, button::{Button, ButtonVariant, ButtonVariants as _},
checkbox::Checkbox, checkbox::Checkbox,
h_flex, h_flex,
input::{InputEvent, OtpInput, TextInput}, input::{InputEvent, OtpInput, TextInput},
@ -398,7 +398,7 @@ impl Render for InputStory {
.child( .child(
Button::new("btn-submit") Button::new("btn-submit")
.w_full() .w_full()
.style(ui::button::ButtonStyle::Primary) .with_variant(ButtonVariant::Primary)
.label("Submit") .label("Submit")
.on_click(cx.listener(|_, _, cx| cx.dispatch_action(Box::new(Tab)))), .on_click(cx.listener(|_, _, cx| cx.dispatch_action(Box::new(Tab)))),
) )

View file

@ -8,7 +8,7 @@ use gpui::{
}; };
use ui::{ use ui::{
button::{Button, ButtonStyle, ButtonStyled as _}, button::{Button, ButtonVariant, ButtonVariants as _},
checkbox::Checkbox, checkbox::Checkbox,
date_picker::DatePicker, date_picker::DatePicker,
dropdown::Dropdown, dropdown::Dropdown,
@ -84,7 +84,7 @@ impl ListDelegate for ListItemDeletegate {
.suffix(|_| { .suffix(|_| {
Button::new("like") Button::new("like")
.icon(IconName::Heart) .icon(IconName::Heart)
.style(ButtonStyle::Ghost) .with_variant(ButtonVariant::Ghost)
.size(px(18.)) .size(px(18.))
.on_click(move |_, cx| { .on_click(move |_, cx| {
cx.stop_propagation(); cx.stop_propagation();

View file

@ -6,7 +6,7 @@ use gpui::{
}; };
use serde::Deserialize; use serde::Deserialize;
use ui::{ use ui::{
button::{Button, ButtonStyled as _}, button::{Button, ButtonVariants as _},
context_menu::ContextMenuExt, context_menu::ContextMenuExt,
divider::Divider, divider::Divider,
h_flex, h_flex,

View file

@ -8,7 +8,7 @@ use gpui::{
}; };
use serde::Deserialize; use serde::Deserialize;
use ui::{ use ui::{
button::{Button, ButtonStyled}, button::{Button, ButtonVariants},
checkbox::Checkbox, checkbox::Checkbox,
h_flex, h_flex,
indicator::Indicator, indicator::Indicator,

View file

@ -4,7 +4,7 @@ use gpui::{
}; };
use ui::{ use ui::{
button::{Button, ButtonStyle}, button::{Button, ButtonVariant, ButtonVariants as _},
checkbox::Checkbox, checkbox::Checkbox,
clipboard::Clipboard, clipboard::Clipboard,
h_flex, h_flex,
@ -118,7 +118,7 @@ impl Render for TextStory {
.child(Label::new("9,182,1 USD").text_2xl().masked(self.masked)) .child(Label::new("9,182,1 USD").text_2xl().masked(self.masked))
.child( .child(
Button::new("btn-mask") Button::new("btn-mask")
.style(ButtonStyle::Ghost) .with_variant(ButtonVariant::Ghost)
.icon(if self.masked { .icon(if self.masked {
IconName::EyeOff IconName::EyeOff
} else { } else {

View file

@ -4,7 +4,7 @@ use gpui::{
}; };
use ui::{ use ui::{
button::{Button, ButtonStyle}, button::{Button, ButtonVariant, ButtonVariants},
checkbox::Checkbox, checkbox::Checkbox,
h_flex, h_flex,
label::Label, label::Label,
@ -57,7 +57,7 @@ impl Render for TooltipStory {
.child( .child(
Button::new("button") Button::new("button")
.label("Hover me") .label("Hover me")
.style(ButtonStyle::Primary), .with_variant(ButtonVariant::Primary),
) )
.id("tooltip-1") .id("tooltip-1")
.tooltip(|cx| Tooltip::new("This is a Button", cx)), .tooltip(|cx| Tooltip::new("This is a Button", cx)),

View file

@ -26,7 +26,7 @@ impl From<Pixels> for ButtonRounded {
} }
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub struct ButtonCustomStyle { pub struct ButtonCustomVariant {
color: Hsla, color: Hsla,
foreground: Hsla, foreground: Hsla,
border: Hsla, border: Hsla,
@ -35,46 +35,46 @@ pub struct ButtonCustomStyle {
active: Hsla, active: Hsla,
} }
pub trait ButtonStyled: Sized { pub trait ButtonVariants: Sized {
fn with_style(self, style: ButtonStyle) -> Self; fn with_variant(self, variant: ButtonVariant) -> Self;
/// With the primary style for the Button. /// With the primary style for the Button.
fn primary(self) -> Self { fn primary(self) -> Self {
self.with_style(ButtonStyle::Primary) self.with_variant(ButtonVariant::Primary)
} }
/// With the danger style for the Button. /// With the danger style for the Button.
fn danger(self) -> Self { fn danger(self) -> Self {
self.with_style(ButtonStyle::Danger) self.with_variant(ButtonVariant::Danger)
} }
/// With the outline style for the Button. /// With the outline style for the Button.
fn outline(self) -> Self { fn outline(self) -> Self {
self.with_style(ButtonStyle::Outline) self.with_variant(ButtonVariant::Outline)
} }
/// With the ghost style for the Button. /// With the ghost style for the Button.
fn ghost(self) -> Self { fn ghost(self) -> Self {
self.with_style(ButtonStyle::Ghost) self.with_variant(ButtonVariant::Ghost)
} }
/// With the link style for the Button. /// With the link style for the Button.
fn link(self) -> Self { fn link(self) -> Self {
self.with_style(ButtonStyle::Link) self.with_variant(ButtonVariant::Link)
} }
/// With the text style for the Button, it will no padding look like a normal text. /// With the text style for the Button, it will no padding look like a normal text.
fn text(self) -> Self { fn text(self) -> Self {
self.with_style(ButtonStyle::Text) self.with_variant(ButtonVariant::Text)
} }
/// With the custom style for the Button. /// With the custom style for the Button.
fn custom(self, style: ButtonCustomStyle) -> Self { fn custom(self, style: ButtonCustomVariant) -> Self {
self.with_style(ButtonStyle::Custom(style)) self.with_variant(ButtonVariant::Custom(style))
} }
} }
impl ButtonCustomStyle { impl ButtonCustomVariant {
pub fn new(cx: &WindowContext) -> Self { pub fn new(cx: &WindowContext) -> Self {
Self { Self {
color: cx.theme().secondary, color: cx.theme().secondary,
@ -117,8 +117,9 @@ impl ButtonCustomStyle {
} }
} }
/// The veriant of the Button.
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub enum ButtonStyle { pub enum ButtonVariant {
Primary, Primary,
Secondary, Secondary,
Danger, Danger,
@ -126,10 +127,16 @@ pub enum ButtonStyle {
Ghost, Ghost,
Link, Link,
Text, Text,
Custom(ButtonCustomStyle), Custom(ButtonCustomVariant),
} }
impl ButtonStyle { impl Default for ButtonVariant {
fn default() -> Self {
Self::Secondary
}
}
impl ButtonVariant {
fn is_link(&self) -> bool { fn is_link(&self) -> bool {
matches!(self, Self::Link) matches!(self, Self::Link)
} }
@ -153,7 +160,7 @@ pub struct Button {
children: Vec<AnyElement>, children: Vec<AnyElement>,
disabled: bool, disabled: bool,
pub(crate) selected: bool, pub(crate) selected: bool,
style: ButtonStyle, variant: ButtonVariant,
rounded: ButtonRounded, rounded: ButtonRounded,
border_corners: Corners<bool>, border_corners: Corners<bool>,
border_edges: Edges<bool>, border_edges: Edges<bool>,
@ -181,7 +188,7 @@ impl Button {
label: None, label: None,
disabled: false, disabled: false,
selected: false, selected: false,
style: ButtonStyle::Secondary, variant: ButtonVariant::default(),
rounded: ButtonRounded::Medium, rounded: ButtonRounded::Medium,
border_corners: Corners::all(true), border_corners: Corners::all(true),
border_edges: Edges::all(true), border_edges: Edges::all(true),
@ -232,12 +239,6 @@ impl Button {
self self
} }
/// Set the ButtonStyle
pub fn style(mut self, style: ButtonStyle) -> Self {
self.style = style;
self
}
/// Set true to show the loading indicator. /// Set true to show the loading indicator.
pub fn loading(mut self, loading: bool) -> Self { pub fn loading(mut self, loading: bool) -> Self {
self.loading = loading; self.loading = loading;
@ -291,9 +292,9 @@ impl Sizable for Button {
} }
} }
impl ButtonStyled for Button { impl ButtonVariants for Button {
fn with_style(mut self, style: ButtonStyle) -> Self { fn with_variant(mut self, variant: ButtonVariant) -> Self {
self.style = style; self.variant = variant;
self self
} }
} }
@ -318,7 +319,7 @@ impl InteractiveElement for Button {
impl RenderOnce for Button { impl RenderOnce for Button {
fn render(self, cx: &mut WindowContext) -> impl IntoElement { fn render(self, cx: &mut WindowContext) -> impl IntoElement {
let style: ButtonStyle = self.style; let style: ButtonVariant = self.variant;
let normal_style = style.normal(cx); let normal_style = style.normal(cx);
let icon_size = match self.size { let icon_size = match self.size {
Size::Size(v) => Size::Size(v * 0.75), Size::Size(v) => Size::Size(v * 0.75),
@ -459,7 +460,7 @@ impl RenderOnce for Button {
} }
} }
struct ButtonStyles { struct ButtonVariantStyle {
bg: Hsla, bg: Hsla,
border: Hsla, border: Hsla,
fg: Hsla, fg: Hsla,
@ -467,66 +468,69 @@ struct ButtonStyles {
shadow: bool, shadow: bool,
} }
impl ButtonStyle { impl ButtonVariant {
fn bg_color(&self, cx: &WindowContext) -> Hsla { fn bg_color(&self, cx: &WindowContext) -> Hsla {
match self { match self {
ButtonStyle::Primary => cx.theme().primary, ButtonVariant::Primary => cx.theme().primary,
ButtonStyle::Secondary => cx.theme().secondary, ButtonVariant::Secondary => cx.theme().secondary,
ButtonStyle::Danger => cx.theme().destructive, ButtonVariant::Danger => cx.theme().destructive,
ButtonStyle::Outline | ButtonStyle::Ghost | ButtonStyle::Link | ButtonStyle::Text => { ButtonVariant::Outline
cx.theme().transparent | ButtonVariant::Ghost
} | ButtonVariant::Link
ButtonStyle::Custom(colors) => colors.color, | ButtonVariant::Text => cx.theme().transparent,
ButtonVariant::Custom(colors) => colors.color,
} }
} }
fn text_color(&self, cx: &WindowContext) -> Hsla { fn text_color(&self, cx: &WindowContext) -> Hsla {
match self { match self {
ButtonStyle::Primary => cx.theme().primary_foreground, ButtonVariant::Primary => cx.theme().primary_foreground,
ButtonStyle::Secondary | ButtonStyle::Outline | ButtonStyle::Ghost => { ButtonVariant::Secondary | ButtonVariant::Outline | ButtonVariant::Ghost => {
cx.theme().secondary_foreground cx.theme().secondary_foreground
} }
ButtonStyle::Danger => cx.theme().destructive_foreground, ButtonVariant::Danger => cx.theme().destructive_foreground,
ButtonStyle::Link => cx.theme().link, ButtonVariant::Link => cx.theme().link,
ButtonStyle::Text => cx.theme().foreground, ButtonVariant::Text => cx.theme().foreground,
ButtonStyle::Custom(colors) => colors.foreground, ButtonVariant::Custom(colors) => colors.foreground,
} }
} }
fn border_color(&self, cx: &WindowContext) -> Hsla { fn border_color(&self, cx: &WindowContext) -> Hsla {
match self { match self {
ButtonStyle::Primary => cx.theme().primary, ButtonVariant::Primary => cx.theme().primary,
ButtonStyle::Secondary => cx.theme().border, ButtonVariant::Secondary => cx.theme().border,
ButtonStyle::Danger => cx.theme().destructive, ButtonVariant::Danger => cx.theme().destructive,
ButtonStyle::Outline => cx.theme().border, ButtonVariant::Outline => cx.theme().border,
ButtonStyle::Ghost | ButtonStyle::Link | ButtonStyle::Text => cx.theme().transparent, ButtonVariant::Ghost | ButtonVariant::Link | ButtonVariant::Text => {
ButtonStyle::Custom(colors) => colors.border, cx.theme().transparent
}
ButtonVariant::Custom(colors) => colors.border,
} }
} }
fn underline(&self, _: &WindowContext) -> bool { fn underline(&self, _: &WindowContext) -> bool {
match self { match self {
ButtonStyle::Link => true, ButtonVariant::Link => true,
_ => false, _ => false,
} }
} }
fn shadow(&self, _: &WindowContext) -> bool { fn shadow(&self, _: &WindowContext) -> bool {
match self { match self {
ButtonStyle::Primary | ButtonStyle::Secondary | ButtonStyle::Danger => true, ButtonVariant::Primary | ButtonVariant::Secondary | ButtonVariant::Danger => true,
ButtonStyle::Custom(c) => c.shadow, ButtonVariant::Custom(c) => c.shadow,
_ => false, _ => false,
} }
} }
fn normal(&self, cx: &WindowContext) -> ButtonStyles { fn normal(&self, cx: &WindowContext) -> ButtonVariantStyle {
let bg = self.bg_color(cx); let bg = self.bg_color(cx);
let border = self.border_color(cx); let border = self.border_color(cx);
let fg = self.text_color(cx); let fg = self.text_color(cx);
let underline = self.underline(cx); let underline = self.underline(cx);
let shadow = self.shadow(cx); let shadow = self.shadow(cx);
ButtonStyles { ButtonVariantStyle {
bg, bg,
border, border,
fg, fg,
@ -535,31 +539,31 @@ impl ButtonStyle {
} }
} }
fn hovered(&self, cx: &WindowContext) -> ButtonStyles { fn hovered(&self, cx: &WindowContext) -> ButtonVariantStyle {
let bg = match self { let bg = match self {
ButtonStyle::Primary => cx.theme().primary_hover, ButtonVariant::Primary => cx.theme().primary_hover,
ButtonStyle::Secondary | ButtonStyle::Outline => cx.theme().secondary_hover, ButtonVariant::Secondary | ButtonVariant::Outline => cx.theme().secondary_hover,
ButtonStyle::Danger => cx.theme().destructive_hover, ButtonVariant::Danger => cx.theme().destructive_hover,
ButtonStyle::Ghost => { ButtonVariant::Ghost => {
if cx.theme().mode.is_dark() { if cx.theme().mode.is_dark() {
cx.theme().secondary.lighten(0.1).opacity(0.8) cx.theme().secondary.lighten(0.1).opacity(0.8)
} else { } else {
cx.theme().secondary.darken(0.1).opacity(0.8) cx.theme().secondary.darken(0.1).opacity(0.8)
} }
} }
ButtonStyle::Link => cx.theme().transparent, ButtonVariant::Link => cx.theme().transparent,
ButtonStyle::Text => cx.theme().transparent, ButtonVariant::Text => cx.theme().transparent,
ButtonStyle::Custom(colors) => colors.hover, ButtonVariant::Custom(colors) => colors.hover,
}; };
let border = self.border_color(cx); let border = self.border_color(cx);
let fg = match self { let fg = match self {
ButtonStyle::Link => cx.theme().link_hover, ButtonVariant::Link => cx.theme().link_hover,
_ => self.text_color(cx), _ => self.text_color(cx),
}; };
let underline = self.underline(cx); let underline = self.underline(cx);
let shadow = self.shadow(cx); let shadow = self.shadow(cx);
ButtonStyles { ButtonVariantStyle {
bg, bg,
border, border,
fg, fg,
@ -568,27 +572,27 @@ impl ButtonStyle {
} }
} }
fn active(&self, cx: &WindowContext) -> ButtonStyles { fn active(&self, cx: &WindowContext) -> ButtonVariantStyle {
let bg = match self { let bg = match self {
ButtonStyle::Primary => cx.theme().primary_active, ButtonVariant::Primary => cx.theme().primary_active,
ButtonStyle::Secondary | ButtonStyle::Outline | ButtonStyle::Ghost => { ButtonVariant::Secondary | ButtonVariant::Outline | ButtonVariant::Ghost => {
cx.theme().secondary_active cx.theme().secondary_active
} }
ButtonStyle::Danger => cx.theme().destructive_active, ButtonVariant::Danger => cx.theme().destructive_active,
ButtonStyle::Link => cx.theme().transparent, ButtonVariant::Link => cx.theme().transparent,
ButtonStyle::Text => cx.theme().transparent, ButtonVariant::Text => cx.theme().transparent,
ButtonStyle::Custom(colors) => colors.active, ButtonVariant::Custom(colors) => colors.active,
}; };
let border = self.border_color(cx); let border = self.border_color(cx);
let fg = match self { let fg = match self {
ButtonStyle::Link => cx.theme().link_active, ButtonVariant::Link => cx.theme().link_active,
ButtonStyle::Text => cx.theme().foreground.opacity(0.7), ButtonVariant::Text => cx.theme().foreground.opacity(0.7),
_ => self.text_color(cx), _ => self.text_color(cx),
}; };
let underline = self.underline(cx); let underline = self.underline(cx);
let shadow = self.shadow(cx); let shadow = self.shadow(cx);
ButtonStyles { ButtonVariantStyle {
bg, bg,
border, border,
fg, fg,
@ -597,27 +601,27 @@ impl ButtonStyle {
} }
} }
fn selected(&self, cx: &WindowContext) -> ButtonStyles { fn selected(&self, cx: &WindowContext) -> ButtonVariantStyle {
let bg = match self { let bg = match self {
ButtonStyle::Primary => cx.theme().primary_active, ButtonVariant::Primary => cx.theme().primary_active,
ButtonStyle::Secondary | ButtonStyle::Outline | ButtonStyle::Ghost => { ButtonVariant::Secondary | ButtonVariant::Outline | ButtonVariant::Ghost => {
cx.theme().secondary_active cx.theme().secondary_active
} }
ButtonStyle::Danger => cx.theme().destructive_active, ButtonVariant::Danger => cx.theme().destructive_active,
ButtonStyle::Link => cx.theme().transparent, ButtonVariant::Link => cx.theme().transparent,
ButtonStyle::Text => cx.theme().transparent, ButtonVariant::Text => cx.theme().transparent,
ButtonStyle::Custom(colors) => colors.active, ButtonVariant::Custom(colors) => colors.active,
}; };
let border = self.border_color(cx); let border = self.border_color(cx);
let fg = match self { let fg = match self {
ButtonStyle::Link => cx.theme().link_active, ButtonVariant::Link => cx.theme().link_active,
ButtonStyle::Text => cx.theme().foreground.opacity(0.7), ButtonVariant::Text => cx.theme().foreground.opacity(0.7),
_ => self.text_color(cx), _ => self.text_color(cx),
}; };
let underline = self.underline(cx); let underline = self.underline(cx);
let shadow = self.shadow(cx); let shadow = self.shadow(cx);
ButtonStyles { ButtonVariantStyle {
bg, bg,
border, border,
fg, fg,
@ -626,32 +630,33 @@ impl ButtonStyle {
} }
} }
fn disabled(&self, cx: &WindowContext) -> ButtonStyles { fn disabled(&self, cx: &WindowContext) -> ButtonVariantStyle {
let bg = match self { let bg = match self {
ButtonStyle::Link | ButtonStyle::Ghost | ButtonStyle::Outline | ButtonStyle::Text => { ButtonVariant::Link
cx.theme().transparent | ButtonVariant::Ghost
} | ButtonVariant::Outline
ButtonStyle::Primary => cx.theme().primary.opacity(0.15), | ButtonVariant::Text => cx.theme().transparent,
ButtonStyle::Danger => cx.theme().destructive.opacity(0.15), ButtonVariant::Primary => cx.theme().primary.opacity(0.15),
ButtonStyle::Secondary => cx.theme().secondary.opacity(1.5), ButtonVariant::Danger => cx.theme().destructive.opacity(0.15),
ButtonStyle::Custom(style) => style.color.opacity(0.15), ButtonVariant::Secondary => cx.theme().secondary.opacity(1.5),
ButtonVariant::Custom(style) => style.color.opacity(0.15),
}; };
let fg = match self { let fg = match self {
ButtonStyle::Link | ButtonStyle::Text | ButtonStyle::Ghost => { ButtonVariant::Link | ButtonVariant::Text | ButtonVariant::Ghost => {
cx.theme().link.grayscale() cx.theme().link.grayscale()
} }
_ => cx.theme().secondary_foreground.opacity(0.5).grayscale(), _ => cx.theme().secondary_foreground.opacity(0.5).grayscale(),
}; };
let border = match self { let border = match self {
ButtonStyle::Outline => cx.theme().border.opacity(0.5), ButtonVariant::Outline => cx.theme().border.opacity(0.5),
_ => bg, _ => bg,
}; };
let underline = self.underline(cx); let underline = self.underline(cx);
let shadow = false; let shadow = false;
ButtonStyles { ButtonVariantStyle {
bg, bg,
border, border,
fg, fg,

View file

@ -5,7 +5,7 @@ use gpui::{
use std::{cell::Cell, rc::Rc}; use std::{cell::Cell, rc::Rc};
use crate::{ use crate::{
button::{Button, ButtonStyle, ButtonStyled}, button::{Button, ButtonVariant, ButtonVariants},
Disableable, Sizable, Size, Disableable, Sizable, Size,
}; };
@ -20,7 +20,7 @@ pub struct ButtonGroup {
// The button props // The button props
compact: Option<bool>, compact: Option<bool>,
style: Option<ButtonStyle>, variant: Option<ButtonVariant>,
size: Option<Size>, size: Option<Size>,
on_click: Option<Box<dyn Fn(&Vec<usize>, &mut WindowContext) + 'static>>, on_click: Option<Box<dyn Fn(&Vec<usize>, &mut WindowContext) + 'static>>,
@ -40,7 +40,7 @@ impl ButtonGroup {
base: div(), base: div(),
children: Vec::new(), children: Vec::new(),
id: id.into(), id: id.into(),
style: None, variant: None,
size: None, size: None,
compact: None, compact: None,
multiple: false, multiple: false,
@ -89,9 +89,9 @@ impl Styled for ButtonGroup {
} }
} }
impl ButtonStyled for ButtonGroup { impl ButtonVariants for ButtonGroup {
fn with_style(mut self, style: ButtonStyle) -> Self { fn with_variant(mut self, variant: ButtonVariant) -> Self {
self.style = Some(style); self.variant = Some(variant);
self self
} }
} }
@ -163,7 +163,7 @@ impl RenderOnce for ButtonGroup {
} }
.stop_propagation(false) .stop_propagation(false)
.when_some(self.size, |this, size| this.with_size(size)) .when_some(self.size, |this, size| this.with_size(size))
.when_some(self.style, |this, style| this.style(style)) .when_some(self.variant, |this, variant| this.with_variant(variant))
.when_some(self.compact, |this, _| this.compact()) .when_some(self.compact, |this, _| this.compact())
.on_click(move |_, _| { .on_click(move |_, _| {
state.set(Some(child_index)); state.set(Some(child_index));

View file

@ -6,7 +6,7 @@ use gpui::{
}; };
use crate::{ use crate::{
button::{Button, ButtonStyled as _}, button::{Button, ButtonVariants as _},
h_flex, IconName, Sizable as _, h_flex, IconName, Sizable as _,
}; };

View file

@ -10,7 +10,7 @@ use gpui::{
use rust_i18n::t; use rust_i18n::t;
use crate::{ use crate::{
button::{Button, ButtonStyled as _}, button::{Button, ButtonVariants as _},
dock::DockItemInfo, dock::DockItemInfo,
h_flex, h_flex,
popup_menu::{PopupMenu, PopupMenuExt}, popup_menu::{PopupMenu, PopupMenuExt},

View file

@ -8,7 +8,7 @@ use gpui::{
}; };
use crate::{ use crate::{
button::{Button, ButtonStyled as _}, button::{Button, ButtonVariants as _},
h_flex, h_flex,
modal::overlay_color, modal::overlay_color,
root::ContextModal as _, root::ContextModal as _,

View file

@ -1,7 +1,7 @@
use gpui::{Styled, WindowContext}; use gpui::{Styled, WindowContext};
use crate::{ use crate::{
button::{Button, ButtonStyled as _}, button::{Button, ButtonVariants as _},
theme::ActiveTheme as _, theme::ActiveTheme as _,
Icon, IconName, Sizable as _, Icon, IconName, Sizable as _,
}; };

View file

@ -9,7 +9,7 @@ use gpui::{
use crate::{ use crate::{
animation::cubic_bezier, animation::cubic_bezier,
button::{Button, ButtonStyled as _}, button::{Button, ButtonVariants as _},
theme::ActiveTheme as _, theme::ActiveTheme as _,
v_flex, ContextModal, IconName, Sizable as _, v_flex, ContextModal, IconName, Sizable as _,
}; };

View file

@ -9,7 +9,7 @@ use smol::Timer;
use crate::{ use crate::{
animation::cubic_bezier, animation::cubic_bezier,
button::{Button, ButtonStyled as _}, button::{Button, ButtonVariants as _},
h_flex, h_flex,
theme::ActiveTheme as _, theme::ActiveTheme as _,
v_flex, Icon, IconName, Sizable as _, StyledExt, v_flex, Icon, IconName, Sizable as _, StyledExt,

View file

@ -6,7 +6,7 @@ use gpui::{
use regex::Regex; use regex::Regex;
use crate::{ use crate::{
button::{Button, ButtonStyled as _}, button::{Button, ButtonVariants as _},
h_flex, h_flex,
input::{InputEvent, TextInput}, input::{InputEvent, TextInput},
prelude::FluentBuilder, prelude::FluentBuilder,

View file

@ -1,5 +1,5 @@
use crate::{ use crate::{
button::{Button, ButtonStyled}, button::{Button, ButtonVariants},
h_flex, h_flex,
scroll::ScrollbarAxis, scroll::ScrollbarAxis,
theme::ActiveTheme, theme::ActiveTheme,

View file

@ -9,7 +9,7 @@ use gpui::{
use rust_i18n::t; use rust_i18n::t;
use crate::{ use crate::{
button::{Button, ButtonStyled as _}, button::{Button, ButtonVariants as _},
h_flex, h_flex,
theme::ActiveTheme, theme::ActiveTheme,
v_flex, Disableable as _, IconName, Selectable, Sizable, Size, v_flex, Disableable as _, IconName, Selectable, Sizable, Size,

View file

@ -8,7 +8,7 @@ use gpui::{
use rust_i18n::t; use rust_i18n::t;
use crate::{ use crate::{
button::{Button, ButtonStyled as _}, button::{Button, ButtonVariants as _},
dropdown::Escape, dropdown::Escape,
h_flex, h_flex,
input::ClearButton, input::ClearButton,