组件
- 手风琴 Accordion
- 警告 Alert
- 警告对话框 Alert Dialog
- 宽高比 Aspect Ratio
- 头像 Avatar
- 徽章 Badge
- 面包屑 Breadcrumb
- 按钮 Button
- 按钮组 Button Group
- 日历 Calendar
- 卡片 Card
- 轮播图 Carousel
- 图表 Chart
- 复选框 Checkbox
- 折叠面板 Collapsible
- 组合框 Combobox
- 命令菜单 Command
- 上下文菜单 Context Menu
- 数据表格 Data Table
- 日期选择器 Date Picker
- 对话框 Dialog
- 抽屉 Drawer
- 下拉菜单 Dropdown Menu
- 空状态 Empty
- 字段 Field
- 表单 Form
- 悬停卡片 Hover Card
- 输入 Input
- 输入组 Input Group
- 一次性密码 OTP
- 条目 Item
- 快捷键 Kbd
- 标签 Label
- 菜单栏 Menubar
- 导航菜单 Navigation Menu
- 分页 Pagination
- 弹出层 Popover
- 进度 Progress
- 单选框组 Radio Group
- 可调整大小 Resizable
- 滚动区域 Scroll Area
- 选择框 Select
- 分隔符 Separator
- 侧边栏 Sheet
- 侧边栏 Sidebar
- 骨架屏 Skeleton
- 滑块 Slider
- 通知 Sonner
- 加载指示器 Spinner
- 开关 Switch
- 表格 Table
- 标签页 Tabs
- 文本区域 Textarea
- 消息 Toast
- 切换按钮 Toggle
- 切换组 Toggle Group
- 提示 Tooltip
- 排版 Typography
注意: 本指南针对 Remix。React Router 的相关内容,请参阅 React Router 指南。
创建项目
首先使用 create-remix 创建一个新的 Remix 项目:
pnpm dlx create-remix@latest my-app
运行 CLI
运行 shadcn 初始化命令来设置你的项目:
pnpm dlx shadcn@latest init
配置 components.json
系统将询问你一些问题来配置 components.json:
Which color would you like to use as base color? › Neutral应用结构
注意:此应用结构仅作为建议。你可以将文件放置在任何你想放的位置。
- 将 UI 组件放置在 app/components/ui文件夹中。
- 你自己的组件可以放在 app/components文件夹内。
- app/lib文件夹包含所有的工具函数。我们在- utils.ts中定义了- cn辅助函数。
- app/tailwind.css文件包含全局 CSS。
安装 Tailwind CSS
pnpm add -D tailwindcss@latest autoprefixer@latest
然后创建 postcss.config.js 文件:
export default {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
}最后,在 remix.config.js 文件中添加以下内容:
/** @type {import('@remix-run/dev').AppConfig} */
export default {
  ...
  tailwind: true,
  postcss: true,
  ...
};将 tailwind.css 添加到你的应用
在你的 app/root.tsx 文件中,导入 tailwind.css 文件:
import styles from "./tailwind.css?url"
 
export const links: LinksFunction = () => [
  { rel: "stylesheet", href: styles },
  ...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
]就这些了
现在你可以开始往你的项目中添加组件了。
pnpm dlx shadcn@latest add button
上面的命令会将 Button 组件添加到你的项目中。然后你可以这样导入它:
import { Button } from "~/components/ui/button"
 
export default function Home() {
  return (
    <div>
      <Button>Click me</Button>
    </div>
  )
}Deploy your shadcn/ui app on Vercel
Trusted by OpenAI, Sonos, Adobe, and more.
Vercel provides tools and infrastructure to deploy apps and features at scale.
Deploy to Vercel