tag: Rename badge to tag (#539)
This commit is contained in:
parent
ceba66c22d
commit
2aad7e412a
4 changed files with 42 additions and 42 deletions
|
|
@ -4,7 +4,6 @@ use gpui::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use ui::{
|
use ui::{
|
||||||
badge::Badge,
|
|
||||||
button::{Button, ButtonVariant, ButtonVariants as _},
|
button::{Button, ButtonVariant, ButtonVariants as _},
|
||||||
checkbox::Checkbox,
|
checkbox::Checkbox,
|
||||||
clipboard::Clipboard,
|
clipboard::Clipboard,
|
||||||
|
|
@ -12,6 +11,7 @@ use ui::{
|
||||||
label::Label,
|
label::Label,
|
||||||
link::Link,
|
link::Link,
|
||||||
radio::Radio,
|
radio::Radio,
|
||||||
|
tag::Tag,
|
||||||
v_flex, Disableable as _, IconName, Sizable, StyledExt,
|
v_flex, Disableable as _, IconName, Sizable, StyledExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -247,22 +247,22 @@ impl Render for TextStory {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
section("Badge", cx)
|
section("Tag", cx)
|
||||||
.child(
|
.child(
|
||||||
h_flex().gap_2()
|
h_flex().gap_2()
|
||||||
.child(Badge::primary().small().child("Badge"))
|
.child(Tag::primary().small().child("Tag"))
|
||||||
.child(Badge::secondary().small().child("Secondary"))
|
.child(Tag::secondary().small().child("Secondary"))
|
||||||
.child(Badge::outline().small().child("Outline"))
|
.child(Tag::outline().small().child("Outline"))
|
||||||
.child(Badge::destructive().small().child("Destructive"))
|
.child(Tag::destructive().small().child("Destructive"))
|
||||||
.child(Badge::custom(ui::yellow_500(), ui::yellow_800(), ui::yellow_500()).small().child("Custom"))
|
.child(Tag::custom(ui::yellow_500(), ui::yellow_800(), ui::yellow_500()).small().child("Custom"))
|
||||||
)
|
)
|
||||||
.child(
|
.child(
|
||||||
h_flex().gap_2()
|
h_flex().gap_2()
|
||||||
.child(Badge::primary().child("Badge"))
|
.child(Tag::primary().child("Tag"))
|
||||||
.child(Badge::secondary().child("Secondary"))
|
.child(Tag::secondary().child("Secondary"))
|
||||||
.child(Badge::outline().child("Outline"))
|
.child(Tag::outline().child("Outline"))
|
||||||
.child(Badge::destructive().child("Destructive"))
|
.child(Tag::destructive().child("Destructive"))
|
||||||
.child(Badge::custom(ui::yellow_500(), ui::yellow_800(), ui::yellow_500()).child("Custom"))
|
.child(Tag::custom(ui::yellow_500(), ui::yellow_800(), ui::yellow_500()).child("Custom"))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,7 @@ pub trait Panel: EventEmitter<PanelEvent> + FocusableView {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return `PanelControl` if the panel is zoomable, default is `None`.
|
/// Return `PanelControl` if the panel is zoomable, default is `PanelControl::Menu`.
|
||||||
///
|
///
|
||||||
/// This method called in Panel render, we should make sure it is fast.
|
/// This method called in Panel render, we should make sure it is fast.
|
||||||
fn zoomable(&self, cx: &AppContext) -> Option<PanelControl> {
|
fn zoomable(&self, cx: &AppContext) -> Option<PanelControl> {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ mod window_border;
|
||||||
|
|
||||||
pub mod accordion;
|
pub mod accordion;
|
||||||
pub mod animation;
|
pub mod animation;
|
||||||
pub mod badge;
|
|
||||||
pub mod breadcrumb;
|
pub mod breadcrumb;
|
||||||
pub mod button;
|
pub mod button;
|
||||||
pub mod button_group;
|
pub mod button_group;
|
||||||
|
|
@ -45,6 +44,7 @@ pub mod slider;
|
||||||
pub mod switch;
|
pub mod switch;
|
||||||
pub mod tab;
|
pub mod tab;
|
||||||
pub mod table;
|
pub mod table;
|
||||||
|
pub mod tag;
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
pub mod tooltip;
|
pub mod tooltip;
|
||||||
pub mod virtual_list;
|
pub mod virtual_list;
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
use crate::{theme::ActiveTheme as _, Sizable, Size};
|
use crate::{theme::ActiveTheme as _, Sizable, Size};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, prelude::FluentBuilder as _, relative, Div, Hsla, InteractiveElement as _, IntoElement,
|
div, prelude::FluentBuilder as _, relative, transparent_black, AnyElement, Div, Hsla,
|
||||||
ParentElement, RenderOnce, Styled,
|
InteractiveElement as _, IntoElement, ParentElement, RenderOnce, Styled, WindowContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||||
pub enum BadgeVariant {
|
pub enum TagVariant {
|
||||||
#[default]
|
#[default]
|
||||||
Primary,
|
Primary,
|
||||||
Secondary,
|
Secondary,
|
||||||
|
|
@ -17,18 +17,18 @@ pub enum BadgeVariant {
|
||||||
border: Hsla,
|
border: Hsla,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
impl BadgeVariant {
|
impl TagVariant {
|
||||||
fn bg(&self, cx: &gpui::WindowContext) -> Hsla {
|
fn bg(&self, cx: &WindowContext) -> Hsla {
|
||||||
match self {
|
match self {
|
||||||
Self::Primary => cx.theme().primary,
|
Self::Primary => cx.theme().primary,
|
||||||
Self::Secondary => cx.theme().secondary,
|
Self::Secondary => cx.theme().secondary,
|
||||||
Self::Outline => gpui::transparent_black(),
|
Self::Outline => transparent_black(),
|
||||||
Self::Destructive => cx.theme().destructive,
|
Self::Destructive => cx.theme().destructive,
|
||||||
Self::Custom { color, .. } => *color,
|
Self::Custom { color, .. } => *color,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn border(&self, cx: &gpui::WindowContext) -> Hsla {
|
fn border(&self, cx: &WindowContext) -> Hsla {
|
||||||
match self {
|
match self {
|
||||||
Self::Primary => cx.theme().primary,
|
Self::Primary => cx.theme().primary,
|
||||||
Self::Secondary => cx.theme().secondary,
|
Self::Secondary => cx.theme().secondary,
|
||||||
|
|
@ -38,7 +38,7 @@ impl BadgeVariant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fg(&self, cx: &gpui::WindowContext) -> Hsla {
|
fn fg(&self, cx: &WindowContext) -> Hsla {
|
||||||
match self {
|
match self {
|
||||||
Self::Primary => cx.theme().primary_foreground,
|
Self::Primary => cx.theme().primary_foreground,
|
||||||
Self::Secondary => cx.theme().secondary_foreground,
|
Self::Secondary => cx.theme().secondary_foreground,
|
||||||
|
|
@ -49,75 +49,75 @@ impl BadgeVariant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Badge is a small status indicator for UI elements.
|
/// Tag is a small status indicator for UI elements.
|
||||||
///
|
///
|
||||||
/// Only support: Medium, Small
|
/// Only support: Medium, Small
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct Badge {
|
pub struct Tag {
|
||||||
base: Div,
|
base: Div,
|
||||||
veriant: BadgeVariant,
|
variant: TagVariant,
|
||||||
size: Size,
|
size: Size,
|
||||||
}
|
}
|
||||||
impl Badge {
|
impl Tag {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
base: div().flex().items_center().rounded_md().border_1(),
|
base: div().flex().items_center().rounded_md().border_1(),
|
||||||
veriant: BadgeVariant::default(),
|
variant: TagVariant::default(),
|
||||||
size: Size::Medium,
|
size: Size::Medium,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_variant(mut self, variant: BadgeVariant) -> Self {
|
pub fn with_variant(mut self, variant: TagVariant) -> Self {
|
||||||
self.veriant = variant;
|
self.variant = variant;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn primary() -> Self {
|
pub fn primary() -> Self {
|
||||||
Self::new().with_variant(BadgeVariant::Primary)
|
Self::new().with_variant(TagVariant::Primary)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn secondary() -> Self {
|
pub fn secondary() -> Self {
|
||||||
Self::new().with_variant(BadgeVariant::Secondary)
|
Self::new().with_variant(TagVariant::Secondary)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn outline() -> Self {
|
pub fn outline() -> Self {
|
||||||
Self::new().with_variant(BadgeVariant::Outline)
|
Self::new().with_variant(TagVariant::Outline)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn destructive() -> Self {
|
pub fn destructive() -> Self {
|
||||||
Self::new().with_variant(BadgeVariant::Destructive)
|
Self::new().with_variant(TagVariant::Destructive)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn custom(color: Hsla, foreground: Hsla, border: Hsla) -> Self {
|
pub fn custom(color: Hsla, foreground: Hsla, border: Hsla) -> Self {
|
||||||
Self::new().with_variant(BadgeVariant::Custom {
|
Self::new().with_variant(TagVariant::Custom {
|
||||||
color,
|
color,
|
||||||
foreground,
|
foreground,
|
||||||
border,
|
border,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl Sizable for Badge {
|
impl Sizable for Tag {
|
||||||
fn with_size(mut self, size: impl Into<Size>) -> Self {
|
fn with_size(mut self, size: impl Into<Size>) -> Self {
|
||||||
self.size = size.into();
|
self.size = size.into();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl ParentElement for Badge {
|
impl ParentElement for Tag {
|
||||||
fn extend(&mut self, elements: impl IntoIterator<Item = gpui::AnyElement>) {
|
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
|
||||||
self.base.extend(elements);
|
self.base.extend(elements);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl RenderOnce for Badge {
|
impl RenderOnce for Tag {
|
||||||
fn render(self, cx: &mut gpui::WindowContext) -> impl IntoElement {
|
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||||
self.base
|
self.base
|
||||||
.line_height(relative(1.3))
|
.line_height(relative(1.3))
|
||||||
.map(|this| match self.size {
|
.map(|this| match self.size {
|
||||||
Size::XSmall | Size::Small => this.text_xs().px_1p5().py_0(),
|
Size::XSmall | Size::Small => this.text_xs().px_1p5().py_0(),
|
||||||
_ => this.text_xs().px_2p5().py_0p5(),
|
_ => this.text_xs().px_2p5().py_0p5(),
|
||||||
})
|
})
|
||||||
.bg(self.veriant.bg(cx))
|
.bg(self.variant.bg(cx))
|
||||||
.text_color(self.veriant.fg(cx))
|
.text_color(self.variant.fg(cx))
|
||||||
.border_color(self.veriant.border(cx))
|
.border_color(self.variant.border(cx))
|
||||||
.hover(|this| this.opacity(0.9))
|
.hover(|this| this.opacity(0.9))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue