Craft Web UI
Core Principle
Specs in. Craft out.
Even when given thorough Design System prompts naming tokens, component libraries, accessibility, and modern references (Linear, Vercel/Geist, Raycast, Nuxt UI, shadcn/ui), AI coding agents routinely fall into Visual Mimicry: writing hand-rolled CSS classes around raw <select>, <input type="checkbox">, and <table> elements to approximate a screenshot instead of wiring the real headless component runtime, portal tree, variant engine, and spatial physics.
This skill closes the gap between design intent and shipped frontend code. It does not impose a fixed brand palette or product domain; instead, it enforces non-negotiable engineering craft across public unicorn component ecosystems.
Composition with Upstream Design Skills
craft-web-ui is the production frontend execution & governance layer. Support three explicit upstream modes without duplicating upstream responsibilities:
| Mode | Condition | Behavior |
|---|---|---|
| Consume | Repository or sibling generate-design-system / generate-brand-vi deliverables already exist | Consume approved DTCG tokens, DESIGN.md, and brand assets directly; map them into semantic CSS variables / Tailwind v4 @theme and headless component variants. |
| Compose | User requests full brand identity creation or formal cross-platform Design System specification first | Resolve and run installed generate-brand-vi / generate-design-system first, then execute production Web UI via craft-web-ui. |
| Standalone | Building or refactoring a web app directly without formal upstream specs | Establish clean 3-tier CSS tokens (Primitive -> Semantic -> Component) on a 4px spacing grid and 4/6/8/12px radius scale, then execute all 7 gates below. |
The 7-Gate Closed-Loop Workflow
Gate 1 — Reconnoiter the Stack & Cascade Before Writing UI
- Run
node scripts/scan_ui_stack.mjs <project-root>first when an existing repository is present. - Identify the exact framework (
Nuxt 4,Next.js App Router,Vite + Vue 3,Vite + React 19), installed headless UI kit (@nuxt/ui+reka-ui,shadcn/ui+@radix-ui/*or@base-ui-components/react,@heroui/react+react-aria), table engine (@tanstack/vue-table/@tanstack/react-table), motion library (motion-v/motion/react), CSS version (Tailwind v4vsv3), and theme controller (@nuxtjs/color-mode/next-themes). - Quarantine Cascade & Theme Hazards Immediately:
- In Tailwind CSS v4, native CSS Cascade Layers mean any unlayered legacy rule (
.btn { display: inline-flex }, globalbodyoverrides) beats@layer utilities(hidden,md:hidden). Move custom rules into@layer components, scope them per component, or delete legacy stylesheets. - Never mix
@media (prefers-color-scheme: dark)CSS variable blocks with class-driven dark mode (html.dark). Bind all dark tokens to a single root selector controlled by the theme provider. - Restart the dev server whenever adding framework UI modules (
@nuxt/ui,@tailwindcss/vite) so virtual theme templates compile cleanly.
- In Tailwind CSS v4, native CSS Cascade Layers mean any unlayered legacy rule (
Gate 2 — Wire Root Providers & Global Variant Physics Once
- Mount Root Providers:
- Nuxt UI v4: Wrap
app.vuein<UApp :toaster="{ position: 'bottom-right' }">so Reka UI portals, tooltips, modals, and toasts share one context. - React / Next.js: Mount
ThemeProvider(attribute="class"),TooltipProvider, andToaster(sonner) in rootlayout.tsx.
- Nuxt UI v4: Wrap
- Configure Variants Centrally, Not Per Page:
- Define tactile press (
active:scale-[0.98]), precision easing (cubic-bezier(0.23, 1, 0.32, 1)), table cell density, and popover/modal elevation once inapp.config.ts(Tailwind Variants) orcomponents/ui/*(CVA). - Read references/stack-recipes.md for exact Vue/Nuxt and React/Next.js configurations.
- Define tactile press (
Gate 3 — Enforce 100% Headless Componentization & Sub-Control Hygiene
- Hard Invariant (Outer Tags): Outside
components/ui/*(orcomponents/skin/*primitive wrappers), business pages, views, and modals MUST contain zero raw<select>,<textarea>,<input type="checkbox">,<input type="radio">, or hand-rolledfixed inset-0modal backdrops. - Hard Invariant (Residual Inner Sub-Control Chrome): Switching to
<UTextarea>,<UInput>, orshadcn/ui<Textarea>/<Input>is necessary but not sufficient—component wrappers still render underlying HTML elements whose browser-native pseudo-controls leak unless explicitly neutralized:- Textarea Corner Resize Gripper (
//): Browsers default<textarea>toresize: both(and many wrappers omitresize-noneunlessautoresizeis passed), painting a 1990s diagonal//grabber right across rounded bottom-right corners and letting users drag-break modal widths. Always enforceresize-none(resize: none+textarea::-webkit-resizer { display: none }) paired withautoresize(maxrows/field-sizing: content). - Number Spinbuttons & Search Cancel Icons: Use headless
NumberField(UInputNumber/ Reka UI / Base UI / React Aria) or stripinput[type="number"]::-webkit-inner-spin-button(appearance: textfield+tabular-nums) andinput[type="search"]::-webkit-search-cancel-buttonglobally in@layer base. - Autofill & Scrollbar Color-Scheme: Neutralize
:-webkit-autofillyellow/blue background flashes and declarecolor-scheme: light/color-scheme: darkon:root/.darkso native scrollbars and carets match the active surface.
- Textarea Corner Resize Gripper (
- Icon Discipline: Standardize on one vector icon set (
Lucideat16px/20px, uniform stroke width). Never use Emoji as production UI icons, and never write a literal"+ "label prefix when a leadingplusicon prop is already passed (which renders+ + Add).
Gate 4 — Engineer Focus Rings & Shared-Layout Active Indicators
- Pointer vs. Keyboard Separation (
WCAG 2.2 AA):- Every interactive button, tab, and navigation row must use
outline-none focus-visible:ring-2 focus-visible:ring-primary/50(orfocus-visible:ring-ring/50). - Never style
:focus(focus:ring-*) directly—mouse clicks must never leave a lingering focus box.
- Every interactive button, tab, and navigation row must use
- Kill Static
2pxSide-Border Boxes:- Never mark active sidebar, settings rail, or tree items with
box-shadow: inset 2px 0 0orborder-l-2. - Render a shared-layout spring gliding pill (
layoutIdinmotion/reactormotion-v) behind the active item (rounded-md bg-elevated ring-1 ring-default shadow-2xs) paired with semantic icon tinting (text-primary). - Use headless
TabsIndicator(UTabspill/linkor Radix/Base UITabs) for segmented controls and underline tabs.
- Never mark active sidebar, settings rail, or tree items with
Gate 5 — Choreograph Functional Micro-Motion (Without SSR Blank Flashes)
- Read references/cognitive-traps-field-notes.md before adding page or row animations.
- Three-Tier Motion Budget:
- Hover / Press:
100–150mscubic-bezier(0.23, 1, 0.32, 1)+active:scale-[0.98]. - Shared-Layout Pill Glide (
layoutId): Spring{ type: "spring", stiffness: 520, damping: 38 }. - Popover / Dialog / Sheet:
150–220msscale (0.97 -> 1) + opacity driven bydata-[state=open|closed].
- Hover / Press:
- Ban the SSR Hydration Opacity Trap:
- Never wrap SSR page roots in
<Motion :initial="{ opacity: 0 }">or<motion.main initial={{ opacity: 0 }}>. SSR serializesstyle="opacity: 0"into HTML, causing a blank screen until client JS downloads and hydrates. - Use
opacity: 1transform-only CSS@keyframes(translateY(3px) -> 0) on page containers; reserveAnimatePresenceopacity transitions for client-mounted dynamic bars, inline#expandedrows, and toasts.
- Never wrap SSR page roots in
- Reactivity Initialization Order: Declare all
ref/reactive/useStatevariables above any{ immediate: true }watcher or effect that touches them to prevent Temporal Dead Zone crashes on route switch. - Accessibility: Always include a global
@media (prefers-reduced-motion: reduce)reset.
Gate 6 — Apply 2026 Spatial Architecture & Single-Skeleton Governance
Read references/do-and-donot-matrix.md before structuring application shells and pages.
- Recessed Workspace Sheet (
Application Shell):- Pair a matte outer frame (
#08080adark /zinc-100/80light) and borderless220–232pxleft rail with an inset rounded workspace sheet (md:my-2 md:mr-2 md:rounded-xl bg-default ring-1 ring-default shadow-sm overflow-hidden). - Aggregate scope/tenant switchers and the
⌘Ksearch launcher at the top of the left rail; keep the topbar quiet (context badges, pending alerts, theme toggle).
- Pair a matte outer frame (
- Two-Row Precision Page Header:
- Row 1: Single
H1(18–20px, tight tracking) + optional inlineSubTabs+ at most one solid primary CTA on the right (demote secondary actions tooutline/ghost). - Row 2: Full
tabular-nums(font-variant-numeric: tabular-nums) KPI strip—never hide operational KPIs behindhidden xl:flex.
- Row 1: Single
- Cohesive Data Panel (
Toolbar + DataGrid + Inline Expand):- Attach
FilterToolbar(Segmented Filter+Select+Search+ contextualBatch Actions) directly as the#barheader of the same borderedPanelthat renders theDataTable/EmptyState. Never float a detached filter bar above a separate table card. - Prefer inline
#expandedrow panels for editing existing records so operators keep surrounding table context; use centeredModaldialogs for creation and cross-scope batch confirmations. - Enforce a
4pxspacing grid and4 / 6 / 8 / 12pxradius scale (kbd4px ·control6px ·panel8px ·modal/sheet12px). Banrounded-2xl shadow-lgnested card slop.
- Attach
- Single Structural Skeleton Across Themes / Skins (L3–L5 Invariance):
- When a product supports multiple themes, brand skins, or UI library adapters, maintain exactly one canonical view/shell tree (L3–L5). Route visual differences strictly through L0–L2 tokens and primitive adapters (
components/ui/*orcomponents/skin/*) so DOM hierarchy and element coordinates never jump when switching themes.
- When a product supports multiple themes, brand skins, or UI library adapters, maintain exactly one canonical view/shell tree (L3–L5). Route visual differences strictly through L0–L2 tokens and primitive adapters (
Gate 7 — Verify with Automated Hygiene Script & Live Browser Proof
- Run the static anti-slop auditor and resolve every error and warning:
node scripts/audit_ui_hygiene.mjs <project-root> - Follow references/qa-acceptance-checklist.md in a real browser:
- Confirm
0raw<select>/<input type="checkbox">leaks in the live DOM. - Open
Selectpopovers,Modaldialogs, and⌘KCommand Palette, and inspect real screenshots in both Dark and Light modes. - Confirm
document.documentElement.scrollWidth <= document.documentElement.clientWidthat390pxand320pxviewports, and0console/page errors.
- Confirm