Get Started
组件
- Accordion
- Alert Dialog
- Alert
- Aspect Ratio
- Avatar
- Badge
- Breadcrumb
- Button Group
- Button
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Form
- Hover Card
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Label
- Menubar
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle Group
- Toggle
- Tooltip
- Typography
init
使用 init 命令为新项目初始化配置与依赖。
init 会安装依赖、添加 cn 工具函数,并为项目配置 CSS 变量。
pnpm dlx shadcn@latest init
命令选项
Usage: shadcn init [options] [components...]
initialize your project and install dependencies
Arguments:
components name, url or local path to component
Options:
-t, --template <template> the template to use. (next, next-monorepo)
-b, --base-color <base-color> the base color to use. (neutral, gray, zinc, stone, slate)
-y, --yes skip confirmation prompt. (default: true)
-f, --force force overwrite of existing configuration. (default: false)
-c, --cwd <cwd> the working directory. defaults to the current directory.
-s, --silent mute output. (default: false)
--src-dir use the src directory when creating a new project. (default: false)
--no-src-dir do not use the src directory when creating a new project.
--css-variables use css variables for theming. (default: true)
--no-css-variables do not use css variables for theming.
--no-base-style do not install the base shadcn style
-h, --help display help for commandadd
使用 add 命令将组件及其依赖添加到项目中。
pnpm dlx shadcn@latest add [component]
命令选项
Usage: shadcn add [options] [components...]
add a component to your project
Arguments:
components name, url or local path to component
Options:
-y, --yes skip confirmation prompt. (default: false)
-o, --overwrite overwrite existing files. (default: false)
-c, --cwd <cwd> the working directory. defaults to the current directory.
-a, --all add all available components (default: false)
-p, --path <path> the path to add the component to.
-s, --silent mute output. (default: false)
--src-dir use the src directory when creating a new project. (default: false)
--no-src-dir do not use the src directory when creating a new project.
--css-variables use css variables for theming. (default: true)
--no-css-variables do not use css variables for theming.
-h, --help display help for commandview
使用 view 命令在安装前预览注册表中的条目。
pnpm dlx shadcn@latest view [item]
可以一次查看多个条目:
pnpm dlx shadcn@latest view button card dialog
也可以查看带命名空间的注册表条目:
pnpm dlx shadcn@latest view @acme/auth @v0/dashboard
命令选项
Usage: shadcn view [options] <items...>
view items from the registry
Arguments:
items the item names or URLs to view
Options:
-c, --cwd <cwd> the working directory. defaults to the current directory.
-h, --help display help for commandsearch
使用 search 命令在注册表中搜索条目。
pnpm dlx shadcn@latest search [registry]
可以配合查询关键字使用:
pnpm dlx shadcn@latest search @shadcn -q "button"
也可以一次搜索多个注册表:
pnpm dlx shadcn@latest search @shadcn @v0 @acme
list 命令是 search 的别名:
pnpm dlx shadcn@latest list @acme
命令选项
Usage: shadcn search|list [options] <registries...>
search items from registries
Arguments:
registries the registry names or urls to search items from. Names
must be prefixed with @.
Options:
-c, --cwd <cwd> the working directory. defaults to the current directory.
-q, --query <query> query string
-l, --limit <number> maximum number of items to display per registry (default: "100")
-o, --offset <number> number of items to skip (default: "0")
-h, --help display help for commandlist
使用 list 命令列出某个注册表中的所有条目。
pnpm dlx shadcn@latest list @acme
命令选项
Usage: shadcn list [options] <registries...>
list items from registries
Arguments:
registries the registry names or urls to list items from. Names
must be prefixed with @.build
使用 build 命令生成注册表 JSON 文件。
pnpm dlx shadcn@latest build
该命令会读取 registry.json,并在 public/r 目录下生成对应的注册表 JSON 文件。
命令选项
Usage: shadcn build [options] [registry]
build components for a shadcn registry
Arguments:
registry path to registry.json file (default: "./registry.json")
Options:
-o, --output <path> destination directory for json files (default: "./public/r")
-c, --cwd <cwd> the working directory. defaults to the current directory.
-h, --help display help for command可以通过 --output 参数自定义输出目录:
pnpm dlx shadcn@latest build --output ./public/registry