shadcn-patterns
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineseshadcn/ui patterns
shadcn/ui 模式
Use existing shadcn components from . Do not reinvent primitives.
@/components/ui使用中现有的shadcn组件。不要重新实现基础组件。
@/components/uiDialog vs Sheet
Dialog 与 Sheet
| Use | Component |
|---|---|
| Desktop modal, short forms | |
| Mobile-first, filters, long forms | |
Always include / for accessibility.
DialogTitleSheetTitle| 使用场景 | 组件 |
|---|---|
| 桌面端模态框、短表单 | |
| 移动端优先、筛选器、长表单 | |
始终包含 / 以满足无障碍要求。
DialogTitleSheetTitleData tables
数据表
- Use with shadcn
@tanstack/react-table,Tablepattern.DataTable - Column headers sortable when list is large.
- Row actions in , not 5 inline buttons.
DropdownMenu - Empty/error states via skill.
error-states-and-empty-ui
- 将与shadcn的
@tanstack/react-table、Table模式配合使用。DataTable - 当列表数据量大时,列标题需支持排序。
- 行操作放在中,不要使用5个内联按钮。
DropdownMenu - 空状态/错误状态参考技能。
error-states-and-empty-ui
Forms
表单
- ,
Form,FormField,FormItem,FormLabel,FormControl.FormMessage - Pair with Zod + react-hook-form (skill).
typed-api-hooks-forms
- 使用、
Form、FormField、FormItem、FormLabel、FormControl。FormMessage - 搭配Zod + react-hook-form(参考技能)。
typed-api-hooks-forms
Buttons and actions
按钮与操作
- One primary action per section; destructive uses .
variant="destructive" - +
Buttonduring mutations.disabled={isPending}
- 每个区域仅保留一个主要操作;破坏性操作使用。
variant="destructive" - 数据变更期间,需添加
Button属性。disabled={isPending}
Command palette
命令面板
- ,
Command,CommandInput,CommandListfor search/navigation.CommandItem - Keyboard: Cmd/Ctrl+K when spec asks for it.
- 使用、
Command、CommandInput、CommandList实现搜索/导航功能。CommandItem - 若需求中指定,支持键盘快捷键Cmd/Ctrl+K。
Toasts and notifications
提示框与通知
- Use Sonner (once at the root) for transient feedback.
<Toaster /> - One toast per action; don't stack 5 success toasts.
- Errors: short message + optional retry; never raw from Supabase.
error.message
ts
import { toast } from "sonner";
toast.success("Project created");
toast.error("Could not save changes", { description: "Please try again." });- 使用Sonner(在根节点处仅渲染一次)提供临时反馈。
<Toaster /> - 每个操作仅显示一个提示框;不要堆叠5个成功提示框。
- 错误提示:简短消息 + 可选重试按钮;绝不要直接显示Supabase返回的原始。
error.message
ts
import { toast } from "sonner";
toast.success("Project created");
toast.error("Could not save changes", { description: "Please try again." });Navigation patterns
导航模式
- Persistent left for app shell;
Sidebarinside a route for sub-views.Tabs - once routes go ≥ 3 levels deep.
Breadcrumb - Mobile: bottom nav or drawer — never desktop sidebar squeezed onto phones.
Sheet
- 应用外壳使用固定左侧;路由内使用
Sidebar切换子视图。Tabs - 当路由层级≥3级时,使用面包屑。
Breadcrumb - 移动端:使用底部导航或抽屉——绝不要将桌面端侧边栏压缩适配手机。
Sheet
Responsive
响应式设计
- Stack filters in on mobile; inline on
Sheet.md+ - Touch targets ≥ 44px where possible.
- Test at 375px width.
- 移动端将筛选器堆叠在中;
Sheet尺寸(中等及以上屏幕)时使用内联布局。md+ - 触摸目标尽可能≥44px。
- 在375px宽度下测试。
Theming
主题
- Use CSS variables from shadcn (,
bg-background) — never hardcodedtext-foreground.#fff - Dark mode: see skill.
dark-mode-and-theming
- 使用shadcn提供的CSS变量(、
bg-background)——绝不要硬编码text-foreground。#fff - 深色模式:参考技能。
dark-mode-and-theming
Avoid
注意避免
- Raw HTML styled ad hoc when shadcn exists.
<button> - Nested dialogs without clear close path.
- Missing labels on icon-only buttons.
aria - Multiple toast libraries (Sonner + react-hot-toast + custom) in one app.
- 当shadcn组件存在时,不要使用自定义样式的原生HTML 。
<button> - 不要使用没有清晰关闭路径的嵌套对话框。
- 纯图标按钮不要缺失标签。
aria - 同一应用中不要使用多个提示框库(Sonner + react-hot-toast + 自定义)。