Agent skill
af-design-ui-components
Design UI components with Storybook stories, RTL tests, and accessibility compliance. Use when creating component specifications, performing UX reviews, aligning BDD scenarios with UI design, or working with shadcn/ui.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/af-design-ui-components
SKILL.md
UX Design Expertise
When to Use This Skill
Load this skill when you need to:
- Create or classify components using Atomic Design
- Transform BDD scenarios into Storybook stories
- Create RTL tests or Storybook play functions
- Define selector contracts for testing
- Perform UX review before PR approval
- Create or update the brand system specification
- Check the component catalog before creating new components
Common triggers:
- Refinement phase creates visual sub-tasks
- UI features need Storybook stories
- PR touches
src/components/orstories/ - Discovery phase needs brand system specification
- New feature may duplicate existing components
Quick Reference
Core principles:
- Design happens in code (Storybook) — Figma is an optional visual layer (see
af-sync-figma-designs) - Extended Atomic Design hierarchy: Tokens → Primitives → Atoms → Molecules → Organisms → Templates → Pages → Flows
- Component Catalog Check before creating anything new
- Storybook play functions are PRIMARY for UI testing
- RTL tests are for non-visual logic only
- View Components are the single source of truth — shared by Storybook stories AND app pages
- Design Grammar (
.design-grammar/) defines the shared cross-project vocabulary
The 7-Stage Design Flow:
- UX Intent Extraction → Understand requirements
- Visual Language + Base Tokens → Establish tokens from day one
- Component Design in Storybook → Build in atomic folders
- Behavior Locked with Tests → Play functions + RTL
- Design Sign-off → Storybook + tests complete
- Handoff to Engineering → Ownership transfer
- Pattern Tokenisation → Extract emergent patterns
Key deliverables:
- View components (
src/components/views/) — rendering logic shared by stories and pages - Storybook stories (all states, themes, viewports)
- Selector contract (
/tests/selectors/[capability].ts) - Components in atomic folders (
src/components/{primitives,atoms,molecules,organisms,templates}/)
Rules
Extended Atomic Design Hierarchy
The full hierarchy extends classic Atomic Design with Primitives below and Pages/Flows above:
Tokens → Primitives → Atoms → Molecules → Organisms → Templates → Pages → Flows
| Level | Purpose | Examples |
|---|---|---|
| Tokens | Design values (colors, spacing, typography) | --color-primary, --spacing-md |
| Primitives | Unstyled behavioural + layout building blocks | Component: <Pressable>, <Slot>; Layout: <Stack>, <Grid> |
| Atoms | Styled single-purpose elements | <Button>, <Badge>, <Input> |
| Molecules | Small atom combinations | <FormField>, <NavItem>, <PricingCard> |
| Organisms | Large UI sections (page sections) | <Hero>, <FeatureGrid>, <Pricing> |
| Templates | Page structure without content | <LandingTemplate>, <DashboardTemplate> |
| Pages | Templates + real content (data-fetching boundary) | <LandingPage>, <PricingPage> |
| Flows | Multi-page user journeys | Signup flow, Onboarding flow, Checkout flow |
Primitives split into two categories:
- Component primitives — Behavioural wrappers (e.g.,
<Pressable>,<Collapsible>,<Slot>) - Layout primitives — Spatial containers (e.g.,
<Stack>,<Grid>,<Container>,<Spacer>)
Atomic Design Rules
- MUST classify components using the extended hierarchy above
- MUST check component catalog BEFORE creating — Browse Storybook sidebar, check shadcn/ui, compose before creating
- MUST use atomic folder structure —
src/components/{primitives,atoms,molecules,organisms,templates}/ - MUST mirror atomic levels in Storybook titles —
title: 'Atoms/Button',title: 'Organisms/Auth/SignupForm' - SHOULD prefer shadcn/ui for atoms — Only create custom atoms when shadcn/ui doesn't cover the need
Component Rules
- MUST read design system FIRST —
/docs/design/design-system.md - MUST map every BDD scenario to a story — 100% coverage
- MUST create selector contracts — Bridge between stories and tests
- MUST separate components from stories — Stories import from
src/components/, never embed code - MUST check tsconfig.json paths before imports — Path aliases vary by project
View Components Pattern
View components are the single source of truth for rendering logic. Both Storybook stories and app pages import the same view component — no duplication.
src/components/views/
├── PricingView.tsx ← rendering logic (props in, JSX out)
├── DashboardView.tsx
└── OnboardingView.tsx
src/app/pricing/page.tsx ← data fetching + auth → passes props to PricingView
stories/PricingView.stories.tsx ← mock data → passes props to PricingView
Rules:
11. MUST create view components for any page-level UI — src/components/views/[Name]View.tsx
12. View components accept props, return JSX — No data fetching, no auth, no side effects
13. Pages are thin wrappers — page.tsx handles data/auth, passes props to the view component
14. Stories import views directly — Stories provide mock data to the same view component that pages use
15. MUST NOT duplicate rendering logic — If a story and a page render the same UI, extract to a view component
Design Grammar
The Design Grammar at .design-grammar/ defines the shared cross-project vocabulary. It provides JSON definitions for every level of the atomic hierarchy.
Rules: 16. MUST consult Design Grammar before creating new components — check if a grammar definition exists 17. Components SHOULD conform to grammar JSON — structure, prop names, and variants defined in grammar 18. New patterns MUST be proposed to grammar — if you create a novel organism or molecule, add its JSON definition 19. Token values come from grammar — never invent token names; use what the grammar defines 20. Grammar is platform-agnostic — same JSON drives React, Flutter, and other renderers
Grammar structure:
.design-grammar/
├── primitives/ ← component + layout primitive definitions
│ ├── components.json
│ └── layouts.json
├── atoms.json ← atom definitions
├── molecules.json ← molecule definitions
├── organisms.json ← organism definitions (including marketing sections)
├── templates.json ← template definitions
├── pipeline/ ← token build tooling (Style Dictionary)
└── tokens-studio/ ← Figma ↔ repo token sync
Testing Rules
- Storybook play functions are PRIMARY for UI component testing (real browser)
- RTL tests are for non-visual logic ONLY — Hooks, utils, state machines
- MUST NOT duplicate assertions — If play function tests it, don't repeat in RTL
- MUST include accessibility assertions — Roles, labels, focus management
- Tests MUST pass before handoff — Engineering keeps them passing
Design Token Rules
- MUST establish base tokens in Stage 2 — Brand colors, typography, spacing, radius, shadows
- Stage 7 is for emergent patterns ONLY — Not base tokens
- MUST use design system tokens — Never hard-code values that have tokens
- Token changes require pipeline validation — Run
npm run validateandnpm run buildin.design-grammar/pipeline/
Accessibility Rules (WCAG 2.1 AA)
- Semantic HTML mandatory — Headings, ARIA roles, landmarks, form labels
- Keyboard navigation complete — Tab order, focus visible, Escape closes modals
- Screen reader support — ARIA labels, live regions, described-by
- Color contrast minimum 4.5:1 — Text on background
- Touch targets minimum 44px — Mobile-friendly
Story Variant Rules
- MUST create responsive variants — Mobile (320-768px), Tablet (768-1024px), Desktop (1024px+)
- MUST create theme variants — Light and Dark mode using decorators
- MUST use
tags: ['autodocs']— Enable auto-generated component documentation - SHOULD add JSDoc to props interfaces — Appears in autodocs as prop descriptions
- SHOULD use CSF 3 with
satisfies Meta— Modern Storybook pattern
Workflows
Workflow: Creating Stories from Scenarios
When: Refinement phase, after BDD scenarios.
- Read BDD scenarios from mini-PRD Section 4
- Check Design Grammar — Does
.design-grammar/define this component type? - Component Catalog Check — Browse Storybook, check shadcn/ui
- Read design system at
/docs/design/design-system.md - Create selector contract at
/tests/selectors/[capability].ts - Classify components using extended hierarchy (Tokens → Primitives → ... → Flows)
- Create view components at
src/components/views/for page-level UI - Create atomic components in
src/components/{primitives,atoms,molecules,organisms,templates}/ - Create stories that import view components or atomic components
- Write stories per scenario (happy, error, boundary, validation)
- Add responsive variants (Mobile, Tablet, Desktop)
- Add theme variants (Light, Dark)
- Add play functions for interaction testing
- Add
tags: ['autodocs']and JSDoc on props - Test locally:
npm run storybook
See UX Design Guide for detailed steps and examples.
Workflow: UX Review
When: Delivery phase, before PR approval for UI changes.
- Gather inputs: UI under review, brand system specification, design decision log, reference class
- Run 7-point checklist: Structure, Component Discipline, Density, State/Feedback, Accessibility, Brand Alignment, Decision Log Compliance
- Classify findings as: Aligned | Tension | Violation
- Emit outputs: Implementation fixes, token evolution, guideline amendments, design decisions
Hard rule: If a reference class can't be stated, the review is invalid.
See UX Design Guide for full checklist.
Workflow: Component Catalog Check
When: Before creating ANY new component.
- Browse Storybook sidebar — does this component already exist?
- Check shadcn/ui —
mcp__shadcn-ui-server__list_shadcn_components - Can you compose from existing atoms/molecules?
- Only create new if nothing exists at the right level
- Classify the new component: atom, molecule, organism, or template
Common Pitfalls
| Pitfall | Solution |
|---|---|
| Creating duplicates | Check Storybook catalog first |
| Embedding code in stories | Stories import from src/components/ |
| RTL duplicating play functions | Play functions are primary for UI |
| No theme variants | Add Light/Dark mode stories |
| Missing autodocs | Add JSDoc + tags: ['autodocs'] |
| Wrong import paths | Read tsconfig.json first |
| Flat component structure | Use atomic folders with primitives/ level |
| Deferring all tokens | Base tokens go in Stage 2 |
| Duplicating render logic | Extract to view components (src/components/views/) |
| Page components doing rendering | Pages fetch data only — delegate rendering to views |
| Ignoring Design Grammar | Check .design-grammar/ before creating new component types |
| Inventing token names | Use grammar-defined tokens only |
Integration with AgentFlow Phases
| Phase | Activities |
|---|---|
| Discovery | Brand system specification, reference class, base design tokens, Brand Page in Storybook |
| Refinement | Catalog Check → Components → Stories → Tests → Sign-off |
| Delivery | Engineering wires components, UX Review before PR |
| Post-Delivery | Extract emergent pattern tokens |
Essential Reading
Comprehensive guide (workflows, examples, review checklists):
- UX Design Guide
Design system:
- Project design system:
/docs/design/design-system.md
Variant reference:
- Tailwind Plus catalogue:
.design-grammar/sources/tailwind-plus/catalogue.json— 657 component variants mapped to grammar types. Use as a reference when choosing variants for new components.
Related skills:
af-write-bdd-scenarios— Scenario understandingaf-configure-test-frameworks— Test patternsaf-develop-flutter-apps— Mobile-specific patternsaf-sync-figma-designs— Figma round-trip workflows (optional visual layer)
MCP Tools:
mcp__shadcn-ui-server__list_shadcn_components— List available componentsmcp__shadcn-ui-server__get_component_details— Get component specsmcp__shadcn-ui-server__get_component_examples— Get usage examples
Remember:
- Extended hierarchy: Tokens → Primitives → Atoms → Molecules → Organisms → Templates → Pages → Flows
- View components (
src/components/views/) are the single source of truth for rendering - Check Design Grammar (
.design-grammar/) AND component catalog BEFORE creating - Play functions are PRIMARY for UI testing
- Base tokens established in Stage 2, emergent patterns in Stage 7
- Storybook is the source of truth, not Figma
- Pages fetch data only — delegate all rendering to view components
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?