跳到正文
Skillpedia
界面(UI/UX)48k · #5768

shadcn

它能做什么

shadcn/ui 是一套用于构建用户界面和设计系统的工具包。它可以通过一条命令,把现成可用的组件直接添加到你的项目中。

适用场景

  • ✓给项目添加新的界面组件时。
  • ✓调整现有组件的外观或修复其中的问题时。
  • ✓开始新项目或更换项目视觉风格时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/shadcn/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/shadcn/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我该怎么在项目里添加一个卡片按钮?”

每周 5 个新技能,1 分钟读完。

工作原理

你在终端中使用一条特殊命令(CLI),例如 `npx shadcn@latest add card`,工具就会把组件代码直接插入你的项目中。它还能帮你查找文档和使用示例。

技术内容(原始 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, or bunx --bun shadcn@latest — based on the project's packageManager. Examples below use npx shadcn@latest but substitute the correct runner for the project.

When to Use

  • Use when adding new components from shadcn/ui or community registries.
  • Use when styling, composing, or debugging existing shadcn/ui components.
  • Use when initializing a new project or switching design system presets.
  • Use to retrieve component documentation, examples, and API references.

Current Project Context

!`npx shadcn@latest info --json 2>/dev/null || echo '{"error": "No shadcn project found. Run shadcn init first."}'`

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

  1. Use existing components first. Use npx shadcn@latest search to check registries before writing custom UI. Check community registries too.
  2. Compose, don't reinvent. Settings page = Tabs + Card + form controls. Dashboard = Sidebar + Card + Chart + Table.
  3. Use built-in variants before custom styles. variant="outline", size="sm", etc.
  4. Use semantic colors. bg-primary, text-muted-foreground — never raw values like bg-blue-500.

Critical Rules

These rules are always enforced. Each links to a file with Incorrect/Correct code pairs.

Styling & Tailwind → styling.md

  • className for layout, not styling. Never override component colors or typography.
  • No space-x-* or space-y-*. Use flex with gap-*. For vertical stacks, flex flex-col gap-*.
  • Use size-* when width and height are equal. size-10 not w-10 h-10.
  • Use truncate shorthand. Not overflow-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-index on overlay components. Dialog, Sheet, Popover, etc. handle their own stacking.

Forms & Inputs → forms.md

  • Forms use FieldGroup + Field. Never use raw div with space-y-* or grid gap-* for form layout.
  • InputGroup uses InputGroupInput/InputGroupTextarea. Never raw Input/Textarea inside InputGroup.
  • Buttons inside inputs use InputGroup + InputGroupAddon.
  • Option sets (2–7 choices) use ToggleGroup. Don't loop Button with manual active state.
  • FieldSet + FieldLegend for grouping related checkboxes/radios. Don't use a div with a heading.
  • Field validation uses data-invalid + aria-invalid. data-invalid on Field, aria-invalid on the control. For disabled: data-disabled on Field, disabled on the control.

Component Structure → composition.md

  • Items always inside their Group. SelectItem → SelectGroup. DropdownMenuItem → DropdownMenuGroup. CommandItem → CommandGroup.
  • Use asChild (radix) or render (base) for custom triggers. Check base field from npx shadcn@latest info. → base-vs-radix.md
  • Dialog, Sheet, and Drawer always need a Title. DialogTitle, SheetTitle, DrawerTitle required for accessibility. Use className="sr-only" if visually hidden.
  • Use full Card composition. CardHeader/CardTitle/CardDescription/CardContent/CardFooter. Don't dump everything in CardContent.
  • Button has no isPending/isLoading. Compose with Spinner + data-icon + disabled.
  • TabsTrigger must be inside TabsList. Never render triggers directly in Tabs.
  • Avatar always needs AvatarFallback. 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. Use toast() from sonner.

…

常见问题

什么是 shadcn/ui?

它是一组界面组件(比如按钮、卡片、菜单),你可以把它们加到编程项目中,更快、更统一地搭建现代界面。

怎么使用这些组件?

在终端里用特定命令添加你需要的组件。之后它们会以源代码的形式出现在项目中,你可以直接使用并自由修改。

使用它需要懂很多设计吗?

不一定。shadcn/ui 自带统一的设计风格和最佳实践,会引导你使用语义化颜色,并组合已有组件,让你更容易做出美观又实用的界面。

详情

作者的原始描述

Manages shadcn/ui components and projects, providing context, documentation, and usage patterns for building modern design systems.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5768
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能