theme: add info severity color token

This commit is contained in:
2026-10-31 09:34:09 +07:00
parent d53f4e290d
commit 9ddf8fe90f
8 changed files with 83 additions and 5 deletions
+1 -1
View File
@@ -221,7 +221,7 @@ impl RenderOnce for ToastsView {
let toasts = self.toasts.clone();
let accent = match toast.severity {
ToastSeverity::Info => theme.ramps.primary.base,
ToastSeverity::Info => theme.ramps.info.base,
ToastSeverity::Success => theme.ramps.success.base,
ToastSeverity::Warning => theme.ramps.warning.base,
ToastSeverity::Danger => theme.ramps.destructive.base,
+6
View File
@@ -33,6 +33,8 @@ pub struct ColorTokens {
pub success_foreground: Hsla,
pub warning: Hsla,
pub warning_foreground: Hsla,
pub info: Hsla,
pub info_foreground: Hsla,
pub border: Hsla,
pub input: Hsla,
pub ring: Hsla,
@@ -65,6 +67,8 @@ impl ColorTokens {
success_foreground: hex(0xffffff),
warning: hex(0xd97706),
warning_foreground: hex(0xffffff),
info: hex(0x0284c7),
info_foreground: hex(0xffffff),
border: hex(0xe4e4e7),
input: hex(0xe4e4e7),
ring: hex(0x93c5fd),
@@ -96,6 +100,8 @@ impl ColorTokens {
success_foreground: hex(0x052e16),
warning: hex(0xf59e0b),
warning_foreground: hex(0x451a03),
info: hex(0x38bdf8),
info_foreground: hex(0x082f49),
border: hex(0x27272a),
input: hex(0x27272a),
ring: hex(0x1d4ed8),
+12 -1
View File
@@ -29,6 +29,8 @@ pub struct ThemeDefinition {
pub success_foreground: Option<String>,
pub warning: Option<String>,
pub warning_foreground: Option<String>,
pub info: Option<String>,
pub info_foreground: Option<String>,
pub border: Option<String>,
pub input: Option<String>,
pub ring: Option<String>,
@@ -114,6 +116,14 @@ impl ThemeDefinition {
parse_hex(self.warning_foreground.as_deref()?)
}
pub fn info(&self) -> Option<Hsla> {
parse_hex(self.info.as_deref()?)
}
pub fn info_foreground(&self) -> Option<Hsla> {
parse_hex(self.info_foreground.as_deref()?)
}
pub fn border(&self) -> Option<Hsla> {
parse_hex(self.border.as_deref()?)
}
@@ -206,11 +216,12 @@ mod tests {
#[test]
fn parses_a_full_definition() {
let def = ThemeDefinition::parse_toml(
"mode = \"dark\"\naccent = \"#7aa2f7\"\nbackground = \"#1a1b26\"\n",
"mode = \"dark\"\naccent = \"#7aa2f7\"\nbackground = \"#1a1b26\"\ninfo = \"#38bdf8\"\n",
)
.unwrap();
assert_eq!(def.mode, Some(crate::ThemeVariant::Dark));
assert!(def.accent().is_some());
assert!(def.info().is_some());
assert!(def.foreground().is_none());
}
+45 -2
View File
@@ -12,6 +12,7 @@ pub struct Ramps {
pub destructive: AccentShades,
pub success: AccentShades,
pub warning: AccentShades,
pub info: AccentShades,
}
/// Everything a component paints from, after the overlay chain.
@@ -70,6 +71,7 @@ pub(crate) fn resolve(
system_palette.warning,
base.warning,
);
let info = pick(def_color(|d| d.info()), system_palette.info, base.info);
let mut colors = ColorTokens {
background: pick(
@@ -126,18 +128,24 @@ pub(crate) fn resolve(
None,
contrast_foreground(destructive),
),
success: pick(def_color(|d| d.success()), None, base.success),
success,
success_foreground: pick(
def_color(|d| d.success_foreground()),
None,
contrast_foreground(success),
),
warning: pick(def_color(|d| d.warning()), None, base.warning),
warning,
warning_foreground: pick(
def_color(|d| d.warning_foreground()),
None,
contrast_foreground(warning),
),
info,
info_foreground: pick(
def_color(|d| d.info_foreground()),
None,
contrast_foreground(info),
),
border: pick(
def_color(|d| d.border()),
system_palette.border,
@@ -208,6 +216,7 @@ pub(crate) fn resolve(
),
success: derive_shades(success, colors.background, variant == ThemeVariant::Dark),
warning: derive_shades(warning, colors.background, variant == ThemeVariant::Dark),
info: derive_shades(info, colors.background, variant == ThemeVariant::Dark),
},
colors,
radius,
@@ -523,4 +532,38 @@ mod tests {
assert!(resolved.colors.ring != resolved.colors.background);
}
}
#[test]
fn info_stays_calm_when_the_accent_warms_up() {
// The whole point of the info role: a warm platform accent (GNOME
// red, Omarchy red themes) must not make Info toasts read as Danger.
let red_accent = hsla(0xdc2626);
let resolved = resolve(
&system(
ThemeVariant::Dark,
PartialPalette::default(),
Some(red_accent),
),
None,
None,
);
assert_eq!(resolved.ramps.primary.base, red_accent);
assert_ne!(resolved.colors.info, resolved.colors.destructive);
assert_ne!(resolved.ramps.info.base, resolved.ramps.destructive.base);
}
#[test]
fn info_follows_the_severity_overlay_chain() {
let palette = PartialPalette {
info: Some(hsla(0x155e75)),
..PartialPalette::default()
};
let system_stated = resolve(&system(ThemeVariant::Dark, palette, None), None, None);
assert_eq!(system_stated.colors.info, hsla(0x155e75));
assert_eq!(system_stated.ramps.info.base, hsla(0x155e75));
let def = ThemeDefinition::parse_toml("info = \"#0ea5e9\"\n").unwrap();
let preset_stated = resolve(&system(ThemeVariant::Dark, palette, None), Some(&def), None);
assert_eq!(preset_stated.colors.info, hsla(0x0ea5e9));
}
}
+1
View File
@@ -83,6 +83,7 @@ impl MacosSource {
destructive: Self::color_to_hsla(&NSColor::systemRedColor()),
success: None,
warning: None,
info: None,
border: Self::color_to_hsla(&NSColor::separatorColor()),
input: Self::color_to_hsla(&NSColor::controlBackgroundColor()),
ring: Self::color_to_hsla(&NSColor::keyboardFocusIndicatorColor()),
+1
View File
@@ -55,6 +55,7 @@ pub struct PartialPalette {
/// No platform states severity colors; presets override them.
pub success: Option<Hsla>,
pub warning: Option<Hsla>,
pub info: Option<Hsla>,
pub border: Option<Hsla>,
pub input: Option<Hsla>,
pub ring: Option<Hsla>,