tag: Rename badge to tag (#539)

This commit is contained in:
Floyd Wang 2025-01-10 10:28:47 +08:00 committed by GitHub
parent ceba66c22d
commit 2aad7e412a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 42 additions and 42 deletions

View file

@ -4,7 +4,6 @@ use gpui::{
};
use ui::{
badge::Badge,
button::{Button, ButtonVariant, ButtonVariants as _},
checkbox::Checkbox,
clipboard::Clipboard,
@ -12,6 +11,7 @@ use ui::{
label::Label,
link::Link,
radio::Radio,
tag::Tag,
v_flex, Disableable as _, IconName, Sizable, StyledExt,
};
@ -247,22 +247,22 @@ impl Render for TextStory {
),
)
.child(
section("Badge", cx)
section("Tag", cx)
.child(
h_flex().gap_2()
.child(Badge::primary().small().child("Badge"))
.child(Badge::secondary().small().child("Secondary"))
.child(Badge::outline().small().child("Outline"))
.child(Badge::destructive().small().child("Destructive"))
.child(Badge::custom(ui::yellow_500(), ui::yellow_800(), ui::yellow_500()).small().child("Custom"))
.child(Tag::primary().small().child("Tag"))
.child(Tag::secondary().small().child("Secondary"))
.child(Tag::outline().small().child("Outline"))
.child(Tag::destructive().small().child("Destructive"))
.child(Tag::custom(ui::yellow_500(), ui::yellow_800(), ui::yellow_500()).small().child("Custom"))
)
.child(
h_flex().gap_2()
.child(Badge::primary().child("Badge"))
.child(Badge::secondary().child("Secondary"))
.child(Badge::outline().child("Outline"))
.child(Badge::destructive().child("Destructive"))
.child(Badge::custom(ui::yellow_500(), ui::yellow_800(), ui::yellow_500()).child("Custom"))
.child(Tag::primary().child("Tag"))
.child(Tag::secondary().child("Secondary"))
.child(Tag::outline().child("Outline"))
.child(Tag::destructive().child("Destructive"))
.child(Tag::custom(ui::yellow_500(), ui::yellow_800(), ui::yellow_500()).child("Custom"))
)
)
}

View file

@ -76,7 +76,7 @@ pub trait Panel: EventEmitter<PanelEvent> + FocusableView {
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.
fn zoomable(&self, cx: &AppContext) -> Option<PanelControl> {

View file

@ -11,7 +11,6 @@ mod window_border;
pub mod accordion;
pub mod animation;
pub mod badge;
pub mod breadcrumb;
pub mod button;
pub mod button_group;
@ -45,6 +44,7 @@ pub mod slider;
pub mod switch;
pub mod tab;
pub mod table;
pub mod tag;
pub mod theme;
pub mod tooltip;
pub mod virtual_list;

View file

@ -1,11 +1,11 @@
use crate::{theme::ActiveTheme as _, Sizable, Size};
use gpui::{
div, prelude::FluentBuilder as _, relative, Div, Hsla, InteractiveElement as _, IntoElement,
ParentElement, RenderOnce, Styled,
div, prelude::FluentBuilder as _, relative, transparent_black, AnyElement, Div, Hsla,
InteractiveElement as _, IntoElement, ParentElement, RenderOnce, Styled, WindowContext,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum BadgeVariant {
pub enum TagVariant {
#[default]
Primary,
Secondary,
@ -17,18 +17,18 @@ pub enum BadgeVariant {
border: Hsla,
},
}
impl BadgeVariant {
fn bg(&self, cx: &gpui::WindowContext) -> Hsla {
impl TagVariant {
fn bg(&self, cx: &WindowContext) -> Hsla {
match self {
Self::Primary => cx.theme().primary,
Self::Secondary => cx.theme().secondary,
Self::Outline => gpui::transparent_black(),
Self::Outline => transparent_black(),
Self::Destructive => cx.theme().destructive,
Self::Custom { color, .. } => *color,
}
}
fn border(&self, cx: &gpui::WindowContext) -> Hsla {
fn border(&self, cx: &WindowContext) -> Hsla {
match self {
Self::Primary => cx.theme().primary,
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 {
Self::Primary => cx.theme().primary_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
#[derive(IntoElement)]
pub struct Badge {
pub struct Tag {
base: Div,
veriant: BadgeVariant,
variant: TagVariant,
size: Size,
}
impl Badge {
impl Tag {
fn new() -> Self {
Self {
base: div().flex().items_center().rounded_md().border_1(),
veriant: BadgeVariant::default(),
variant: TagVariant::default(),
size: Size::Medium,
}
}
pub fn with_variant(mut self, variant: BadgeVariant) -> Self {
self.veriant = variant;
pub fn with_variant(mut self, variant: TagVariant) -> Self {
self.variant = variant;
self
}
pub fn primary() -> Self {
Self::new().with_variant(BadgeVariant::Primary)
Self::new().with_variant(TagVariant::Primary)
}
pub fn secondary() -> Self {
Self::new().with_variant(BadgeVariant::Secondary)
Self::new().with_variant(TagVariant::Secondary)
}
pub fn outline() -> Self {
Self::new().with_variant(BadgeVariant::Outline)
Self::new().with_variant(TagVariant::Outline)
}
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 {
Self::new().with_variant(BadgeVariant::Custom {
Self::new().with_variant(TagVariant::Custom {
color,
foreground,
border,
})
}
}
impl Sizable for Badge {
impl Sizable for Tag {
fn with_size(mut self, size: impl Into<Size>) -> Self {
self.size = size.into();
self
}
}
impl ParentElement for Badge {
fn extend(&mut self, elements: impl IntoIterator<Item = gpui::AnyElement>) {
impl ParentElement for Tag {
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
self.base.extend(elements);
}
}
impl RenderOnce for Badge {
fn render(self, cx: &mut gpui::WindowContext) -> impl IntoElement {
impl RenderOnce for Tag {
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
self.base
.line_height(relative(1.3))
.map(|this| match self.size {
Size::XSmall | Size::Small => this.text_xs().px_1p5().py_0(),
_ => this.text_xs().px_2p5().py_0p5(),
})
.bg(self.veriant.bg(cx))
.text_color(self.veriant.fg(cx))
.border_color(self.veriant.border(cx))
.bg(self.variant.bg(cx))
.text_color(self.variant.fg(cx))
.border_color(self.variant.border(cx))
.hover(|this| this.opacity(0.9))
}
}