Adjust TintColor color token terminology (#22826)

Previously, to use a green and red shade with `TintColor` you'd need to
pass `Positive` and `Negative`, respectively. This terminology always
tripped me up, because, for example, I'd often try to use something
like:

```
Button::new("icon_color", "Negative")
      style(ButtonStyle::Tinted(TintColor::Negative))
      .color(Color::Error)
      .icon_color(Color::Error)
      .icon(IconName::Trash),
)
```

...and due to `icon_color` taking `Color::Error`, I'd always get
`TintColor` wrong at a first try, because I would, out of muscle memory,
write `TintColor::Error`, which wouldn't compile. That's exactly the
change in this PR—`TintColor` now takes `Success` and `Error` instead of
`Positive` and `Negative`, for more consistency.


Release Notes:

- N/A
This commit is contained in:
Danilo Leal 2025-01-08 11:40:48 -03:00 committed by GitHub
parent bbb473b8df
commit 115aa43354
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 18 deletions

View file

@ -3654,7 +3654,7 @@ impl ContextEditor {
let (style, tooltip) = match token_state(&self.context, cx) { let (style, tooltip) = match token_state(&self.context, cx) {
Some(TokenState::NoTokensLeft { .. }) => ( Some(TokenState::NoTokensLeft { .. }) => (
ButtonStyle::Tinted(TintColor::Negative), ButtonStyle::Tinted(TintColor::Error),
Some(Tooltip::text("Token limit reached", cx)), Some(Tooltip::text("Token limit reached", cx)),
), ),
Some(TokenState::HasMoreTokens { Some(TokenState::HasMoreTokens {
@ -3711,7 +3711,7 @@ impl ContextEditor {
let (style, tooltip) = match token_state(&self.context, cx) { let (style, tooltip) = match token_state(&self.context, cx) {
Some(TokenState::NoTokensLeft { .. }) => ( Some(TokenState::NoTokensLeft { .. }) => (
ButtonStyle::Tinted(TintColor::Negative), ButtonStyle::Tinted(TintColor::Error),
Some(Tooltip::text("Token limit reached", cx)), Some(Tooltip::text("Token limit reached", cx)),
), ),
Some(TokenState::HasMoreTokens { Some(TokenState::HasMoreTokens {

View file

@ -381,7 +381,7 @@ impl TitleBar {
.style(ButtonStyle::Subtle) .style(ButtonStyle::Subtle)
.icon_size(IconSize::Small) .icon_size(IconSize::Small)
.toggle_state(is_muted) .toggle_state(is_muted)
.selected_style(ButtonStyle::Tinted(TintColor::Negative)) .selected_style(ButtonStyle::Tinted(TintColor::Error))
.on_click(move |_, cx| { .on_click(move |_, cx| {
toggle_mute(&Default::default(), cx); toggle_mute(&Default::default(), cx);
}) })
@ -398,7 +398,7 @@ impl TitleBar {
}, },
) )
.style(ButtonStyle::Subtle) .style(ButtonStyle::Subtle)
.selected_style(ButtonStyle::Tinted(TintColor::Negative)) .selected_style(ButtonStyle::Tinted(TintColor::Error))
.icon_size(IconSize::Small) .icon_size(IconSize::Small)
.toggle_state(is_deafened) .toggle_state(is_deafened)
.tooltip(move |cx| { .tooltip(move |cx| {

View file

@ -474,9 +474,9 @@ impl ComponentPreview for Button {
.style(ButtonStyle::Tinted(TintColor::Accent)), .style(ButtonStyle::Tinted(TintColor::Accent)),
), ),
single_example( single_example(
"Negative", "Error",
Button::new("tinted_negative", "Negative") Button::new("tinted_negative", "Error")
.style(ButtonStyle::Tinted(TintColor::Negative)), .style(ButtonStyle::Tinted(TintColor::Error)),
), ),
single_example( single_example(
"Warning", "Warning",
@ -484,9 +484,9 @@ impl ComponentPreview for Button {
.style(ButtonStyle::Tinted(TintColor::Warning)), .style(ButtonStyle::Tinted(TintColor::Warning)),
), ),
single_example( single_example(
"Positive", "Success",
Button::new("tinted_positive", "Positive") Button::new("tinted_positive", "Success")
.style(ButtonStyle::Tinted(TintColor::Positive)), .style(ButtonStyle::Tinted(TintColor::Success)),
), ),
], ],
), ),
@ -527,8 +527,8 @@ impl ComponentPreview for Button {
), ),
single_example( single_example(
"Tinted Icons", "Tinted Icons",
Button::new("icon_color", "Delete") Button::new("icon_color", "Error")
.style(ButtonStyle::Tinted(TintColor::Negative)) .style(ButtonStyle::Tinted(TintColor::Error))
.color(Color::Error) .color(Color::Error)
.icon_color(Color::Error) .icon_color(Color::Error)
.icon(IconName::Trash) .icon(IconName::Trash)

View file

@ -49,9 +49,9 @@ pub enum IconPosition {
pub enum TintColor { pub enum TintColor {
#[default] #[default]
Accent, Accent,
Negative, Error,
Warning, Warning,
Positive, Success,
} }
impl TintColor { impl TintColor {
@ -63,7 +63,7 @@ impl TintColor {
label_color: cx.theme().colors().text, label_color: cx.theme().colors().text,
icon_color: cx.theme().colors().text, icon_color: cx.theme().colors().text,
}, },
TintColor::Negative => ButtonLikeStyles { TintColor::Error => ButtonLikeStyles {
background: cx.theme().status().error_background, background: cx.theme().status().error_background,
border_color: cx.theme().status().error_border, border_color: cx.theme().status().error_border,
label_color: cx.theme().colors().text, label_color: cx.theme().colors().text,
@ -75,7 +75,7 @@ impl TintColor {
label_color: cx.theme().colors().text, label_color: cx.theme().colors().text,
icon_color: cx.theme().colors().text, icon_color: cx.theme().colors().text,
}, },
TintColor::Positive => ButtonLikeStyles { TintColor::Success => ButtonLikeStyles {
background: cx.theme().status().success_background, background: cx.theme().status().success_background,
border_color: cx.theme().status().success_border, border_color: cx.theme().status().success_border,
label_color: cx.theme().colors().text, label_color: cx.theme().colors().text,
@ -89,9 +89,9 @@ impl From<TintColor> for Color {
fn from(tint: TintColor) -> Self { fn from(tint: TintColor) -> Self {
match tint { match tint {
TintColor::Accent => Color::Accent, TintColor::Accent => Color::Accent,
TintColor::Negative => Color::Error, TintColor::Error => Color::Error,
TintColor::Warning => Color::Warning, TintColor::Warning => Color::Warning,
TintColor::Positive => Color::Success, TintColor::Success => Color::Success,
} }
} }
} }