Define the ring, card-foreground and popover-foreground

This commit is contained in:
Chris Scott committed 2026-12-03 10:58:51 -05:00
1 parent a6cdbc378d
commit ae3399ac6b
4 files changed
+41 -5

No files matched your search

+6
View File
@@ -6,7 +6,9 @@
--color-foreground: #fafafa;
--color-card: #141414;
--color-card-hover: #1a1a1a;
--color-card-foreground: #fafafa;
--color-border: #2a2a2a;
--color-ring: #d4d4d8;
--color-primary: #1d4ed8;
--color-primary-hover: #1e40af;
--color-primary-foreground: #fafafa;
@@ -16,6 +18,7 @@
--color-input: #323232;
--color-muted: #18181b;
--color-popover: #18181b;
--color-popover-foreground: #fafafa;
--color-destructive: #dc2626;
--color-destructive-foreground: #ffffff;
--color-secondary: #27272a;
@@ -53,7 +56,9 @@
--color-foreground: #111827;
--color-card: #f9fafb;
--color-card-hover: #f3f4f6;
--color-card-foreground: #111827;
--color-border: #e5e7eb;
--color-ring: #6b7280;
--color-primary: #1d4ed8;
--color-primary-hover: #1e40af;
--color-primary-foreground: #ffffff;
@@ -63,6 +68,7 @@
--color-input: #e5e7eb;
--color-muted: #f4f4f5;
--color-popover: #ffffff;
--color-popover-foreground: #111827;
--color-destructive: #dc2626;
--color-destructive-foreground: #ffffff;
--color-secondary: #f4f4f5;
+29
View File
@@ -1,4 +1,5 @@
import indexHtml from '../../../index.html?raw'
import indexCss from '../../index.css?raw'
import { beforeEach, describe, expect, it } from 'vitest'
import {
APPEARANCE_STORAGE_KEY,
@@ -14,6 +15,10 @@ function themeColorMeta(): string | null {
return document.querySelector('meta[name="theme-color"]')?.getAttribute('content') ?? null
}
function countOccurrences(source: string, needle: string): number {
return source.split(needle).length - 1
}
function appearanceSnapshot() {
const raw = window.localStorage.getItem(APPEARANCE_STORAGE_KEY)
if (!raw) throw new Error('appearance snapshot missing')
@@ -35,9 +40,33 @@ describe('applyColorTheme', () => {
expect(root.style.getPropertyValue('--color-foreground')).toBe('#f8f8f2')
expect(root.style.getPropertyValue('--color-primary')).toBe('#bd93f9')
expect(root.style.getPropertyValue('--color-destructive')).toBe('#ff5555')
expect(root.style.getPropertyValue('--color-ring')).toBe('color-mix(in oklab, #f8f8f2 62%, #1d1e28)')
expect(root.style.getPropertyValue('--color-card-foreground')).toBe('#f8f8f2')
expect(root.style.getPropertyValue('--color-popover-foreground')).toBe('#f8f8f2')
expect(themeColorMeta()).toBe('#1d1e28')
})
it('derives the focus ring and the card and popover foregrounds from the palette', () => {
const dark = resolveColorThemeTokens('dracula', true)
const light = resolveColorThemeTokens('dracula', false)
expect(dark?.ring).toBe(dark?.['muted-foreground'])
expect(dark?.['card-foreground']).toBe('#f8f8f2')
expect(dark?.['popover-foreground']).toBe('#f8f8f2')
expect(light?.['card-foreground']).toBe('#1f1f2f')
expect(light?.['popover-foreground']).toBe('#1f1f2f')
expect(resolveColorThemeTokens('oc-2', true)?.ring).toBe('#707070')
})
it('defines every themed token once for dark mode and once for light mode', () => {
const keys = Object.keys(resolveColorThemeTokens('dracula', true) ?? {})
expect(keys).toEqual(expect.arrayContaining(['ring', 'card-foreground', 'popover-foreground']))
for (const key of keys) {
expect(countOccurrences(indexCss, `--color-${key}:`)).toBe(2)
}
})
it('applies the Dracula light palette when the mode is light', () => {
applyColorTheme(document.documentElement, 'dracula', false)
+6
View File
@@ -9,7 +9,9 @@ const MANAGER_THEME_TOKENS = [
'foreground',
'card',
'card-hover',
'card-foreground',
'border',
'ring',
'primary',
'primary-hover',
'primary-foreground',
@@ -18,6 +20,7 @@ const MANAGER_THEME_TOKENS = [
'input',
'muted',
'popover',
'popover-foreground',
'destructive',
'destructive-foreground',
'secondary',
@@ -134,11 +137,14 @@ export function resolveColorThemeTokens(
foreground: ink,
card: mix(4),
'card-hover': mix(7),
'card-foreground': ink,
popover: mix(5),
'popover-foreground': ink,
muted: mix(6),
accent: mix(10),
secondary: mix(10),
border: mix(14),
ring: mutedForeground,
input: mix(16),
'muted-foreground': mutedForeground,
primary,
@@ -3,10 +3,6 @@ import textPart from '../../components/message/TextPart.tsx?raw'
import { describe, expect, it } from 'vitest'
import { resolveColorThemeTokens } from './colorTheme'
function countOccurrences(source: string, needle: string): number {
return source.split(needle).length - 1
}
describe('syntax highlight stylesheet', () => {
it('does not import GitHub highlight.js stylesheets', () => {
expect(indexCss).not.toContain('highlight.js/styles')
@@ -26,7 +22,6 @@ describe('syntax highlight stylesheet', () => {
for (const key of syntaxKeys) {
expect(indexCss).toContain(`var(--color-${key})`)
expect(countOccurrences(indexCss, `--color-${key}:`)).toBe(2)
}
})
})