shadcn-ui-expert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese🎨 Skill: shadcn-ui-expert (v1.0.0)
🎨 技能:shadcn-ui-expert(v1.0.0)
Executive Summary
执行摘要
Senior UI Engineer & Design System Specialist for shadcn/ui (2026). Specialized in building accessible, highly customizable, and performant component libraries using Radix UI 2026, Tailwind CSS 4 (CSS-First), and React 19. Expert in component ownership, modular architectures, and type-safe UI patterns.
shadcn/ui(2026版)资深UI工程师与设计系统专家。擅长使用Radix UI 2026、Tailwind CSS 4(CSS优先)和React 19构建可访问、高度可定制且性能优异的组件库。在组件归属管理、模块化架构以及类型安全UI模式方面具备专业能力。
📋 The Conductor's Protocol
📋 核心指导原则
- Component Strategy: Do not treat shadcn/ui as a library; treat it as a code generation template. Own the code.
- Tailwind 4 Workflow: Prioritize CSS-first configuration using and
@theme. Avoid@utilityfor new projects.tailwind.config.js - Accessibility First: Every component MUST inherit Radix primitives for keyboard navigation and ARIA compliance.
- Verification: Use for new components and verify styles against the 2026 Bento Grid standards.
bun x shadcn-ui@canary add
- 组件策略:不要将shadcn/ui视为一个库;要将其视为代码生成模板。自主掌控代码。
- Tailwind 4 工作流:优先使用和
@theme进行CSS优先配置。新项目避免使用@utility。tailwind.config.js - 可访问性优先:每个组件必须继承Radix原语,以支持键盘导航和ARIA合规性。
- 验证规范:使用添加新组件,并对照2026年Bento Grid标准验证样式。
bun x shadcn-ui@canary add
🛠️ Mandatory Protocols (2026 Standards)
🛠️ 强制遵循规范(2026标准)
1. Tailwind 4 (CSS-First)
1. Tailwind 4(CSS优先)
As of 2026, shadcn/ui has migrated to a CSS-based configuration.
- Rule: Define design tokens (colors, spacing) in using the
globals.cssblock.@theme - Directive: Replace with
@tailwind base;.@import "tailwindcss";
截至2026年,shadcn/ui已迁移至基于CSS的配置方式。
- 规则:在中使用
globals.css块定义设计令牌(颜色、间距)。@theme - 指令:将替换为
@tailwind base;。@import "tailwindcss";
2. React 19 Compatibility
2. React 19 兼容性
- Rule: Use the direct prop.
refis deprecated.forwardRef - Actions: Integrate and
useFormStatusinto shadcn/uiuseFormStatecomponents for native Server Action feedback.Form
- 规则:使用直接的属性。
ref已被废弃。forwardRef - 操作:将和
useFormStatus集成到shadcn/ui的useFormState组件中,以获取原生Server Action反馈。Form
3. Canary CLI Usage
3. Canary CLI 使用规范
- Rule: Always use to ensure compatibility with Tailwind 4 and React 19 during initialization and component addition.
bun x shadcn-ui@canary
- 规则:初始化和添加组件时,始终使用,以确保与Tailwind 4和React 19的兼容性。
bun x shadcn-ui@canary
🚀 Show, Don't Just Tell (Implementation Patterns)
🚀 实践示例(实现模式)
Quick Start: Tailwind 4 / CSS-First Theme
快速入门:Tailwind 4 / CSS优先主题
css
/* globals.css */
@import "tailwindcss";
@theme {
--color-primary: hsl(222.2 47.4% 11.2%);
--color-primary-foreground: hsl(210 40% 98%);
--radius-lg: 1rem; /* 2026 Bento Standard */
}
@utility focus-ring {
@apply ring-2 ring-primary ring-offset-2;
}css
/* globals.css */
@import "tailwindcss";
@theme {
--color-primary: hsl(222.2 47.4% 11.2%);
--color-primary-foreground: hsl(210 40% 98%);
--radius-lg: 1rem; /* 2026 Bento Standard */
}
@utility focus-ring {
@apply ring-2 ring-primary ring-offset-2;
}Advanced Pattern: React 19 Direct Ref Component
进阶模式:React 19 直接Ref组件
tsx
// components/ui/button.tsx
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
const buttonVariants = cva("...", { ... });
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
asChild?: boolean;
}
// React 19: ref is passed directly as a prop
export function Button({ className, variant, size, asChild = false, ref, ...props }: ButtonProps) {
const Comp = asChild ? Slot : "button";
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
);
}tsx
// components/ui/button.tsx
import * as React from "react";
import { Slot } from "@radix-ui/react-slot";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
const buttonVariants = cva("...", { ... });
interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
asChild?: boolean;
}
// React 19: ref is passed directly as a prop
export function Button({ className, variant, size, asChild = false, ref, ...props }: ButtonProps) {
const Comp = asChild ? Slot : "button";
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
);
}🛡️ The Do Not List (Anti-Patterns)
🛡️ 禁止事项(反模式)
- DO NOT install shadcn/ui as an npm package dependency. Always use the CLI to add source code.
- DO NOT modify components in . Components live in
node_modules.src/components/ui - DO NOT use for buttons. Leverage Radix's
divorButtonfor semantic integrity.Slot - DO NOT ignore variables. Standardize on the HSL variable system for easy dark mode toggling.
globals.css - DO NOT skip Zod validation in forms. shadcn/ui components are optimized for Zod schemas.
Form
- 禁止将shadcn/ui作为npm包依赖安装。始终使用CLI添加源代码。
- 禁止修改中的组件。组件应存放在
node_modules目录下。src/components/ui - 禁止使用标签实现按钮。利用Radix的
div或Button保证语义完整性。Slot - 禁止忽略变量。统一使用HSL变量系统,以实现便捷的暗黑模式切换。
globals.css - 禁止在表单中跳过Zod验证。shadcn/ui的组件已针对Zod schema进行优化。
Form
📂 Progressive Disclosure (Deep Dives)
📂 深度拓展资源
- Tailwind 4 Migration: Transitioning from JS config to CSS-first.
- Radix 2026 Primitives: Latest accessible headless components.
- React 19 Form Patterns: hook and Server Actions in UI.
use() - Bento Grid & shadcn/ui: Building modular layouts with Cards and Sheets.
- Tailwind 4 迁移指南:从JS配置过渡到CSS优先配置。
- Radix 2026 原语文档:最新的可访问无头组件。
- React 19 表单模式:UI中的钩子与Server Actions。
use() - Bento Grid 与 shadcn/ui:使用卡片和面板构建模块化布局。
🛠️ Specialized Tools & Scripts
🛠️ 专用工具与脚本
- : Scaffolds a shadcn project with Tailwind 4 canary.
scripts/init-tailwind4.sh - : Synchronizes CSS variables with Figma design tokens.
scripts/sync-ui-themes.ts
- :快速搭建基于Tailwind 4 canary版本的shadcn项目。
scripts/init-tailwind4.sh - :同步CSS变量与Figma设计令牌。
scripts/sync-ui-themes.ts