Add ButtonStyle::Outline, ButtonStyle::Glost

This commit is contained in:
Jason Lee 2024-07-05 00:18:36 +08:00
parent acbc029eed
commit c925a6aa61
3 changed files with 55 additions and 0 deletions

View file

@ -50,6 +50,18 @@ impl Render for ButtonStory {
.label("Danger Button")
.style(ButtonStyle::Danger)
.on_click(Self::on_click),
)
.child(
Button::new("button-5", cx)
.label("Outline Button")
.style(ButtonStyle::Outline)
.on_click(Self::on_click),
)
.child(
Button::new("button-6", cx)
.label("Ghost Button")
.style(ButtonStyle::Ghost)
.on_click(Self::on_click),
),
)
.child(
@ -197,6 +209,19 @@ impl Render for ButtonStory {
.size(ButtonSize::Small)
.style(ButtonStyle::Primary),
)
.child(
Button::new("icon-button-0-outline", cx)
.icon(IconName::Search)
.style(ButtonStyle::Outline),
)
.child(
Button::new("icon-button-1", cx)
.icon(IconName::Info)
.style(ButtonStyle::Ghost),
),
)
.child(
section("Icon Button", cx)
.child(
Button::new("icon-button-4", cx)
.icon(IconName::Info)

View file

@ -29,6 +29,8 @@ pub enum ButtonStyle {
Primary,
Secondary,
Danger,
Outline,
Ghost,
}
#[derive(IntoElement)]
@ -282,6 +284,8 @@ impl ButtonStyle {
ButtonStyle::Primary => cx.theme().primary,
ButtonStyle::Secondary => cx.theme().secondary,
ButtonStyle::Danger => cx.theme().destructive,
ButtonStyle::Outline => cx.theme().transparent,
ButtonStyle::Ghost => cx.theme().transparent,
}
}
@ -290,6 +294,8 @@ impl ButtonStyle {
ButtonStyle::Primary => cx.theme().primary_foreground,
ButtonStyle::Secondary => cx.theme().secondary_foreground,
ButtonStyle::Danger => cx.theme().destructive_foreground,
ButtonStyle::Outline => cx.theme().secondary_foreground,
ButtonStyle::Ghost => cx.theme().secondary_foreground,
}
}
@ -298,6 +304,8 @@ impl ButtonStyle {
ButtonStyle::Primary => cx.theme().primary,
ButtonStyle::Secondary => cx.theme().border,
ButtonStyle::Danger => cx.theme().destructive,
ButtonStyle::Outline => cx.theme().border,
ButtonStyle::Ghost => cx.theme().transparent,
}
}
@ -314,6 +322,8 @@ impl ButtonStyle {
ButtonStyle::Primary => cx.theme().primary_hover,
ButtonStyle::Secondary => cx.theme().secondary_hover,
ButtonStyle::Danger => cx.theme().destructive_hover,
ButtonStyle::Outline => cx.theme().secondary_hover,
ButtonStyle::Ghost => cx.theme().secondary_hover,
};
let border = self.border_color(cx);
let fg = self.text_color(cx);
@ -326,6 +336,8 @@ impl ButtonStyle {
ButtonStyle::Primary => cx.theme().primary_active,
ButtonStyle::Secondary => cx.theme().secondary_active,
ButtonStyle::Danger => cx.theme().destructive_active,
ButtonStyle::Outline => cx.theme().secondary_active,
ButtonStyle::Ghost => cx.theme().secondary_active,
};
let border = self.border_color(cx);
let fg = self.text_color(cx);
@ -338,6 +350,8 @@ impl ButtonStyle {
ButtonStyle::Primary => cx.theme().primary_active,
ButtonStyle::Secondary => cx.theme().secondary_active,
ButtonStyle::Danger => cx.theme().destructive_active,
ButtonStyle::Outline => cx.theme().secondary_active,
ButtonStyle::Ghost => cx.theme().secondary_active,
};
let border = self.border_color(cx);
let fg = self.text_color(cx);

View file

@ -1,6 +1,8 @@
use std::ops::Range;
use crate::event::InterativeElementExt as _;
use crate::popover::Popover;
use crate::popup_menu::PopupMenu;
use crate::theme::ActiveTheme;
use crate::StyledExt as _;
use blink_cursor::BlinkCursor;
@ -369,6 +371,20 @@ impl TextInput {
blink_cursor.pause(cx);
});
}
fn render_content_menu(&self, cx: &mut ViewContext<Self>) -> impl IntoElement {
let focus_handle = self.focus_handle.clone();
PopupMenu::build(cx, |mut this, _| {
this.content(focus_handle)
.menu("Copy", Box::new(Copy))
.menu("Cut", Box::new(Cut))
.menu("Paste", Box::new(Paste))
.separator()
.menu("Search", Box::new(SelectAll));
this
})
}
}
impl ViewInputHandler for TextInput {