Merge claude/design-tokens-build (d6675d2): theme on any element, primary-inverse roles
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -48,8 +48,9 @@ describe('shipped CSS files', () => {
|
||||
|
||||
test('the preset maps every colour role and keeps the dark variant on data-theme', () => {
|
||||
const preset = read('src/styles/tailwind.css')
|
||||
// link-inverse / focus-inverse are read through the inverse scope, not by a utility
|
||||
for (const role of Object.keys(COLOR_DEFAULTS).filter((r) => r !== 'link-inverse' && r !== 'focus-inverse')) {
|
||||
// *-inverse roles are read through the inverse scope, not by a utility
|
||||
const scoped = ['link-inverse', 'focus-inverse', 'primary-inverse', 'primary-inverse-text']
|
||||
for (const role of Object.keys(COLOR_DEFAULTS).filter((r) => !scoped.includes(r))) {
|
||||
expect(preset, role).toContain(`var(--ipal-${role})`)
|
||||
}
|
||||
expect(preset).toContain('@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));')
|
||||
@@ -127,10 +128,35 @@ describe('defineTokens / tokensToCss', () => {
|
||||
expect(light).toEqual(dark)
|
||||
const css = tokensToCss(tokens)
|
||||
expect(css).toContain('color-scheme: dark;')
|
||||
expect(css.match(/--ipal-bg: #070707;/g)).toHaveLength(2)
|
||||
expect(css.match(/--ipal-bg: #070707;/g)).toHaveLength(1)
|
||||
expect(css).toContain(':root, [data-theme="light"], :root[data-theme="dark"], [data-theme="dark"] {')
|
||||
expect(contrastReport(tokens).every((r) => r.theme === 'dark')).toBe(true)
|
||||
})
|
||||
|
||||
test('themes switch on any element, not only <html>', () => {
|
||||
const defaults = defaultTokensCss()
|
||||
expect(defaults).toContain(':root, [data-theme="light"] {')
|
||||
expect(defaults).toContain(':root[data-theme="dark"], [data-theme="dark"] {')
|
||||
const css = tokensToCss({ color: { dark: { bg: '#111' }, light: { bg: '#fefefe' } } })
|
||||
expect(css).toMatch(/:root, \[data-theme="light"\] \{\n {2}--ipal-bg: #fefefe;/)
|
||||
expect(css).toMatch(/:root\[data-theme="dark"\], \[data-theme="dark"\] \{\n {2}--ipal-bg: #111;/)
|
||||
})
|
||||
|
||||
test('primary is re-mapped inside an inverted section and checked there', () => {
|
||||
expect(defaultTokensCss()).toMatch(/\[data-surface="inverse"\] \{[^}]*--ipal-primary: var\(--ipal-primary-inverse\);/)
|
||||
const darkBrand = { color: { light: { primary: 'oklch(0.3 0.08 150)' } } }
|
||||
const warn = contrastReport(darkBrand).find((r) => r.scope === 'inverse' && r.fg === 'primary' && r.theme === 'light')
|
||||
expect(warn).toMatchObject({ level: 'warn', pass: false })
|
||||
// the dark theme's inverse surface is light: there the dark brand colour works again
|
||||
const fixed = contrastReport({
|
||||
color: {
|
||||
dark: { 'primary-inverse': 'oklch(0.3 0.08 150)', 'primary-inverse-text': 'oklch(0.98 0 0)' },
|
||||
light: { ...darkBrand.color.light, 'primary-inverse': 'oklch(0.85 0.1 150)', 'primary-inverse-text': 'oklch(0.2 0.05 150)' },
|
||||
},
|
||||
})
|
||||
expect(fixed.filter((r) => r.scope === 'inverse' && !r.pass)).toEqual([])
|
||||
})
|
||||
|
||||
test('the contrast report fails a low-contrast brand', () => {
|
||||
const rows = contrastReport({ color: { light: { primary: '#ffeb3b', 'primary-text': '#ffffff' } } })
|
||||
expect(rows.find((r) => r.theme === 'light' && r.fg === 'primary-text' && r.bg === 'primary')).toMatchObject({ pass: false })
|
||||
|
||||
Reference in New Issue
Block a user