|
| 1 | +--- |
| 2 | +description: Component scaffolding templates for creating new design system components |
| 3 | +globs: packages/design-system/src/components/**/* |
| 4 | +--- |
| 5 | + |
| 6 | +# Component Scaffolding |
| 7 | + |
| 8 | +## File Structure |
| 9 | + |
| 10 | +New component at `packages/design-system/src/components/ds-{name}/`: |
| 11 | + |
| 12 | +``` |
| 13 | +ds-{name}/ |
| 14 | +├── index.ts # Barrel export |
| 15 | +├── ds-{name}.tsx # Implementation |
| 16 | +├── ds-{name}.types.ts # Props interface |
| 17 | +├── ds-{name}.module.scss # Styles |
| 18 | +└── ds-{name}.stories.tsx # Stories |
| 19 | +``` |
| 20 | + |
| 21 | +## Implementation Template |
| 22 | + |
| 23 | +```tsx |
| 24 | +import classNames from 'classnames'; |
| 25 | +import styles from './ds-{name}.module.scss'; |
| 26 | +import type { Ds{Name}Props } from './ds-{name}.types'; |
| 27 | + |
| 28 | +/** |
| 29 | + * Design system {Name} component |
| 30 | + */ |
| 31 | +const Ds{Name} = ({ |
| 32 | + className, |
| 33 | + children, |
| 34 | + ...props |
| 35 | +}: Ds{Name}Props) => { |
| 36 | + return ( |
| 37 | + <div className={classNames(styles.container, className)} {...props}> |
| 38 | + {children} |
| 39 | + </div> |
| 40 | + ); |
| 41 | +}; |
| 42 | + |
| 43 | +export default Ds{Name}; |
| 44 | +``` |
| 45 | + |
| 46 | +## Types Template |
| 47 | + |
| 48 | +```typescript |
| 49 | +import type { ComponentPropsWithoutRef, ReactNode } from 'react'; |
| 50 | + |
| 51 | +export interface Ds{Name}Props extends ComponentPropsWithoutRef<'div'> { |
| 52 | + /** |
| 53 | + * JSDoc description |
| 54 | + */ |
| 55 | + label?: ReactNode; |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +## Index Barrel |
| 60 | + |
| 61 | +```typescript |
| 62 | +export { default as Ds{Name} } from './ds-{name}'; |
| 63 | +export type { Ds{Name}Props } from './ds-{name}.types'; |
| 64 | +``` |
| 65 | + |
| 66 | +## Primitive Libraries |
| 67 | + |
| 68 | +1. **Ark UI** (`@ark-ui/react`) - Primary choice for new components |
| 69 | +2. **Radix UI** (`@radix-ui/react-*`) - Deprecated, modify existing only |
| 70 | +3. **TanStack** - Data-heavy components (table, virtual) |
| 71 | +4. **Custom** - Only when no primitive exists |
| 72 | + |
| 73 | +## Skills |
| 74 | + |
| 75 | +- To scaffold a new component, use the **component-scaffold** skill. |
| 76 | +- To create a component from a Figma URL, use the **figma-to-component** skill. |
| 77 | +- To check if Ark UI has a primitive, use the **check-ark-ui** notepad. |
0 commit comments