shadcn/ui
The shadcn/ui approach: 29 components on Radix and Tailwind are placed in the project and belong to it, a theme on CSS variables in a light and a dark scheme, cn(), components.json. Norms: components in one folder, colors only from the theme, a complete theme, a valid config.
关于该包
这段内容尚未翻译,下面是英文原文。
The shadcn/ui approach for a project on React and Tailwind 4: component sources live in the project and belong to it, and the look is held by a theme of CSS variables. What this approach is in our own words, what is placed and how to add a component is on the page shadcn/ui.
What it installs
- The page shadcn/ui: a guide, the list of the project's components (
components:), where@/points (aliasRoot:). - A theme showcase: buttons, fields, a card, tabs, badges, alerts in the light and dark schemes, and the contrast of color pairs.
- The
placeaction (runs by itself after install and update): components go to theuifolder fromcomponents.json,cn()toutils, the theme totailwind.css, andcomponents.jsonif there is none; hashes go to.shadcn.json. It does not overwrite edited files. - The registry: 29 shadcn/ui components (style
new-york-v4),cn(), the "neutral" theme for Tailwind 4, and the defaultcomponents.json, in.shtukbase/packages/shadcn/registry/with the MIT license and a note of the source. - Norms:
- SHD-R01:
components.jsonis valid; theconfigcheck. - SHD-R02: components in one folder, Radix primitives only there; the
foldercheck. - SHD-R03: colors only from the theme: no Tailwind palette and no custom colors in components; the
colorscheck. - SHD-R04: the theme has a light and a dark scheme and all required variables; the
themecheck.
- SHD-R01:
Where the boundary is
- The package does not install npm dependencies and does not build code: the needed packages (
react,radix-ui,cva,cn,lucide-react,tailwindcss4,tw-animate-css) are printed byplaceas a list. - The registry has 29 components; blocks, charts, a calendar and a sidebar are not included. The rest is added with the ordinary shadcn CLI; they share
components.json. - Theme contrast is a norm of the
design-a11ypackage, spacing and font scales belong todesign-scales. tools/vendor.tsis for whoever maintains the package: it re-reads the components from the open shadcn registry. Installation does not run it.
Source: shadcn/ui, https://ui.shadcn.com, MIT © 2023 shadcn; read on 28.11.2026.
规范 4
| ID | 规范 | 级别 | 模式 | Enforcer |
|---|---|---|---|---|
| SHD-R01 | 项目根目录的 components.json 是一个 JSON 对象,其字段为 shadcn 所读取的字段,且类型正确;tailwind.css 中指定的主题文件存在;ui 与 utils 别名指向一个文件夹与一个文件。 |
MUST | 拦截 | 检查 |
| SHD-R02 | 界面组件位于同一个文件夹中,即 components.json 中 ui 别名所指的文件夹:所有已放入的组件都在其中;在该文件夹之外,文件不声明组件(data-slot),也不导入 Radix 原语。 |
MUST | 拦截 | 检查 |
| SHD-R03 | 在产品的组件与屏幕中,颜色只取自主题变量:不使用 Tailwind 调色板颜色(bg-red-500),不使用自定义颜色(bg-[#fff]、style={{ color: "#333" }}、fill="#000"),也不在 CSS 规则中使用原始颜色。 |
MUST | 拦截 | 检查 |
| SHD-R04 | 项目 CSS 中的主题在 :root 中设定 --radius 以及全部必需的 shadcn 颜色,暗色配色(.dark)再次设定全部必需的颜色;每个值都须是一个颜色。 |
MUST | 拦截 | 检查 |
“拦截”:enforcer 会阻止违规;“观察”:只记录违规。MUST 级别表示必须遵守;SHOULD 表示默认应当遵守。
动作 5
| 名称 | 作用 | 文件 | 时机 |
|---|---|---|---|
| place | Place components in the project (the list is on /design/shadcn.md; names in the arguments add more; --force replaces edited ones) | actions/place.ts | 安装后 更新后 |
| config | components.json is valid 规范 SHD-R01 | checks/config.ts | 检查 |
| folder | Components in one folder, Radix only there 规范 SHD-R02 | checks/folder.ts | 检查 |
| colors | Colors only from the theme 规范 SHD-R03 | checks/colors.ts | 检查 |
| theme | The theme has both schemes and all required variables 规范 SHD-R04 | checks/theme.ts | 检查 |
shtuk check 运行检查;shtuk run shadcn <名称> 运行任意动作。“安装后”动作只有在包来自可信来源时才会自动运行。
页面 6
这些页面会放到项目中的以下路径。
- /design/
- shadcn/ui 页面
- /design/shadcn/
- showcase.html 文件
- /norms/rules/shadcn/
- components.json 有效 SHD-R01
- 组件位于同一文件夹 SHD-R02
- 颜色只取自主题 SHD-R03
- 主题具备两套配色和全部必需变量 SHD-R04
包文件 43
它们会放到 .shtukbase/packages/shadcn/,动作从那里运行。