Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions web/src/lib/Theme/accentPalette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DEFAULT_ACCENT_COLOR } from '@/config/appearance.config.ts'
const DARK_INK = '#020a0b'
const WHITE = '#ffffff'
const BLACK = '#000000'
const LIGHT_SURFACE = '#fbfdfc'
const LIGHT_CANVAS = '#eef4f0'
const DARK_SURFACE = '#0d0f12'
const MIN_TEXT_CONTRAST = 4.5

Expand Down Expand Up @@ -71,11 +71,11 @@ const DEFAULT_PALETTE: AccentPalette = {
brand400: '#4ee99a',
brand500: DEFAULT_ACCENT_COLOR,
brand600: '#0fb33a',
brand700: '#0d8a31',
brand700: '#0c7f2d',
foreground: DARK_INK,
hover: '#65f586',
active: '#0fb33a',
textLight: '#0d8a31',
textLight: '#0c7f2d',
textDark: '#65f586',
rgb: '48 238 97',
}
Expand All @@ -90,7 +90,7 @@ export function deriveAccentPalette(value: string): AccentPalette {
relativeLuminance(accent) > 0.85 ? BLACK : foreground === BLACK ? WHITE : BLACK
const brand300 = ensureContrast(mix(accent, WHITE, 0.28), DARK_SURFACE)
const brand400 = ensureContrast(mix(accent, WHITE, 0.16), DARK_SURFACE)
const brand700 = ensureContrast(mix(accent, BLACK, 0.25), LIGHT_SURFACE)
const brand700 = ensureContrast(mix(accent, BLACK, 0.25), LIGHT_CANVAS)
const channels = parseHex(accent)

return {
Expand Down
4 changes: 2 additions & 2 deletions web/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@
--accent-400: #4ee99a;
--accent-500: #30ee61;
--accent-600: #0fb33a;
--accent-700: #0d8a31;
--accent-700: #0c7f2d;
--accent-foreground: #020a0b;
--accent-hover: #65f586;
--accent-active: #0fb33a;
--accent-text-light: #0d8a31;
--accent-text-light: #0c7f2d;
--accent-text-dark: #65f586;
--accent-rgb: 48 238 97;
}
Expand Down
16 changes: 13 additions & 3 deletions web/src/tests/lib/Theme/accent-palette.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,33 @@ import {
} from '@/lib/Theme/accentPalette.ts'

describe('system accent palette', () => {
test('keeps the existing green palette exactly when no color is configured', () => {
test('keeps the default accent and uses readable light-theme text when no color is configured', () => {
expect(deriveAccentPalette('#30ee61')).toEqual({
accent: '#30ee61',
brand300: '#65f586',
brand400: '#4ee99a',
brand500: '#30ee61',
brand600: '#0fb33a',
brand700: '#0d8a31',
brand700: '#0c7f2d',
foreground: '#020a0b',
hover: '#65f586',
active: '#0fb33a',
textLight: '#0d8a31',
textLight: '#0c7f2d',
textDark: '#65f586',
rgb: '48 238 97',
})
expect(deriveAccentPalette('invalid')).toEqual(deriveAccentPalette('#30ee61'))
})

test('default light-theme text is readable on the canvas and every standard surface', () => {
const palette = deriveAccentPalette('#30ee61')
for (const background of ['#eef4f0', '#fbfdfc', '#ffffff', '#f4f8f5', '#f7fbf8']) {
expect(accentContrastRatio(palette.textLight, background)).toBeGreaterThanOrEqual(4.5)
expect(accentContrastRatio(palette.brand700, background)).toBeGreaterThanOrEqual(4.5)
}
expect(accentCssVariables('#30ee61')['--accent-text-light']).toBe(palette.textLight)
})

test('derives legible foreground and theme text for arbitrary colors', () => {
for (const color of [
'#000000',
Expand All @@ -49,6 +58,7 @@ describe('system accent palette', () => {
4.5,
)
expect(accentContrastRatio(palette.textLight, '#fbfdfc')).toBeGreaterThanOrEqual(4.5)
expect(accentContrastRatio(palette.textLight, '#eef4f0')).toBeGreaterThanOrEqual(4.5)
expect(accentContrastRatio(palette.textDark, '#0d0f12')).toBeGreaterThanOrEqual(4.5)
expect(accentContrastRatio(palette.brand300, '#0d0f12')).toBeGreaterThanOrEqual(4.5)
expect(accentContrastRatio(palette.brand400, '#0d0f12')).toBeGreaterThanOrEqual(4.5)
Expand Down
Loading