feat(design): switch to IMS Admin tokens, Geist and the 1px-rule gate

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 09:26:08 +08:00
co-authored by Claude Haiku 4.5
parent 9ed8c97c24
commit 01343d732e
18 changed files with 220 additions and 179 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ describe('Sidebar (Modernist shell)', () => {
it('is flat: a 2px divider rule, ground fill and no rounded corners except the avatar', () => {
const { container } = render(<Sidebar role="hse" userName="Ada" userEmail="" />)
const aside = container.querySelector('aside')
expect(aside?.className).toContain('border-r-2')
expect(aside?.className).toContain('border-r')
expect(aside?.className).toContain('bg-ground')
const rounded = container.innerHTML.match(/rounded[\w-]*/g) ?? []
expect(rounded.every(r => r === 'rounded-full')).toBe(true)
+1 -1
View File
@@ -35,7 +35,7 @@ describe('Modal (Modernist dialog)', () => {
)
const html = screen.getByRole('dialog').innerHTML
expect(html).not.toMatch(/rounded/)
expect(html).toContain('border-b-2')
expect(html).toContain('border-b')
})
it('closes from the X button and on Escape', () => {
+66 -43
View File
@@ -4,59 +4,82 @@ import path from 'path'
const css = readFileSync(path.resolve(__dirname, '../../app/globals.css'), 'utf8')
describe('Modernist tokens in globals.css', () => {
describe('IMS Admin tokens in globals.css', () => {
it.each([
['--color-bg', '#f3f2f2'],
['--color-surface', '#eae9e9'],
['--color-text', '#201e1d'],
['--color-accent', '#ec3013'],
['--color-accent-700', '#ae1800'],
['--color-neutral-900', '#2d2b2b'],
['--color-ink', '#1f1f1f'],
['--color-ink-2', '#303030'],
['--color-ink-3', '#4a4a4a'],
['--color-muted', '#616161'],
['--color-faint', '#8a8a8a'],
['--color-rule', '#ebebeb'],
['--color-rule-2', '#e3e3e3'],
['--color-ring', '#d4d4d4'],
['--color-surface', '#ffffff'],
['--color-surface-2', '#f7f7f7'],
['--color-ground', '#f1f1f1'],
['--color-accent', '#0f766e'],
['--color-accent-tint', '#f2f7f6'],
['--color-accent-tint-2', '#e6f4f1'],
['--color-danger', '#b3261e'],
['--color-topbar', '#1a1a1a'],
])('declares %s as %s', (name, value) => {
expect(css).toMatch(new RegExp(`${name}:\\s*${value}`, 'i'))
expect(css).toMatch(new RegExp(`${name}:\\s*${value}\\b`, 'i'))
})
it.each(['xs', 'sm', 'md', 'lg', 'xl', '2xl', '3xl', '4xl'])('zeroes --radius-%s', size => {
expect(css).toMatch(new RegExp(`--radius-${size}:\\s*0px`))
it.each([
['amber', '#fff1c2', '#6b4a00'],
['blue', '#e0efff', '#00527c'],
['violet', '#ede7ff', '#4b2e99'],
['orange', '#ffe6cf', '#7a3a00'],
['indigo', '#e3e8ff', '#2c3e8f'],
['green', '#d7f4e3', '#0c5132'],
['grey', '#ebebeb', '#4a4a4a'],
['red', '#fee3e0', '#8e1f0b'],
])('declares the %s status pair', (hue, bg, fg) => {
expect(css).toMatch(new RegExp(`--color-st-${hue}-bg:\\s*${bg}`, 'i'))
expect(css).toMatch(new RegExp(`--color-st-${hue}-fg:\\s*${fg}`, 'i'))
})
it('zeroes the bare --radius used by the plain rounded class', () => {
expect(css).toMatch(/--radius:\s*0px/)
it('sets the radius scale: md 8, xl 12', () => {
expect(css).toMatch(/--radius-md:\s*8px/)
expect(css).toMatch(/--radius-xl:\s*12px/)
})
it('declares the card and floating shadows', () => {
expect(css).toMatch(/--shadow-card:\s*0 0 0 1px rgba\(0, ?0, ?0, ?\.08\), 0 1px 2px rgba\(0, ?0, ?0, ?\.06\)/)
expect(css).toMatch(/--shadow-float:\s*0 0 0 1px rgba\(0, ?0, ?0, ?\.1\), 0 12px 32px rgba\(0, ?0, ?0, ?\.18\)/)
})
it('declares the component shadows', () => {
for (const name of ['drawer', 'primary', 'secondary', 'input', 'chip', 'chip-set']) {
expect(css).toMatch(new RegExp(`--shadow-${name}:`))
}
})
it('uses Geist through the next/font variables', () => {
expect(css).toMatch(/--font-sans:\s*var\(--font-geist\)/)
expect(css).toMatch(/--font-mono:\s*var\(--font-geist-mono\)/)
})
it('keeps the legacy remaps so unmigrated pages still render', () => {
expect(css).toMatch(/--color-gray-100:\s*var\(--color-neutral-200\)/)
expect(css).toMatch(/--color-blue-600:\s*var\(--color-accent\)/)
expect(css).toMatch(/--color-red-600:\s*var\(--color-danger\)/)
expect(css).toMatch(/--color-divider:/)
})
it('styles keyboard focus with the 2px accent ring', () => {
expect(css).toMatch(/:focus-visible\s*\{[^}]*outline:\s*2px solid var\(--color-accent\)/)
})
it('has no dark mode block and no Modernist leftovers', () => {
expect(css).not.toContain('prefers-color-scheme')
expect(css).not.toMatch(/ec3013/i)
expect(css).not.toMatch(/archivo/i)
})
it('has no stray comment terminator before @theme', () => {
const head = css.slice(0, css.indexOf('@theme'))
expect(head.match(/\*\//g)?.length).toBe(head.match(/\/\*/g)?.length)
})
it('remaps the gray ramp onto the neutral ramp', () => {
expect(css).toMatch(/--color-gray-100:\s*var\(--color-neutral-200\)/)
expect(css).toMatch(/--color-gray-900:\s*var\(--color-text\)/)
})
it('remaps the blue ramp onto the accent ramp', () => {
expect(css).toMatch(/--color-blue-600:\s*var\(--color-accent\)/)
expect(css).toMatch(/--color-blue-700:\s*var\(--color-accent-700\)/)
})
it('remaps the red ramp onto the accent ramp, with body-size steps on accent-700', () => {
expect(css).toMatch(/--color-red-600:\s*var\(--color-accent-700\)/)
expect(css).toMatch(/--color-red-50:\s*var\(--color-accent-100\)/)
})
it('maps shadows onto the Modernist elevation tokens', () => {
expect(css).toMatch(/--shadow-2xl:\s*var\(--shadow-lg\)/)
})
it('uses Archivo through the next/font variable', () => {
expect(css).toMatch(/--font-sans:\s*var\(--font-archivo\)/)
})
it('has no dark mode block', () => {
expect(css).not.toContain('prefers-color-scheme')
})
it('styles keyboard focus with the 2px accent ring', () => {
expect(css).toMatch(/:focus-visible\s*\{[^}]*outline:\s*2px solid var\(--color-accent\)/)
})
})
+22 -12
View File
@@ -1,18 +1,24 @@
import { describe, it, expect } from 'vitest'
import { findViolations, ROUND_ALLOWED } from '../../scripts/check-design-gates.mjs'
import { findViolations } from '../../scripts/check-design-gates.mjs'
const rules = (src: string, file = 'components/x.tsx'): string[] =>
(findViolations(src, file) as Array<{ rule: string }>).map(v => v.rule)
describe('design gates', () => {
it('flags rounded corner classes', () => {
expect(rules('<div className="rounded-lg p-2" />')).toContain('no-rounded')
expect(rules('<div className="p-2 hover:rounded-md" />')).toContain('no-rounded')
describe('design gates (IMS Admin refresh)', () => {
it('allows the radius scale, including rounded-full', () => {
expect(rules('<div className="rounded-md rounded-xl rounded-[5px] rounded-full" />')).toEqual([])
})
it('flags rounded-full outside the allowlist and accepts it inside', () => {
expect(rules('<div className="rounded-full" />')).toContain('no-rounded-full')
expect(rules('<div className="rounded-full" />', ROUND_ALLOWED[0])).not.toContain('no-rounded-full')
it.each(['border-2', 'border-b-2', 'border-t-2', 'border-l-2', 'border-r-2'])('flags %s', cls => {
expect(rules(`<div className="${cls}" />`)).toContain('no-2px-border')
})
it('accepts 1px rules', () => {
expect(rules('<div className="border border-b border-rule" />')).toEqual([])
})
it('flags the retired Archivo font', () => {
expect(rules("import { Archivo } from 'next/font/google'")).toContain('no-archivo')
})
it('flags off-palette colors but accepts remapped gray, blue and red', () => {
@@ -21,7 +27,11 @@ describe('design gates', () => {
expect(rules('<p className="text-gray-500 text-blue-700 bg-red-50" />')).toEqual([])
})
it('flags hard-coded hex colors', () => {
it('accepts the status token classes', () => {
expect(rules('<span className="bg-st-green-bg text-st-green-fg" />')).toEqual([])
})
it('flags hard-coded hex colors, including the retired Modernist red', () => {
expect(rules('<div style={{ color: "#ec3013" }} />')).toContain('no-hex')
expect(rules('<p>&#39;quoted&#39;</p>')).not.toContain('no-hex')
})
@@ -35,11 +45,11 @@ describe('design gates', () => {
})
it('reports file and 1-based line numbers', () => {
const v = findViolations('a\n<div className="rounded-md" />', 'components/y.tsx')
expect(v[0]).toMatchObject({ file: 'components/y.tsx', line: 2, rule: 'no-rounded' })
const v = findViolations('a\n<div className="border-2" />', 'components/y.tsx')
expect(v[0]).toMatchObject({ file: 'components/y.tsx', line: 2, rule: 'no-2px-border' })
})
it('accepts clean on-system markup', () => {
expect(rules('<div className="bg-surface border border-divider p-4 text-ink shadow-sm" />')).toEqual([])
expect(rules('<div className="bg-surface border border-rule p-4 text-ink shadow-card rounded-xl" />')).toEqual([])
})
})