use crate::color::Color;
#[derive(Debug, Clone, Copy)]
pub struct DerivedPalette {
pub brand: Color,
pub brand_tint: Color,
pub brand_hover: Color,
pub brand_active: Color,
pub brand_text: Color,
pub bg: Color,
pub border: Color,
pub muted: Color,
}
pub fn derive_palette(brand: &Color) -> DerivedPalette {
let white = Color::from_hex("#ffffff").expect("constant");
let near_black = Color::from_hex("#111111").expect("constant");
let neutral_gray = Color::from_hex("#6b7280").expect("constant");
DerivedPalette {
brand: *brand,
brand_tint: brand.mix(&white, 0.90),
brand_hover: brand.mix(&near_black, 0.12),
brand_active: brand.mix(&near_black, 0.25),
brand_text: brand.mix(&near_black, 0.28),
bg: brand.mix(&white, 0.97),
border: brand.mix(&white, 0.86),
muted: neutral_gray.mix(brand, 0.35),
}
}
#[cfg(test)]
mod tests {
use super::*;
fn c(hex: &str) -> Color {
Color::from_hex(hex).unwrap()
}
#[test]
fn tint_is_lighter_than_brand() {
let p = derive_palette(&c("#0d9488"));
assert!(p.brand_tint.l > p.brand.l);
}
#[test]
fn hover_is_darker_than_brand_and_active_darker_still() {
let p = derive_palette(&c("#0d9488"));
assert!(p.brand_hover.l < p.brand.l);
assert!(p.brand_active.l < p.brand_hover.l);
}
#[test]
fn bg_is_almost_white_and_border_is_lighter_than_brand() {
let p = derive_palette(&c("#0d9488"));
assert!(p.bg.l > 0.95);
assert!(p.border.l > p.brand.l);
}
#[test]
fn muted_has_brand_temperature_not_pure_gray() {
let brand = c("#0d9488"); let p = derive_palette(&brand);
assert!(p.muted.c > 0.0);
}
}