diff --git a/docs/superpowers/plans/2026-09-30-modernist-design-system-restyle.md b/docs/superpowers/plans/2026-09-30-modernist-design-system-restyle.md new file mode 100644 index 0000000..7fe58dd --- /dev/null +++ b/docs/superpowers/plans/2026-09-30-modernist-design-system-restyle.md @@ -0,0 +1,1918 @@ +# Modernist Design System Restyle Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Restyle the whole IMS app to the Modernist design system, and leave guardrails so future development stays on-system. + +**Architecture:** Declare the Modernist tokens in `app/globals.css` with Tailwind v4 `@theme static`, remapping the existing `gray-*` and `blue-*` palettes and zeroing all radii so existing utility classes restyle automatically. A small codemod removes dead `rounded-*` classes and swaps `bg-white` and gray borders. Thin shared components (`Button`, `Tag`, `StatusTag`, `PriorityTag`, `Field`, `Card`, `Modal`) cover what token remapping cannot (flush-left labels, status colors). A gate script (`npm run check:design`) fails on off-system classes. + +**Tech Stack:** Next.js 16.3.7 (App Router), React 19, Tailwind CSS v4 (`@tailwindcss/postcss`), `lucide-react`, Archivo via `next/font/google`, vitest 4 + jsdom + `@testing-library/react`. + +**Spec:** `docs/superpowers/specs/2026-09-30-modernist-design-system-design.md` + +## Global Constraints + +- Design source of truth: `design-system/_ds/modernist-6062679c-a4aa-42a4-9043-28fea370dda9/readme.md` and `styles.css`. `design-system/IMS Admin.dc.html` (Geist, teal, 12px radius) is NOT implemented. +- Take every color, font, spacing, radius and shadow from tokens (`var(--color-*)`, `var(--font-*)`, `var(--space-*)`, `var(--radius-*)`, `var(--shadow-*)`). Never hard-code a hex, font name, or px value the tokens already carry. +- Zero corner radius anywhere. `rounded-full` is kept only for circular avatars and radio dots. +- Strong 2px rules (`var(--color-divider)`) between major sections. Do not soften into hairlines. +- Button labels are flush left, including labels inside wide buttons. Never center button labels or hero copy. +- Icons: Lucide (`lucide-react`). Fonts: Archivo (variable font) for headings and body. +- Light ground only (`--color-bg` #f3f2f2, `--color-text` #201e1d, accent #ec3013). No dark mode. +- Body-size text in the accent uses `accent-700`, never the accent itself (accent on ground is 3:1, for chrome and large text only). +- Interactive states are themed: hover tint, pressed step from the accent ramp, `:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }`. Disabled controls drop to 45% opacity. +- Status mapping (approved): needs attention or overdue or open or reported or severity 4 to 5 = `tag-accent`; in progress (triaged, investigating, CAPA pending, verification, in_progress, pending_verification) = `tag-outline`; done (closed, verified, completed) and low or informational = `tag-neutral`. Status is never color alone: keep the text label and add a Lucide icon. +- Incident evidence photos and thumbnails stay full color. `.grayscale` is for decorative or brand photography only. +- No database, API, auth or routing changes. PDFs (JKKP 6/7/8, incident report) and email templates are out of scope. +- Deployment: build locally only, NEVER run `next build` or `npm ci` on the server. Server path `/srv/apps/ims/app` (`/var/www/ims` is a symlink). Never overwrite or delete `.env*` files. Restart with `sudo systemctl restart ims`. Never restart if `.next/BUILD_ID` is missing. Do not deploy without the user's go-ahead. + +## File Structure + +**Create** +- `tests/design/tokens.test.ts` — contract test for the token sheet in `globals.css` +- `scripts/modernist-codemod.mjs` — `transformSource()` plus CLI that rewrites class names +- `tests/scripts/modernist-codemod.test.ts` — unit tests for the codemod +- `components/ui/button.tsx`, `tag.tsx`, `status-tag.tsx`, `field.tsx`, `card.tsx` — shared components +- `tests/components/ui/*.test.tsx` — tests for each shared component +- `scripts/check-design-gates.mjs` — gate script, exposed as `npm run check:design` +- `tests/scripts/check-design-gates.test.ts` — tests for the gate rules + +**Modify** +- `app/globals.css` — tokens, theme remap, base layer +- `app/layout.tsx` — Archivo replaces Geist +- `package.json` — `lucide-react`, `check:design` script +- `components/ui/modal.tsx`, `components/layout/sidebar.tsx`, `components/notifications/bell.tsx`, `app/(protected)/layout.tsx` +- 10 files holding status, priority or severity color maps (listed in Task 6) +- All remaining TSX files flagged by the gate script (Task 7) +- `CLAUDE.md`, plus memory file `ims-design-system.md` and `MEMORY.md` index (Task 8) + +--- + +### Task 1: Tokens, theme remap, and Archivo font + +**Files:** +- Create: `tests/design/tokens.test.ts` +- Modify: `app/globals.css` (full rewrite), `app/layout.tsx`, `package.json` (via npm install) + +**Interfaces:** +- Consumes: nothing. +- Produces: Tailwind utilities `bg-ground`, `bg-surface`, `text-ink`, `bg-accent`, `text-accent`, `border-divider`, `bg-accent-100…900`, `bg-neutral-100…900`; CSS vars `--color-bg`, `--color-surface`, `--color-text`, `--color-accent`, `--color-divider`, `--shadow-sm|md|lg`, `--font-sans`; `gray-*` remapped to the neutral ramp and `blue-*` remapped to the accent ramp; every `rounded-*` size resolves to 0. + +- [ ] **Step 1: Create a working branch and install Lucide** + +```bash +cd /Users/yapweeihan/Projects/IMS.nosync +git checkout -b feat/modernist-restyle +npm install lucide-react +``` + +Expected: `lucide-react` appears under `dependencies` in `package.json`. Leave the untracked `design-system/*` files and the deleted `design-system/ims-admin/MASTER.md` alone; they are handled in Task 8. + +- [ ] **Step 2: Write the failing token contract test** + +Create `tests/design/tokens.test.ts`: + +```ts +import { describe, it, expect } from 'vitest' +import { readFileSync } from 'fs' +import path from 'path' + +const css = readFileSync(path.resolve(__dirname, '../../app/globals.css'), 'utf8') + +describe('Modernist 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'], + ])('declares %s as %s', (name, value) => { + expect(css).toMatch(new RegExp(`${name}:\\s*${value}`, '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('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('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\)/) + }) +}) +``` + +- [ ] **Step 3: Run the test to verify it fails** + +Run: `npx vitest run tests/design/tokens.test.ts` +Expected: FAIL (most assertions, because `globals.css` still has the old tokens). + +- [ ] **Step 4: Rewrite `app/globals.css`** + +Replace the whole file with: + +```css +@import "tailwindcss"; + +/* Modernist tokens. Source of truth: design-system/_ds/modernist-*/styles.css. + `static` emits every variable so plain CSS can use var(--color-*) too. */ +@theme static { + --color-bg: #f3f2f2; + --color-surface: #eae9e9; + --color-text: #201e1d; + --color-accent: #ec3013; + --color-accent-2: #e15b47; + --color-divider: color-mix(in srgb, #201e1d 40%, transparent); + + /* Utility-friendly aliases: bg-ground, text-ink */ + --color-ground: var(--color-bg); + --color-ink: var(--color-text); + + --color-neutral-100: #f8f4f4; + --color-neutral-200: #eae7e7; + --color-neutral-300: #d7d3d3; + --color-neutral-400: #bab6b6; + --color-neutral-500: #9b9797; + --color-neutral-600: #7d7979; + --color-neutral-700: #605d5d; + --color-neutral-800: #444141; + --color-neutral-900: #2d2b2b; + + --color-accent-100: #fff2ef; + --color-accent-200: #ffe0d9; + --color-accent-300: #ffc4b8; + --color-accent-400: #ff9783; + --color-accent-500: #ff563c; + --color-accent-600: #dd2b0f; + --color-accent-700: #ae1800; + --color-accent-800: #7c1405; + --color-accent-900: #4d170e; + + --color-accent-2-100: #fff2ef; + --color-accent-2-200: #ffe0da; + --color-accent-2-300: #ffc4b9; + --color-accent-2-400: #ff9784; + --color-accent-2-500: #ef6853; + --color-accent-2-600: #c94b39; + --color-accent-2-700: #9e3526; + --color-accent-2-800: #71261b; + --color-accent-2-900: #471d16; + + /* Existing gray-* utilities render on the neutral ramp. */ + --color-gray-50: var(--color-neutral-100); + --color-gray-100: var(--color-neutral-200); + --color-gray-200: var(--color-neutral-300); + --color-gray-300: var(--color-neutral-400); + --color-gray-400: var(--color-neutral-500); + --color-gray-500: var(--color-neutral-600); + --color-gray-600: var(--color-neutral-700); + --color-gray-700: var(--color-neutral-800); + --color-gray-800: var(--color-neutral-900); + --color-gray-900: var(--color-text); + --color-gray-950: var(--color-text); + + /* Existing blue-* utilities render on the accent ramp. 600 is the canonical + accent; 700 and darker are safe for body-size text. */ + --color-blue-50: var(--color-accent-100); + --color-blue-100: var(--color-accent-100); + --color-blue-200: var(--color-accent-200); + --color-blue-300: var(--color-accent-300); + --color-blue-400: var(--color-accent-400); + --color-blue-500: var(--color-accent-500); + --color-blue-600: var(--color-accent); + --color-blue-700: var(--color-accent-700); + --color-blue-800: var(--color-accent-800); + --color-blue-900: var(--color-accent-900); + --color-blue-950: var(--color-accent-900); + + /* Zero corner radius, everywhere. */ + --radius-xs: 0px; + --radius-sm: 0px; + --radius-md: 0px; + --radius-lg: 0px; + --radius-xl: 0px; + --radius-2xl: 0px; + --radius-3xl: 0px; + --radius-4xl: 0px; + + /* Elevation, tuned to the ground. */ + --shadow-sm: 0 1px 2px color-mix(in srgb, #2d2b2b 14%, transparent); + --shadow-md: 0 3px 10px color-mix(in srgb, #2d2b2b 16%, transparent); + --shadow-lg: 0 12px 32px color-mix(in srgb, #2d2b2b 22%, transparent); + --shadow-xl: var(--shadow-lg); + --shadow-2xl: var(--shadow-lg); + + --font-sans: var(--font-archivo), system-ui, sans-serif; + --font-heading: var(--font-archivo), system-ui, sans-serif; +} + +@layer base { + html { + background: var(--color-bg); + } + + body { + background: var(--color-bg); + color: var(--color-text); + font-family: var(--font-sans); + font-size: 15px; + line-height: 1.55; + } + + h1, h2, h3, h4, h5, h6 { + font-family: var(--font-heading); + font-weight: 800; + line-height: 1.12; + letter-spacing: -0.015em; + } + + :focus { + outline: none; + } + + :focus-visible { + outline: 2px solid var(--color-accent); + outline-offset: 2px; + } + + ::selection { + background: color-mix(in srgb, var(--color-accent) 30%, transparent); + } + + input, + textarea, + select { + color: var(--color-text); + } + + input::placeholder, + textarea::placeholder { + color: color-mix(in srgb, var(--color-text) 55%, transparent); + } + + button:disabled, + input:disabled, + select:disabled, + textarea:disabled { + opacity: 0.45; + cursor: not-allowed; + } +} + +.grayscale { + filter: grayscale(1) contrast(1.08); +} +``` + +- [ ] **Step 5: Swap Geist for Archivo in `app/layout.tsx`** + +Replace the font imports and instances. The top of the file becomes: + +```tsx +import type { Metadata } from 'next' +import { Archivo } from 'next/font/google' +import './globals.css' +import { I18nProvider } from '@/lib/i18n/context' +import { getLocale, loadMessages } from '@/lib/i18n/server' + +const archivo = Archivo({ + variable: '--font-archivo', + subsets: ['latin'], +}) +``` + +(Omitting `weight` loads the variable font, so every weight from 400 to 800 renders exactly.) Change the `` element's className to: + +```tsx + className={`${archivo.variable} h-full antialiased`} +``` + +Delete the `geistSans` and `geistMono` constants and their usages. Confirm nothing else uses them: `grep -rn "font-geist\|geistMono\|geistSans" app components` must print nothing (if `font-mono` is used somewhere, it now falls back to the Tailwind default monospace stack, which is fine). + +- [ ] **Step 6: Run the token test, then verify the compiled CSS** + +Run: `npx vitest run tests/design/tokens.test.ts` +Expected: PASS (all). + +Run the production build and inspect the emitted CSS: + +```bash +npm run build 2>&1 | tail -5 +grep -ho '\.rounded-xl{[^}]*}' .next/static/chunks/*.css | head -2 +grep -ho '\-\-radius-xl:[^;}]*' .next/static/chunks/*.css | head -1 +grep -ho '\-\-color-blue-600:[^;}]*' .next/static/chunks/*.css | head -1 +grep -ho '\.rounded{[^}]*}' .next/static/chunks/*.css | head -1 +``` + +Expected: +- build succeeds, +- `.rounded-xl{border-radius:var(--radius-xl)}` and `--radius-xl:0px`, +- `--color-blue-600:var(--color-accent)`. +- Check the bare `.rounded{...}` output: if it is a literal such as `0.25rem` rather than a var resolving to 0, add `--radius: 0px;` to the `@theme static` block and rebuild. The codemod in Task 2 removes bare `rounded` anyway, so this is belt and braces. + +- [ ] **Step 7: Commit** + +```bash +git add app/globals.css app/layout.tsx package.json package-lock.json tests/design/tokens.test.ts +git commit -m "feat(design): add Modernist tokens, theme remap and Archivo font + +Co-Authored-By: Claude Haiku 4.5 " +``` + +--- + +### Task 2: Class-name codemod + +**Files:** +- Create: `scripts/modernist-codemod.mjs`, `tests/scripts/modernist-codemod.test.ts` +- Modify: every `app/**/*.tsx` and `components/**/*.tsx` whose `className` matches a rule (written by the script) + +**Interfaces:** +- Consumes: Task 1 utilities `bg-surface`, `border-divider`, `shadow-lg`. +- Produces: `export function transformSource(src: string): string` (pure, idempotent), and a CLI `node scripts/modernist-codemod.mjs [--dry]` that prints `changed N files`. + +Rules, applied only inside `className=` attribute values (`"…"`, `'…'`, `{"…"}`, `{'…'}`, `` {`…`} ``): +1. Remove `rounded`, `rounded-{xs|sm|md|lg|xl|2xl|3xl|4xl|none}` and side forms (`rounded-t-lg`, `rounded-br`, …), including variant prefixes (`hover:rounded-lg`). Keep `rounded-full`. +2. `bg-white` becomes `bg-surface` (variants and `/opacity` kept). +3. `border-gray-100|200|300` becomes `border-divider`; `divide-gray-100|200|300` becomes `divide-divider`. +4. `shadow-xl` and `shadow-2xl` become `shadow-lg`. +5. Drop a now-empty `className=""` attribute and collapse repeated spaces. + +- [ ] **Step 1: Write the failing tests** + +Create `tests/scripts/modernist-codemod.test.ts`: + +```ts +import { describe, it, expect } from 'vitest' +// @ts-expect-error plain .mjs script without types +import { transformSource } from '../../scripts/modernist-codemod.mjs' + +const t = (s: string): string => transformSource(s) + +describe('modernist codemod', () => { + it('removes rounded-* sizes but keeps rounded-full', () => { + expect(t('
')).toBe('
') + expect(t('
')).toBe('
') + expect(t('
')).toBe('
') + }) + + it('removes variant-prefixed rounded classes whole', () => { + expect(t('')).toBe('') + }) + + it('swaps bg-white for bg-surface, keeping variants and opacity', () => { + expect(t('
')).toBe('
') + expect(t('
')).toBe('
') + }) + + it('swaps light gray borders and dividers for the divider token', () => { + expect(t('
')).toBe('
') + expect(t('
    ')).toBe('
      ') + }) + + it('leaves dark gray borders alone', () => { + expect(t('
      ')).toBe('
      ') + }) + + it('swaps heavy shadows for shadow-lg', () => { + expect(t('
      ')).toBe('
      ') + expect(t('
      ')).toBe('
      ') + expect(t('
      ')).toBe('
      ') + }) + + it('handles template literals with conditionals', () => { + const src = '
      ' + expect(t(src)).toBe('
      ') + }) + + it('drops a className that becomes empty', () => { + expect(t('
      ')).toBe('
      ') + }) + + it('does not touch text outside className', () => { + const src = '

      The corners are rounded and bg-white is a word.

      ' + expect(t(src)).toBe(src) + }) + + it('is idempotent', () => { + const once = t('
      ') + expect(t(once)).toBe(once) + }) +}) +``` + +- [ ] **Step 2: Run the tests to verify they fail** + +Run: `npx vitest run tests/scripts/modernist-codemod.test.ts` +Expected: FAIL ("Cannot find module" for the script). + +- [ ] **Step 3: Write the codemod** + +Create `scripts/modernist-codemod.mjs`: + +```js +import { readdirSync, readFileSync, writeFileSync, statSync } from 'node:fs' +import path from 'node:path' +import { fileURLToPath } from 'node:url' + +const CLASS_ATTR = + /className=(?:"[^"]*"|'[^']*'|\{"[^"]*"\}|\{'[^']*'\}|\{`(?:[^`\\]|\\.)*`\})/g + +const ROUNDED = + /(?&1 | tail -8 +npm run build 2>&1 | tail -6 +grep -rhoE '(^|[\s"'"'"'`:])rounded(-(xs|sm|md|lg|xl|2xl|3xl|4xl|t|b|l|r|tl|tr|bl|br))*[\s"'"'"'`]' app components --include='*.tsx' | sort | uniq -c | sort -rn | head +``` + +Expected: all tests pass (the suite has no class-name assertions), the build passes, and the last command prints only leftovers that sit outside `className` (for example constants such as `const base = '...'`). List any leftovers and fix them by hand in this task: delete the `rounded-*` token, keep `rounded-full`. + +- [ ] **Step 7: Commit** + +```bash +git add scripts/modernist-codemod.mjs tests/scripts/modernist-codemod.test.ts app components +git commit -m "refactor(design): drop rounded classes, swap bg-white and gray borders for tokens + +Co-Authored-By: Claude Haiku 4.5 " +``` + +### Task 3: Shared UI primitives + +**Files:** +- Create: `components/ui/cx.ts`, `components/ui/button.tsx`, `components/ui/tag.tsx`, `components/ui/status-tag.tsx`, `components/ui/field.tsx`, `components/ui/card.tsx`, `components/ui/table-styles.ts` +- Test: `tests/components/ui/primitives.test.tsx` + +**Interfaces:** +- Consumes: Task 1 utilities (`bg-accent`, `bg-surface`, `text-ink`, `border-divider`, `accent-*`, `neutral-*`). +- Produces (later tasks import these exactly): + - `cx(...parts: Array): string` + - `Button({ variant?: 'primary' | 'secondary' | 'ghost' | 'icon', block?: boolean } & ButtonHTMLAttributes)`; default `type="button"` + - `Tag({ variant: 'accent' | 'neutral' | 'outline', children })` + - `statusTone(status: string): 'accent' | 'outline' | 'neutral'`, `StatusTag({ status: string, children?: ReactNode })`, `PriorityTag({ priority: string, children?: ReactNode })` + - `Field({ label, htmlFor, children })`, `Input`, `Textarea`, `Select` (native elements sharing `INPUT_CLASS`) + - `Card({ kicker?, title?, meta?, children? })` + - `TABLE`, `TH`, `TR`, `TD` class-string constants from `table-styles.ts` + +- [ ] **Step 1: Write the failing tests** + +Create `tests/components/ui/primitives.test.tsx`: + +```tsx +import { describe, it, expect } from 'vitest' +import { render, screen } from '@testing-library/react' +import { Button } from '@/components/ui/button' +import { Tag } from '@/components/ui/tag' +import { StatusTag, PriorityTag, statusTone } from '@/components/ui/status-tag' +import { Field, Input } from '@/components/ui/field' +import { Card } from '@/components/ui/card' +import { TABLE, TH, TR, TD } from '@/components/ui/table-styles' + +describe('Button', () => { + it('renders a primary accent button that is type=button and flush left', () => { + render() + const btn = screen.getByRole('button', { name: 'Save' }) + expect(btn.getAttribute('type')).toBe('button') + expect(btn.className).toContain('bg-accent') + expect(btn.className).toContain('justify-start') + expect(btn.className).not.toContain('justify-center') + }) + + it('block buttons span the row and stay flush left', () => { + render() + const btn = screen.getByRole('button', { name: 'Go' }) + expect(btn.className).toContain('w-full') + expect(btn.className).toContain('justify-start') + }) + + it('icon buttons are square and centered', () => { + render() + expect(screen.getByRole('button').className).not.toMatch(/rounded/) + }) +}) + +describe('Tag', () => { + it.each([ + ['accent', 'bg-accent-100'], + ['neutral', 'bg-neutral-100'], + ['outline', 'border-accent'], + ] as const)('%s variant carries %s', (variant, cls) => { + render(Label) + expect(screen.getByText('Label').className).toContain(cls) + }) +}) + +describe('statusTone', () => { + it.each([ + ['reported', 'accent'], + ['triaged', 'outline'], + ['investigating', 'outline'], + ['capa_pending', 'outline'], + ['verification', 'outline'], + ['closed', 'neutral'], + ['open', 'accent'], + ['in_progress', 'outline'], + ['overdue', 'accent'], + ['pending_verification', 'outline'], + ['verified', 'neutral'], + ['reopened', 'accent'], + ['something_else', 'neutral'], + ])('%s maps to %s', (status, tone) => { + expect(statusTone(status)).toBe(tone) + }) +}) + +describe('StatusTag', () => { + it('shows a humanized text label plus an icon, never color alone', () => { + const { container } = render() + expect(screen.getByText('CAPA Pending')).toBeTruthy() + expect(container.querySelector('svg')).not.toBeNull() + }) + + it('accepts a label override', () => { + render(Late) + expect(screen.getByText('Late')).toBeTruthy() + }) +}) + +describe('PriorityTag', () => { + it.each([ + ['high', 'bg-accent-100'], + ['med', 'border-accent'], + ['low', 'bg-neutral-100'], + ])('%s priority uses %s', (priority, cls) => { + const { container } = render() + expect(container.firstElementChild?.className).toContain(cls) + }) +}) + +describe('Field and Input', () => { + it('associates the label with the input', () => { + render( + + + , + ) + const input = screen.getByLabelText('Email') + expect(input.className).toContain('bg-surface') + expect(input.className).toContain('border-divider') + }) +}) + +describe('Card', () => { + it('renders kicker, title, body and meta on the surface fill', () => { + const { container } = render( + + Body text + , + ) + expect(screen.getByText('Open')).toBeTruthy() + expect(screen.getByText('Forklift')).toBeTruthy() + expect(screen.getByText('Body text')).toBeTruthy() + expect(screen.getByText('Due Friday')).toBeTruthy() + expect(container.firstElementChild?.className).toContain('bg-surface') + }) +}) + +describe('table styles', () => { + it('uses a 2px header rule and 1px row rules', () => { + expect(TH).toContain('border-b-2') + expect(TH).toContain('border-divider') + expect(TD).toContain('border-b') + expect(TR).toContain('hover:bg-ink/4') + expect(TABLE).toContain('w-full') + }) +}) +``` + +- [ ] **Step 2: Run the tests to verify they fail** + +Run: `npx vitest run tests/components/ui/primitives.test.tsx` +Expected: FAIL (modules not found). + +- [ ] **Step 3: Write the primitives** + +`components/ui/cx.ts`: + +```ts +export const cx = (...parts: Array): string => + parts.filter(Boolean).join(' ') +``` + +`components/ui/button.tsx`: + +```tsx +import type { ButtonHTMLAttributes } from 'react' +import { cx } from './cx' + +type Variant = 'primary' | 'secondary' | 'ghost' | 'icon' + +const BASE = + 'inline-flex items-center justify-start gap-1.5 text-left font-extrabold text-sm leading-tight ' + + 'border border-transparent cursor-pointer transition-colors ' + + 'disabled:opacity-45 disabled:cursor-not-allowed' + +const VARIANTS: Record = { + primary: 'bg-accent text-ground px-3.5 py-2 hover:bg-accent-600 active:bg-accent-700', + secondary: 'border-divider text-ink px-3.5 py-2 hover:bg-ink/7 active:bg-ink/15', + ghost: 'text-accent px-1 py-2 hover:bg-accent/10 active:bg-accent/20', + icon: 'w-9 h-9 p-0 !justify-center text-ink hover:bg-ink/7 active:bg-ink/15', +} + +type Props = ButtonHTMLAttributes & { + variant?: Variant + block?: boolean +} + +export function Button({ variant = 'primary', block = false, className, type = 'button', ...rest }: Props) { + const isIcon = variant === 'icon' + return ( +