shadcn
它能做什么
它指导 AI 智能体使用 shadcn/ui 组件库。该库提供用于网页应用界面的现成组件。适合使用该库构建网页应用的人。
适用场景
- ✓当你想在 shadcn/ui 项目中添加现成的按钮、表单或卡片时。
- ✓当应用中的某个组件显示异常,你想按照该库的设计方式修正样式时。
- ✓当你想在自行构建之前,先在该库中查找是否已有现成组件时。
技能链接
https://github.com/different-ai/openwork/blob/dev/.opencode/skills/shadcn/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请帮我用 shadcn 组件在应用中添加一个登录表单。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能会读取项目的设置和组件文档,然后按照该库的设计方式添加或调整组件。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
shadcn/ui
A framework for building ui, components and design systems. Components are added as source code to the user's project via the CLI.
IMPORTANT: Run all CLI commands using the project's package runner:
npx shadcn@latest,pnpm dlx shadcn@latest, orbunx --bun shadcn@latest— based on the project'spackageManager. Examples below usenpx shadcn@latestbut substitute the correct runner for the project.
Current Project Context
!`npx shadcn@latest info --json`
The JSON above contains the project config and installed components. Use npx shadcn@latest docs <component> to get documentation and example URLs for any component.
Principles
- Use existing components first. Use
npx shadcn@latest searchto check registries before writing custom UI. Check community registries too. - Compose, don't reinvent. Settings page = Tabs + Card + form controls. Dashboard = Sidebar + Card + Chart + Table.
- Use built-in variants before custom styles.
variant="outline",size="sm", etc. - Use semantic colors.
bg-primary,text-muted-foreground— never raw values likebg-blue-500.
Critical Rules
These rules are always enforced. Each links to a file with Incorrect/Correct code pairs.
Styling & Tailwind → styling.md
classNamefor layout, not styling. Never override component colors or typography.- No
space-x-*orspace-y-*. Useflexwithgap-*. For vertical stacks,flex flex-col gap-*. - Use
size-*when width and height are equal.size-10notw-10 h-10. - Use
truncateshorthand. Notoverflow-hidden text-ellipsis whitespace-nowrap. - No manual
dark:color overrides. Use semantic tokens (bg-background,text-muted-foreground). - Use
cn()for conditional classes. Don't write manual template literal ternaries. - No manual
z-indexon overlay components. Dialog, Sheet, Popover, etc. handle their own stacking.
Forms & Inputs → forms.md
- Forms use
FieldGroup+Field. Never use rawdivwithspace-y-*orgrid gap-*for form layout. InputGroupusesInputGroupInput/InputGroupTextarea. Never rawInput/TextareainsideInputGroup.- Buttons inside inputs use
InputGroup+InputGroupAddon. - Option sets (2–7 choices) use
ToggleGroup. Don't loopButtonwith manual active state. FieldSet+FieldLegendfor grouping related checkboxes/radios. Don't use adivwith a heading.- Field validation uses
data-invalid+aria-invalid.data-invalidonField,aria-invalidon the control. For disabled:data-disabledonField,disabledon the control.
Component Structure → composition.md
- Items always inside their Group.
SelectItem→SelectGroup.DropdownMenuItem→DropdownMenuGroup.CommandItem→CommandGroup. - Use
asChild(radix) orrender(base) for custom triggers. Checkbasefield fromnpx shadcn@latest info. → base-vs-radix.md - Dialog, Sheet, and Drawer always need a Title.
DialogTitle,SheetTitle,DrawerTitlerequired for accessibility. UseclassName="sr-only"if visually hidden. - Use full Card composition.
CardHeader/CardTitle/CardDescription/CardContent/CardFooter. Don't dump everything inCardContent. - Button has no
isPending/isLoading. Compose withSpinner+data-icon+disabled. TabsTriggermust be insideTabsList. Never render triggers directly inTabs.Avataralways needsAvatarFallback. For when the image fails to load.
Use Components, Not Custom Markup → composition.md
- Use existing components before custom markup. Check if a component exists before writing a styled
div. - Callouts use
Alert. Don't build custom styled divs. - Empty states use
Empty. Don't build custom empty state markup. - Toast via
sonner. Usetoast()fromsonner. - Use
Separatorinstead of<hr>or<div className="border-t">. - Use
Skeletonfor loading placeholders. No customanimate-pulsedivs. - Use
Badgeinstead of custom styled spans.
Icons → icons.md
- Icons in
Buttonusedata-icon.data-icon="inline-start"ordata-icon="inline-end"on the icon. - No sizing classes on icons inside components. Components handle icon sizing via CSS. N
常见问题
这项技能只适用于 shadcn/ui 项目吗?
是的。它适用于使用 shadcn/ui 的项目,这些项目带有 components.json 文件作为标识。
它能向我的项目添加新组件吗?
可以。它能以源代码的形式,把 shadcn 注册表中的组件添加到项目里。
它能解释如何使用某个组件吗?
可以。它能获取任何组件的文档和用法示例。
详情
作者的原始描述
Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI. Provides project context, component docs, and usage examples. Applies when working with shadcn/ui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for "shadcn init", "create an app with --preset", or "switch to --preset".
repo: different-ai/openwork
热度
- GitHub 星标
- 24k
- 排名
- #10111
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
create-plugin
24k帮你的智能体创建带有自定义工具和钩子的 OpenCode 插件,并使用符合该插件 API 的正确结构。
upload-photo
24k让你的智能体把截图或视频附加到 GitHub 拉取请求或议题中,并添加替代文字,方便无障碍阅读。
connect-openwork-mcp
24k帮你的智能体连接 OpenWork MCP 网关,使其可以使用你团队的 OpenWork 技能、插件和连接。
install-openwork
24k帮你的智能体在电脑上安装免费的 OpenWork 桌面应用,并带你完成第一个任务。