Shadcn

作者 pproencacf93c57cac89無授權條款215 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫7 週前更新

shadcn/ui component library best practices and patterns (formerly shadcn-ui). This skill should be used when writing, reviewing, or refactoring shadcn/ui components to ensure proper architecture, accessibility, and performance. Triggers on tasks involving Radix primitives, Tailwind styling, form validation with React Hook Form, data tables, theming, or component composition patterns.

AI 產生的概覽

用於建構、審查與重構 shadcn/ui 元件的最佳實務規則,涵蓋 Radix、Tailwind 與 React。

功能
此技能提供依優先順序排列的 58 條規則,分為 10 個類別,用於 shadcn/ui 開發,涵蓋 CLI 與專案設定、元件架構、無障礙、樣式與主題、表單、資料呈現、版面配置、組合、效能與狀態管理。每條規則都有獨立的參考檔案,內含說明與程式碼範例,另有一份合併後的單一檔案版本。它僅提供指引內容,本身不會產生檔案或指令碼。
適用情境
適用於在專案中安裝或設定 shadcn/ui、撰寫或組合以 Radix 原始元件為基礎的元件,或審查現有元件的無障礙、主題與效能問題。也適合使用 React Hook Form 與 Zod 的表單工作、資料表格與大型資料集呈現,以及深色模式或主題客製化。
執行需求
此技能不附帶指令碼或執行階段相依項目,僅為文件。套用其指引的前提是專案使用 shadcn/ui,並搭配 React、Radix 原始元件、Tailwind CSS,可選用 React Hook Form、Zod 與 TanStack Table。

shadcn/ui Community Best Practices

Comprehensive best practices guide for shadcn/ui applications, maintained by the shadcn/ui community. Contains 58 rules across 10 categories, prioritized by impact to guide automated refactoring and code generation.

When to Apply

Reference these guidelines when:

  • Installing and configuring shadcn/ui in a project
  • Writing new shadcn/ui components or composing primitives
  • Implementing forms with React Hook Form and Zod validation
  • Building data tables or handling large dataset displays
  • Customizing themes or adding dark mode support
  • Reviewing code for accessibility compliance

Rule Categories by Priority

PriorityCategoryImpactPrefix
1CLI & Project SetupCRITICALsetup-
2Component ArchitectureCRITICALarch-
3Accessibility PreservationCRITICALally-
4Styling & ThemingHIGHstyle-
5Form PatternsHIGHform-
6Data DisplayMEDIUM-HIGHdata-
7Layout & NavigationMEDIUMlayout-
8Component CompositionMEDIUMcomp-
9Performance OptimizationMEDIUMperf-
10State ManagementLOW-MEDIUMstate-

Quick Reference

1. CLI & Project Setup (CRITICAL)

  • setup-components-json [blocked] - Configure components.json before adding components
  • setup-path-aliases [blocked] - Configure TypeScript path aliases to match components.json
  • setup-cn-utility [blocked] - Create the cn utility before using components
  • setup-use-cli-not-copy [blocked] - Use CLI to add components instead of copy-paste
  • setup-css-variables-theme [blocked] - Enable CSS variables for consistent theming
  • setup-rsc-configuration [blocked] - Set RSC flag based on framework support

2. Component Architecture (CRITICAL)

  • arch-use-asChild-for-custom-triggers [blocked] - Use asChild prop for custom trigger elements
  • arch-preserve-radix-primitive-structure [blocked] - Maintain Radix compound component hierarchy
  • arch-extend-variants-with-cva [blocked] - Use Class Variance Authority for type-safe variants
  • arch-use-cn-for-class-merging [blocked] - Use cn() utility for safe Tailwind class merging
  • arch-forward-refs-for-composable-components [blocked] - Forward refs for form and focus integration
  • arch-isolate-component-variants [blocked] - Separate base styles from variant-specific styles

3. Accessibility Preservation (CRITICAL)

  • ally-preserve-aria-attributes [blocked] - Keep Radix ARIA attributes intact
  • ally-provide-sr-only-labels [blocked] - Add screen reader labels for icon buttons
  • ally-maintain-focus-management [blocked] - Preserve focus trapping in modals
  • ally-preserve-keyboard-navigation [blocked] - Keep WAI-ARIA keyboard patterns
  • ally-ensure-color-contrast [blocked] - Maintain WCAG color contrast ratios
  • ally-dialog-title-required [blocked] - Always include DialogTitle for screen readers
  • ally-form-field-labels [blocked] - Associate labels with form controls
  • ally-aria-invalid-errors [blocked] - Use aria-invalid for form error states
  • ally-checkbox-label-association [blocked] - Wrap Checkbox with Label for click target
  • ally-focus-visible-styles [blocked] - Preserve focus visible styles for keyboard navigation

4. Styling & Theming (HIGH)

  • style-use-css-variables-for-theming [blocked] - Use CSS variables for theme colors
  • style-avoid-important-overrides [blocked] - Never use !important for style overrides
  • style-use-tailwind-theme-extend [blocked] - Extend Tailwind theme for design tokens
  • style-consistent-spacing-scale [blocked] - Use consistent Tailwind spacing scale
  • style-responsive-design-patterns [blocked] - Apply mobile-first responsive design
  • style-dark-mode-support [blocked] - Support dark mode with CSS variables

5. Form Patterns (HIGH)

  • form-use-react-hook-form-integration [blocked] - Integrate with React Hook Form
  • form-use-zod-for-schema-validation [blocked] - Use Zod for type-safe validation
  • form-show-validation-errors-correctly [blocked] - Show errors at appropriate times
  • form-handle-async-validation [blocked] - Debounce async validation calls
  • form-reset-form-state-correctly [blocked] - Reset form state after submission

6. Data Display (MEDIUM-HIGH)

  • data-use-tanstack-table-for-complex-tables [blocked] - Use TanStack Table for sorting/filtering
  • data-virtualize-large-lists [blocked] - Virtualize lists with 100+ items
  • data-use-skeleton-loading-states [blocked] - Use Skeleton for loading states
  • data-paginate-server-side [blocked] - Paginate large datasets server-side
  • data-empty-states-with-guidance [blocked] - Provide actionable empty states

7. Layout & Navigation (MEDIUM)

  • layout-sidebar-provider [blocked] - Wrap layout with SidebarProvider
  • layout-sidebar-collapsible [blocked] - Configure sidebar collapsible behavior
  • layout-sidebar-groups [blocked] - Organize sidebar navigation with groups
  • layout-sheet-mobile-nav [blocked] - Use Sheet for mobile navigation overlay
  • layout-breadcrumb-navigation [blocked] - Implement breadcrumbs for deep navigation

8. Component Composition (MEDIUM)

  • comp-compose-with-compound-components [blocked] - Use compound component patterns
  • comp-use-drawer-for-mobile-modals [blocked] - Use Drawer on mobile devices
  • comp-combine-command-with-popover [blocked] - Create searchable selects with Command
  • comp-nest-dialogs-correctly [blocked] - Manage nested dialog focus correctly
  • comp-create-reusable-form-fields [blocked] - Extract reusable form field components
  • comp-use-slot-pattern-for-flexibility [blocked] - Use slot pattern for flexible content

9. Performance Optimization (MEDIUM)

  • perf-lazy-load-heavy-components [blocked] - Lazy load components over 50KB
  • perf-memoize-expensive-renders [blocked] - Memoize list items and expensive components
  • perf-optimize-icon-imports [blocked] - Use direct imports for Lucide icons
  • perf-avoid-unnecessary-rerenders-in-forms [blocked] - Isolate form field watching
  • perf-debounce-search-inputs [blocked] - Debounce search and filter inputs

10. State Management (LOW-MEDIUM)

  • state-prefer-uncontrolled-for-simple-inputs [blocked] - Use uncontrolled for simple forms
  • state-lift-state-to-appropriate-level [blocked] - Lift state to lowest common ancestor
  • state-use-controlled-dialog-state [blocked] - Control dialogs for programmatic access
  • state-colocate-state-with-components [blocked] - Keep state close to where it's used

How to Use

Read individual reference files for detailed explanations and code examples:

  • Section definitions [blocked] - Category structure and impact levels
  • Rule template [blocked] - Template for adding new rules

Full Compiled Document

For a single-file reference containing all rules, see AGENTS.md [blocked].

Reference Files

FileDescription
AGENTS.md [blocked]Complete compiled guide with all rules
references/_sections.md [blocked]Category definitions and ordering
assets/templates/_template.md [blocked]Template for new rules
metadata.json [blocked]Version and reference information

來源與署名

來源:pproenca/dot-skills位於skills/.curated/shadcn提交cf93c57

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架