Skip to content

📚 shadcn/ui 所有组件列表

📋 当前可用组件(持续更新中)

基础组件

npx shadcn@latest add button
npx shadcn@latest add badge
npx shadcn@latest add avatar
npx shadcn@latest add icon

布局组件

npx shadcn@latest add card
npx shadcn@latest add sheet
npx shadcn@latest add accordion
npx shadcn@latest add tabs
npx shadcn@latest add separator
npx shadcn@latest add aspect-ratio

导航组件

npx shadcn@latest add navigation-menu
npx shadcn@latest add breadcrumb
npx shadcn@latest add pagination
npx shadcn@latest add sidebar

表单组件

npx shadcn@latest add form
npx shadcn@latest add input
npx shadcn@latest add textarea
npx shadcn@latest add label
npx shadcn@latest add button
npx shadcn@latest add select
npx shadcn@latest add checkbox
npx shadcn@latest add radio-group
npx shadcn@latest add switch
npx shadcn@latest add slider
npx shadcn@latest add toggle
npx shadcn@latest add toggle-group
npx shadcn@latest add combobox

数据展示组件

npx shadcn@latest add table
npx shadcn@latest add data-table
npx shadcn@latest add chart
npx shadcn@latest add calendar
npx shadcn@latest add progress
npx shadcn@latest add skeleton
npx shadcn@latest add timeline

反馈组件

npx shadcn@latest add alert
npx shadcn@latest add alert-dialog
npx shadcn@latest add dialog
npx shadcn@latest add toast
npx shadcn@latest add tooltip
npx shadcn@latest add popover
npx shadcn@latest add hover-card
npx shadcn@latest add context-menu
npx shadcn@latest add dropdown-menu
npx shadcn@latest add command
npx shadcn@latest add menubar

多媒体组件

npx shadcn@latest add image

其他组件

npx shadcn@latest add collapsible
npx shadcn@latest add scroll-area
npx shadcn@latest add resizable
npx shadcn@latest add carousel

🎯 完整组件列表(按类别)

1. 基础组件

组件命令描述
Buttonadd button按钮组件
Badgeadd badge徽章标签
Avataradd avatar头像组件
Iconadd icon图标组件

2. 布局组件

组件命令描述
Cardadd card卡片容器
Sheetadd sheet侧边栏面板
Accordionadd accordion手风琴组件
Tabsadd tabs标签页组件
Separatoradd separator分隔线
Aspect Ratioadd aspect-ratio宽高比容器

3. 导航组件

组件命令描述
Navigation Menuadd navigation-menu导航菜单
Breadcrumbadd breadcrumb面包屑导航
Paginationadd pagination分页组件
Sidebaradd sidebar侧边栏

4. 表单组件

组件命令描述
Formadd form表单组件(React Hook Form)
Inputadd input输入框
Textareaadd textarea文本域
Labeladd label表单标签
Selectadd select选择器
Checkboxadd checkbox复选框
Radio Groupadd radio-group单选框组
Switchadd switch开关
Slideradd slider滑块
Toggleadd toggle切换按钮
Toggle Groupadd toggle-group切换按钮组
Comboboxadd combobox组合框

5. 数据展示组件

组件命令描述
Tableadd table表格
Data Tableadd data-table数据表格(TanStack Table)
Chartadd chart图表组件
Calendaradd calendar日历
Progressadd progress进度条
Skeletonadd skeleton骨架屏
Timelineadd timeline时间轴

6. 反馈组件

组件命令描述
Alertadd alert警告提示
Alert Dialogadd alert-dialog确认对话框
Dialogadd dialog对话框
Toastadd toast消息提示
Tooltipadd tooltip工具提示
Popoveradd popover弹出框
Hover Cardadd hover-card悬停卡片
Context Menuadd context-menu右键菜单
Dropdown Menuadd dropdown-menu下拉菜单
Commandadd command命令面板(类似 Spotlight)
Menubaradd menubar菜单栏

7. 多媒体组件

组件命令描述
Imageadd image图片组件

8. 其他组件

组件命令描述
Collapsibleadd collapsible可折叠内容
Scroll Areaadd scroll-area滚动区域
Resizableadd resizable可调整大小
Carouseladd carousel轮播图

💡 实际使用示例

完整表单示例

import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"

function LoginForm() {
  return (
    <Card className="w-full max-w-sm">
      <CardHeader>
        <CardTitle>登录</CardTitle>
      </CardHeader>
      <CardContent className="space-y-4">
        <div className="space-y-2">
          <Label htmlFor="email">邮箱</Label>
          <Input id="email" type="email" placeholder="请输入邮箱" />
        </div>
        <div className="space-y-2">
          <Label htmlFor="password">密码</Label>
          <Input id="password" type="password" placeholder="请输入密码" />
        </div>
        <Button className="w-full">登录</Button>
      </CardContent>
    </Card>
  )
}

数据表格示例

import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"

function UserTable() {
  return (
    <Table>
      <TableHeader>
        <TableRow>
          <TableHead>姓名</TableHead>
          <TableHead>邮箱</TableHead>
          <TableHead>状态</TableHead>
        </TableRow>
      </TableHeader>
      <TableBody>
        <TableRow>
          <TableCell>张三</TableCell>
          <TableCell>zhangsan@example.com</TableCell>
          <TableCell>活跃</TableCell>
        </TableRow>
      </TableBody>
    </Table>
  )
}

交互组件示例

import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"
import { Button } from "@/components/ui/button"

function UserDialog() {
  return (
    <Dialog>
      <DialogTrigger asChild>
        <Button>打开对话框</Button>
      </DialogTrigger>
      <DialogContent>
        <DialogHeader>
          <DialogTitle>用户信息</DialogTitle>
          <DialogDescription>查看和编辑用户详细信息</DialogDescription>
        </DialogHeader>
        {/* 对话框内容 */}
      </DialogContent>
    </Dialog>
  )
}

🚀 批量安装命令

安装常用组件组

# 基础组件组
npx shadcn@latest add button badge avatar card

# 表单组件组
npx shadcn@latest add form input label select checkbox

# 布局组件组
npx shadcn@latest add table dialog dropdown-menu tooltip

# 完整项目组件组
npx shadcn@latest add button input label card table dialog dropdown-menu form select

查看所有可用组件

# 查看当前所有可用的组件
npx shadcn@latest add

# 输出示例:
# Available components:
# ○ accordion
# ○ alert
# ○ alert-dialog
# ○ aspect-ratio
# ○ avatar
# ○ badge
# ○ breadcrumb
# ○ button
# ○ calendar
# ○ card
# ○ carousel
# ○ chart
# ○ checkbox
# ○ collapsible
# ○ combobox
# ○ command
# ○ context-menu
# ○ data-table
# ○ dialog
# ○ dropdown-menu
# ○ form
# ○ hover-card
# ○ icon
# ○ image
# ○ input
# ○ label
# ○ menubar
# ○ navigation-menu
# ○ pagination
# ○ popover
# ○ progress
# ○ radio-group
# ○ resizable
# ○ scroll-area
# ○ select
# ○ separator
# ○ sheet
# ○ sidebar
# ○ skeleton
# ○ slider
# ○ switch
# ○ table
# ○ tabs
# ○ textarea
# ○ timeline
# ○ toggle
# ○ toggle-group
# ○ tooltip

🔧 配置和定制

自定义主题配置

# 初始化时选择配置
npx shadcn@latest init

# 重新配置主题
npx shadcn@latest init --force

组件定制示例

// 定制按钮组件 - 直接修改源码
// src/components/ui/button.tsx
import * as React from "react"
import { cn } from "@/lib/utils"

export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
  variant?: "default" | "destructive" | "outline" | "secondary" | "ghost" | "link"
  size?: "default" | "sm" | "lg" | "icon"
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
  ({ className, variant = "default", size = "default", …props }, ref) => {
    return (
      <button
        className={cn(
          "inline-flex items-center justify-center rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:opacity-50 disabled:pointer-events-none ring-offset-background",
          {
            "bg-primary text-primary-foreground hover:bg-primary/90": variant === "default",
            "bg-destructive text-destructive-foreground hover:bg-destructive/90": variant === "destructive",
            "border border-input hover:bg-accent hover:text-accent-foreground": variant === "outline",
            "bg-secondary text-secondary-foreground hover:bg-secondary/80": variant === "secondary",
            "hover:bg-accent hover:text-accent-foreground": variant === "ghost",
            "underline-offset-4 hover:underline text-primary": variant === "link",
          },
          {
            "h-10 py-2 px-4": size === "default",
            "h-9 px-3 rounded-md": size === "sm",
            "h-11 px-8 rounded-md": size === "lg",
            "h-10 w-10": size === "icon",
          },
          className
        )}
        ref={ref}
        {…props}
      />
    )
  }
)
Button.displayName = "Button"

export { Button }

📱 响应式设计

移动端适配示例

import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet"
import { Button } from "@/components/ui/button"

function MobileNavigation() {
  return (
    <div className="md:hidden">
      <Sheet>
        <SheetTrigger asChild>
          <Button variant="outline">菜单</Button>
        </SheetTrigger>
        <SheetContent side="left">
          {/* 移动端导航内容 */}
        </SheetContent>
      </Sheet>
    </div>
  )
}

🎨 主题和样式

暗色模式支持

import { Button } from "@/components/ui/button"

function ThemeToggle() {
  return (
    <Button variant="outline" onClick={() => document.documentElement.classList.toggle('dark')}>
      切换主题
    </Button>
  )
}

// 所有组件自动支持暗色模式
// 在 tailwind.config.js 中配置 darkMode: 'class'

🔄 更新组件

更新到最新版本

# 更新所有组件到最新版本
npx shadcn@latest update

# 更新特定组件
npx shadcn@latest update button card

💡 最佳实践建议

  1. 按需安装:只安装需要的组件,保持项目轻量
  2. 及时更新:定期更新组件以获得最新功能和修复
  3. 自定义样式:直接修改组件源码来定制样式
  4. 组合使用:结合其他库(如 Framer Motion)增强交互
  5. 类型安全:所有组件都提供完整的 TypeScript 类型定义

这个列表会随着 shadcn/ui 的更新而不断增加新组件。建议定期查看官方文档获取最新信息!🚀