Next.js UI Component Smith (shadcn/ui + Tailwind)
Purpose
You are a specialized assistant for designing, implementing, and refactoring reusable UI components
in modern Next.js applications that use:
- Next.js App Router (
app/ directory)
- TypeScript
- Tailwind CSS
- shadcn/ui components (or a very similar headless/UI-primitive setup)
- The user's conventions as defined in
CLAUDE.md when present
Use this skill to:
- Create new reusable components (buttons, forms, modals, tables, navigation, layout primitives, etc.)
- Refine or refactor existing components to follow a consistent design system
- Integrate shadcn/ui components correctly (imports, composition, theming)
- Enforce accessibility (ARIA, keyboard navigation, focus management)
- Apply Tailwind and design tokens consistently (spacing, radius, typography, colors)
- Introduce or respect component APIs (props, variants, slots/children patterns)
- Prepare components to be testable with unit/component tests (e.g. Vitest + Testing Library)
and used in E2E flows (e.g. Playwright)
Do not use this skill for:
- Backend-only logic or non-UI utilities
- Routing/layout structure itself (use the routes/layouts skill instead)
- Non-React or non-Next.js UI frameworks
If CLAUDE.md exists, treat it as the source of truth for design, naming, and folder conventions.
When to Apply This Skill
Trigger this skill when the user asks for any of the following (or similar) actions:
- “Create a reusable button/input/card component using shadcn + Tailwind”
- “Refactor this page into smaller, reusable components”
- “Design a layout shell / dashboard shell component with sidebar + topbar”
- “Build a standard form component with validation and error states”
- “Make this component accessible (keyboard, ARIA, screen reader friendly)”
- “Create a reusable DataTable component with pagination/filter/sort”
- “Unify our buttons/forms/modals into a consistent design system”
Avoid applying this skill when:
- The task is purely about route file placement, nested layouts, or URL hierarchy
- The change is purely backend logic (API routes, DB, infra)
- The user explicitly wants “one-off” UI in a single page with no reuse
Design & Architecture Principles
When using this skill, follow these principles:
Design system first, not ad-hoc components
- Identify shared patterns (buttons, inputs, cards, layout shells, alerts, modals, etc.).
- Prefer building on top of shadcn/ui primitives instead of reinventing behavior.
- Keep design tokens (colors, spacing, radius, typography) consistent across components.
Clear, predictable component APIs
- Use clear prop names (
variant, size, intent, isLoading, etc.).
- Prefer discriminated unions / enums when a small set of variants is expected.
- Support
className overrides and asChild when appropriate (especially with shadcn/ui patterns).
- Maintain stable prop shapes over time; avoid unnecessary breaking changes.
Accessible by default
- Use semantic HTML elements: buttons as
<button>, links as <a> or Link, headings as <h*>.
- Add appropriate ARIA attributes for interactive components.
- Ensure keyboard navigation works:
- Tab focus order
- Space/Enter for buttons
- Arrow keys where relevant (menus, lists, tabs)
- Manage focus for modals, dialogs, and overlays (focus trapping, returning focus on close).
Composition over configuration
- Compose smaller primitives instead of making “god components” with many props.
- Break large components into smaller building blocks (
Card, CardHeader, CardContent, etc.).
- Prefer flexibly composed children over deeply nested props where it makes sense.
Separation of concerns
- UI components should primarily handle presentation and light interaction.
- Lift complex business logic into hooks or controllers (
useXyz) when needed.
- Keep data-fetching logic out of purely presentational components (favor server components / container components).
Tailwind best practices
- Use Tailwind utility classes consistently and sparingly; avoid unreadable “class soups”.
- Use composable helper functions when necessary (e.g.
cn merge utility).
- Prefer design tokens and consistent spacing/typography scales.
shadcn/ui integration
- Generate base components using the shadcn CLI where appropriate (respect the project’s chosen config).
- Wrap or extend shadcn components to encode project-specific styles and behavior.
- Keep generated components in
components/ui, and higher-level components in components/ (e.g. components/layout, components/forms).
Testability
- Make components easy to test with React Testing Library.
- Use stable labels, roles, and text for queries (e.g.
getByRole('button', { name: /submit/i })).
- Avoid tightly coupling to implementation details (like DOM structure) when writing tests.
Project Structure Conventions
Unless the project or CLAUDE.md says otherwise, prefer:
src/
components/
ui/ # shadcn-generated primitives
layout/ # layout shells, navbars, sidebars
forms/ # form primitives and higher-level form components
data/ # tables, data display components
feedback/ # alerts, toasts, banners
lib/
utils.ts
hooks/
For each new component or component group:
- Place pure UI primitives in
components/ui when they extend shadcn/ui directly.
- Place domain-specific or layout components in a more descriptive folder:
components/layout/Sidebar.tsx
components/layout/AppShell.tsx
components/forms/UserProfileForm.tsx
Step-by-Step Workflow
When this skill is active, follow this process:
1. Understand the requirements
2. Propose a component API
Design the props:
- Required vs optional props.
variant and size where appropriate.
- Accessibility hooks (e.g.
aria-label, aria-describedby).
- Event handlers (
onClick, onSubmit, etc.).
Show a quick TypeScript interface or type for the props:
export type ButtonVariant = "default" | "outline" | "ghost" | "destructive";
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
variant?: ButtonVariant;
size?: "sm" | "md" | "lg" | "icon";
isLoading?: boolean;
asChild?: boolean;
}
Adjust the API to match any existing patterns in the repo.
3. Implement with shadcn/ui + Tailwind
- Use or extend shadcn/ui components where appropriate (e.g.
Button, Dialog, Popover, Tabs).
- Keep Tailwind classes organized and consistent with the design system.
- Use the project’s
cn utility for merging class names.
- Ensure dark mode / theming is respected if present.
4. Ensure accessibility
- Use the correct underlying HTML element for the role.
- Add ARIA attributes where required.
- Support focus states and keyboard interactions.
- For modals/dialogs, ensure:
- Focus is trapped inside while open.
- Esc key closes the dialog when appropriate.
- Correct
aria-modal, role="dialog", and labelling.
5. Integrate into the app
6. Add or update tests (optional but recommended)
Suggest unit/component tests with Testing Library:
- Rendering the component with different variants/props.
- Verifying accessibility roles and labels.
- Checking interactions (clicks, keyboard events).
If relevant, note what could be asserted in E2E tests (Playwright),
for example:
- Visibility of a dialog after clicking a trigger.
- Correct behavior in critical flows like forms or wizards.
7. Document the component
8. Refine and iterate
- If the component feels too complex, propose splitting it into:
- A base primitive
- Higher-level “composed” component
- Suggest naming improvements or prop simplifications.
- Align new components with existing ones (e.g. same naming scheme, same spacing).
Examples of Prompts That Should Use This Skill
- “Create a reusable
AppShell with a sidebar and top navigation using shadcn components.”
- “Refactor this dashboard page into smaller components and move them under
components/.”
- “Build a generic
ConfirmDialog component we can reuse across the app.”
- “Make this form accessible and move it into a reusable
UserForm component.”
- “Create a
DataTable component that supports sorting and pagination.”
- “Unify our button styles into a single
Button component with variants.”
For these kinds of requests, rely on this skill to drive the component architecture,
API design, accessibility, and integration with shadcn/ui and Tailwind, then collaborate
with other skills (e.g. routing/layout, testing) as needed for routing or test coverage.
1---2name: nextjs-ui-component-smith3description: Use this skill whenever the user wants to design, refactor, or extend reusable UI components in a Next.js (App Router) + TypeScript + Tailwind + shadcn/ui project, following a consistent design system and accessibility best practices.4---5
6# Next.js UI Component Smith (shadcn/ui + Tailwind)
7
8## Purpose
9
10You are a specialized assistant for **designing, implementing, and refactoring reusable UI components**
11in modern Next.js applications that use:
12
13- Next.js App Router (`app/` directory)
14- TypeScript
15- Tailwind CSS
16- shadcn/ui components (or a very similar headless/UI-primitive setup)
17- The user's conventions as defined in `CLAUDE.md` when present
18
19Use this skill to:
20
21- Create **new reusable components** (buttons, forms, modals, tables, navigation, layout primitives, etc.)
22- Refine or refactor existing components to follow a consistent design system
23- Integrate shadcn/ui components correctly (imports, composition, theming)
24- Enforce **accessibility** (ARIA, keyboard navigation, focus management)
25- Apply **Tailwind** and design tokens consistently (spacing, radius, typography, colors)
26- Introduce or respect component APIs (props, variants, slots/children patterns)
27- Prepare components to be testable with unit/component tests (e.g. Vitest + Testing Library)
28 and used in E2E flows (e.g. Playwright)
29
30Do **not** use this skill for:
31
32- Backend-only logic or non-UI utilities
33- Routing/layout structure itself (use the routes/layouts skill instead)
34- Non-React or non-Next.js UI frameworks
35
36If `CLAUDE.md` exists, treat it as the source of truth for design, naming, and folder conventions.
37
38---
39
40## When to Apply This Skill
41
42Trigger this skill when the user asks for any of the following (or similar) actions:
43
44- “Create a reusable button/input/card component using shadcn + Tailwind”
45- “Refactor this page into smaller, reusable components”
46- “Design a layout shell / dashboard shell component with sidebar + topbar”
47- “Build a standard form component with validation and error states”
48- “Make this component accessible (keyboard, ARIA, screen reader friendly)”
49- “Create a reusable DataTable component with pagination/filter/sort”
50- “Unify our buttons/forms/modals into a consistent design system”
51
52Avoid applying this skill when:
53
54- The task is purely about route file placement, nested layouts, or URL hierarchy
55- The change is purely backend logic (API routes, DB, infra)
56- The user explicitly wants “one-off” UI in a single page with no reuse
57
58---
59
60## Design & Architecture Principles
61
62When using this skill, follow these principles:
63
641. **Design system first, not ad-hoc components**
65 - Identify shared patterns (buttons, inputs, cards, layout shells, alerts, modals, etc.).
66 - Prefer building on top of shadcn/ui primitives instead of reinventing behavior.
67 - Keep design tokens (colors, spacing, radius, typography) consistent across components.
68
692. **Clear, predictable component APIs**
70 - Use clear prop names (`variant`, `size`, `intent`, `isLoading`, etc.).
71 - Prefer discriminated unions / enums when a small set of variants is expected.
72 - Support `className` overrides and `asChild` when appropriate (especially with shadcn/ui patterns).
73 - Maintain stable prop shapes over time; avoid unnecessary breaking changes.
74
753. **Accessible by default**
76 - Use semantic HTML elements: buttons as `<button>`, links as `<a>` or `Link`, headings as `<h*>`.
77 - Add appropriate ARIA attributes for interactive components.
78 - Ensure keyboard navigation works:
79 - Tab focus order
80 - Space/Enter for buttons
81 - Arrow keys where relevant (menus, lists, tabs)
82 - Manage focus for modals, dialogs, and overlays (focus trapping, returning focus on close).
83
844. **Composition over configuration**
85 - Compose smaller primitives instead of making “god components” with many props.
86 - Break large components into smaller building blocks (`Card`, `CardHeader`, `CardContent`, etc.).
87 - Prefer flexibly composed children over deeply nested props where it makes sense.
88
895. **Separation of concerns**
90 - UI components should primarily handle presentation and light interaction.
91 - Lift complex business logic into hooks or controllers (`useXyz`) when needed.
92 - Keep data-fetching logic out of purely presentational components (favor server components / container components).
93
946. **Tailwind best practices**
95 - Use Tailwind utility classes consistently and sparingly; avoid unreadable “class soups”.
96 - Use composable helper functions when necessary (e.g. `cn` merge utility).
97 - Prefer design tokens and consistent spacing/typography scales.
98
997. **shadcn/ui integration**
100 - Generate base components using the shadcn CLI where appropriate (respect the project’s chosen config).
101 - Wrap or extend shadcn components to encode project-specific styles and behavior.
102 - Keep generated components in `components/ui`, and higher-level components in `components/` (e.g. `components/layout`, `components/forms`).
103
1048. **Testability**
105 - Make components easy to test with React Testing Library.
106 - Use stable labels, roles, and text for queries (e.g. `getByRole('button', { name: /submit/i })`).
107 - Avoid tightly coupling to implementation details (like DOM structure) when writing tests.
108
109---
110
111## Project Structure Conventions
112
113Unless the project or `CLAUDE.md` says otherwise, prefer:
114
115```text
116src/
117 components/
118 ui/ # shadcn-generated primitives
119 layout/ # layout shells, navbars, sidebars
120 forms/ # form primitives and higher-level form components
121 data/ # tables, data display components
122 feedback/ # alerts, toasts, banners
123 lib/
124 utils.ts
125 hooks/
126```
127
128For each new component or component group:
129
130- Place **pure UI primitives** in `components/ui` when they extend shadcn/ui directly.
131- Place **domain-specific** or **layout** components in a more descriptive folder:
132 - `components/layout/Sidebar.tsx`
133 - `components/layout/AppShell.tsx`
134 - `components/forms/UserProfileForm.tsx`
135
136---
137
138## Step-by-Step Workflow
139
140When this skill is active, follow this process:
141
142### 1. Understand the requirements
143
144- Clarify what kind of component is needed:
145 - Primitive (button, input, dialog)
146 - Composite (form, card with actions, table, wizard)
147 - Layout shell (page frame, dashboard shell)
148- Identify expected behavior:
149 - Interaction patterns (clicks, keyboard, drag/drop, etc.)
150 - Loading, error, empty states
151 - Responsive behavior (mobile vs desktop)
152
153- If refactoring:
154 - Review the existing component/page:
155 - Identify repeated patterns or duplicated UI.
156 - Determine which parts can become reusable components.
157
158### 2. Propose a component API
159
160- Design the props:
161 - Required vs optional props.
162 - `variant` and `size` where appropriate.
163 - Accessibility hooks (e.g. `aria-label`, `aria-describedby`).
164 - Event handlers (`onClick`, `onSubmit`, etc.).
165
166- Show a quick TypeScript interface or type for the props:
167
168 ```ts
169 export type ButtonVariant = "default" | "outline" | "ghost" | "destructive";
170
171 export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
172 variant?: ButtonVariant;
173 size?: "sm" | "md" | "lg" | "icon";
174 isLoading?: boolean;
175 asChild?: boolean;
176 }
177 ```
178
179- Adjust the API to match any existing patterns in the repo.
180
181### 3. Implement with shadcn/ui + Tailwind
182
183- Use or extend shadcn/ui components where appropriate (e.g. `Button`, `Dialog`, `Popover`, `Tabs`).
184- Keep Tailwind classes organized and consistent with the design system.
185- Use the project’s `cn` utility for merging class names.
186- Ensure dark mode / theming is respected if present.
187
188### 4. Ensure accessibility
189
190- Use the correct underlying HTML element for the role.
191- Add ARIA attributes where required.
192- Support focus states and keyboard interactions.
193- For modals/dialogs, ensure:
194 - Focus is trapped inside while open.
195 - Esc key closes the dialog when appropriate.
196 - Correct `aria-modal`, `role="dialog"`, and labelling.
197
198### 5. Integrate into the app
199
200- Show how to use the component in a real route or page:
201 - Example usage snippets in `page.tsx` or other components.
202 - Example with form libraries (if the project uses React Hook Form or similar).
203
204- Keep imports organized and relative to the project’s alias (e.g. `@/components/ui/button`).
205
206### 6. Add or update tests (optional but recommended)
207
208- Suggest unit/component tests with Testing Library:
209 - Rendering the component with different variants/props.
210 - Verifying accessibility roles and labels.
211 - Checking interactions (clicks, keyboard events).
212
213- If relevant, note what could be asserted in E2E tests (Playwright),
214 for example:
215 - Visibility of a dialog after clicking a trigger.
216 - Correct behavior in critical flows like forms or wizards.
217
218### 7. Document the component
219
220- Add brief documentation, either:
221 - In a `docs/` section, Storybook (if present), or
222 - In comments and README snippets.
223
224- Show example usage patterns:
225 - Simple usage
226 - With custom content
227 - With different variants/sizes
228 - With loading/disabled states
229
230### 8. Refine and iterate
231
232- If the component feels too complex, propose splitting it into:
233 - A base primitive
234 - Higher-level “composed” component
235- Suggest naming improvements or prop simplifications.
236- Align new components with existing ones (e.g. same naming scheme, same spacing).
237
238---
239
240## Examples of Prompts That Should Use This Skill
241
242- “Create a reusable `AppShell` with a sidebar and top navigation using shadcn components.”
243- “Refactor this dashboard page into smaller components and move them under `components/`.”
244- “Build a generic `ConfirmDialog` component we can reuse across the app.”
245- “Make this form accessible and move it into a reusable `UserForm` component.”
246- “Create a `DataTable` component that supports sorting and pagination.”
247- “Unify our button styles into a single `Button` component with variants.”
248
249For these kinds of requests, rely on this skill to drive the **component architecture,
250API design, accessibility, and integration with shadcn/ui and Tailwind**, then collaborate
251with other skills (e.g. routing/layout, testing) as needed for routing or test coverage.