shadcn-ui-best-practices
SKILL.md
shadcn/ui Best Practices
Comprehensive best practices guide for shadcn/ui applications, designed for AI agents and LLMs. Contains 48 rules across 8 categories, prioritized by impact to guide component composition, styling, accessibility, and performance optimization.
When to Apply
Reference these guidelines when:
- Installing and configuring shadcn/ui in a project
- Composing component structures with Dialog, Select, or Dropdown
- Implementing theming with CSS variables and dark mode
- Building accessible forms with validation and error handling
- Creating data tables with TanStack Table integration
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | CLI & Project Setup | CRITICAL | setup- |
| 2 | Component Composition | CRITICAL | comp- |
| 3 | Styling & Theming | HIGH | style- |
| 4 | Accessibility Patterns | HIGH | access- |
| 5 | Form Integration | MEDIUM-HIGH | form- |
| 6 | Data Display Components | MEDIUM | data- |
| 7 | Layout & Navigation | MEDIUM | layout- |
| 8 | Performance Optimization | LOW-MEDIUM | perf- |
Quick Reference
1. CLI & Project Setup (CRITICAL)
setup-components-json- Configure components.json before adding componentssetup-path-aliases- Configure TypeScript path aliases to match components.jsonsetup-cn-utility- Create the cn utility before using componentssetup-use-cli-not-copy- Use CLI to add components instead of copy-pastesetup-css-variables-theme- Enable CSS variables for consistent themingsetup-rsc-configuration- Set RSC flag based on framework support
2. Component Composition (CRITICAL)
comp-edit-source-not-wrap- Edit component source instead of wrappingcomp-use-aschild-for-custom-elements- Use asChild for custom element renderingcomp-compose-dialog-parts- Compose Dialog with semantic partscomp-use-cva-for-variants- Use CVA for component variantscomp-dropdown-menu-structure- Structure dropdown menus with required partscomp-card-semantic-structure- Use Card semantic parts for content organizationcomp-icons-data-attributes- Use data-icon attributes for icon spacingcomp-select-controlled-value- Use value prop for controlled Select components
3. Styling & Theming (HIGH)
style-use-cn-for-merging- Use cn() for all class mergingstyle-css-variables-naming- Follow CSS variable naming conventionstyle-dark-mode-class- Use class-based dark mode switchingstyle-extend-not-override- Extend variants instead of overriding base stylesstyle-oklch-colors- Use OKLCH color format for theme variablesstyle-register-custom-colors- Register custom colors with Tailwind themestyle-border-radius-variable- Use border radius variable for consistent corners
4. Accessibility Patterns (HIGH)
access-dialog-title-required- Always include DialogTitle for screen readersaccess-form-field-labels- Associate labels with form controlsaccess-aria-invalid-errors- Use aria-invalid for form error statesaccess-icon-button-labels- Add accessible labels to icon-only buttonsaccess-checkbox-label-association- Wrap Checkbox with Label for click targetaccess-focus-visible-styles- Preserve focus visible styles for keyboard navigation
5. Form Integration (MEDIUM-HIGH)
form-react-hook-form-integration- Integrate React Hook Form with Field componentsform-field-error-display- Display field errors with FieldError componentform-select-with-form- Use Controller for Select in React Hook Formform-submit-button-loading- Disable submit button during form submissionform-textarea-auto-resize- Use auto-resizing Textarea for long-form inputform-combobox-async-search- Implement async search with Combobox
6. Data Display Components (MEDIUM)
data-tanstack-table-setup- Configure TanStack Table with required row modelsdata-column-definitions-separate- Define columns in separate file for reusabilitydata-row-actions-dropdown- Use dropdown menu for row actionsdata-pagination-component- Extract pagination into reusable componentdata-empty-state- Handle empty table state gracefully
7. Layout & Navigation (MEDIUM)
layout-sidebar-provider- Wrap layout with SidebarProviderlayout-sidebar-collapsible- Configure sidebar collapsible behaviorlayout-sidebar-groups- Organize sidebar navigation with groupslayout-sheet-mobile-nav- Use Sheet for mobile navigation overlaylayout-breadcrumb-navigation- Implement breadcrumbs for deep navigation
8. Performance Optimization (LOW-MEDIUM)
perf-dynamic-import-heavy-components- Dynamic import heavy componentsperf-direct-lucide-imports- Import Lucide icons directly from pathperf-avoid-rerender-callbacks- Stabilize callback props to prevent re-rendersperf-skeleton-loading-states- Use Skeleton for loading statesperf-virtualize-long-lists- Virtualize long lists in Select and Command
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
Reference Files
| File | Description |
|---|---|
| references/_sections.md | Category definitions and ordering |
| assets/templates/_template.md | Template for new rules |
| metadata.json | Version and reference information |
Weekly Installs
2
Repository
pproenca/dot-skillsInstalled on
opencode2
codex2
claude-code2
kilo1
windsurf1
zencoder1