$npx -y skills add girijashankarj/cursor-handbook --skill component-creationStep-by-step workflow for creating accessible, tested UI components. Use when the user asks to create a new UI component.
| 1 | # Skill: Create UI Component |
| 2 | |
| 3 | ## Trigger |
| 4 | When the user asks to create a new UI component. |
| 5 | |
| 6 | ## Prerequisites |
| 7 | - [ ] Project uses React (or Vue; adjust steps) |
| 8 | - [ ] `src/components/` or equivalent exists |
| 9 | - [ ] Testing framework configured (Jest, Vitest, etc.) |
| 10 | - [ ] Styling approach known (Tailwind, CSS Modules, etc.) |
| 11 | |
| 12 | ## Steps |
| 13 | |
| 14 | ### Step 1: Define Component |
| 15 | - [ ] Name the component (PascalCase) |
| 16 | - [ ] Define its purpose and responsibilities |
| 17 | - [ ] Identify parent and child components |
| 18 | - [ ] List props and their types |
| 19 | - [ ] Identify state requirements |
| 20 | |
| 21 | ### Step 2: Create Component Directory |
| 22 | ``` |
| 23 | src/components/{category}/{ComponentName}/ |
| 24 | ├── {ComponentName}.tsx # Component implementation |
| 25 | ├── {ComponentName}.test.tsx # Unit tests |
| 26 | ├── {ComponentName}.stories.tsx # Storybook story (optional) |
| 27 | └── index.ts # Public export |
| 28 | ``` |
| 29 | |
| 30 | ### Step 3: Define Props Interface |
| 31 | - [ ] Create TypeScript interface for props |
| 32 | - [ ] Add JSDoc documentation for complex props |
| 33 | - [ ] Set default values where appropriate |
| 34 | - [ ] Mark optional props with `?` |
| 35 | |
| 36 | ### Step 4: Implement Component |
| 37 | - [ ] Use functional component with hooks |
| 38 | - [ ] Destructure props in function signature |
| 39 | - [ ] Implement rendering logic |
| 40 | - [ ] Add error boundary if needed |
| 41 | - [ ] Handle loading, error, and empty states |
| 42 | |
| 43 | ### Step 5: Add Accessibility |
| 44 | - [ ] Semantic HTML elements used |
| 45 | - [ ] ARIA attributes where needed |
| 46 | - [ ] Keyboard navigation works |
| 47 | - [ ] Focus management for modals/popups |
| 48 | - [ ] Color contrast meets WCAG 2.1 AA |
| 49 | |
| 50 | ### Step 6: Add Styling |
| 51 | - [ ] Follow project styling approach |
| 52 | - [ ] Responsive across breakpoints |
| 53 | - [ ] Dark mode support |
| 54 | - [ ] Design token usage (no magic numbers) |
| 55 | - [ ] No inline styles (except dynamic values) |
| 56 | |
| 57 | ### Step 7: Write Tests |
| 58 | - [ ] Renders correctly with default props |
| 59 | - [ ] Renders correctly with all prop combinations |
| 60 | - [ ] User interactions work (click, type, etc.) |
| 61 | - [ ] Accessibility tests pass |
| 62 | - [ ] Error states handled |
| 63 | |
| 64 | ### Step 8: Create Export |
| 65 | - [ ] Export component from index.ts |
| 66 | - [ ] Export props interface |
| 67 | |
| 68 | ## Completion Checklist |
| 69 | - [ ] Component renders with default props |
| 70 | - [ ] Props interface exported |
| 71 | - [ ] Tests pass |
| 72 | - [ ] Accessibility: keyboard nav, ARIA, contrast |
| 73 | - [ ] No lint/type errors |
| 74 | |
| 75 | ## If Step Fails |
| 76 | - **Step 2 (directory)**: Match existing structure in `src/components/` (ui/, features/, layout/) |
| 77 | - **Step 5 (a11y)**: Use `aria-label` on icon buttons; `role` only when semantic HTML insufficient |
| 78 | - **Step 7 (tests)**: Run single file: `npm test -- ComponentName.test.tsx`. Fix type errors first with `{{CONFIG.testing.typeCheckCommand}}` |
| 79 | |
| 80 | ## Example |
| 81 | Step 1: `OrderSummary` — displays order total and item count. Props: `items`, `taxRate`. Step 4: Functional component, `useMemo` for total calculation, loading/empty states. |