Components
- 手风琴
- 提示
- 警告对话框
- 宽高比
- 头像
- 徽章
- 面包屑导航
- 按钮
- 按钮组
- 日历 Calendar
- 卡片
- Carousel
- 图表 Chart
- 复选框
- 折叠面板
- 组合框
- 命令
- 上下文菜单
- 数据表格 Data Table
- 日期选择器 Date Picker
- 对话框 Dialog
- 方向
- 抽屉
- 下拉菜单
- Empty
- 字段
- 悬停卡片
- 输入
- 输入组
- 输入 OTP
- 项目
- Kbd
- 标签
- 菜单栏
- 原生选择框
- 导航菜单 Navigation Menu
- 分页
- 弹出框
- 进度 Progress
- 单选框组
- 可调整大小
- 滚动区域 Scroll Area
- 选择框
- 分隔符 Separator
- 侧边栏 Sheet
- 侧边栏 Sidebar
- 骨架屏
- 滑块
- Sonner
- 加载指示器 Spinner
- 开关
- 表格
- 标签页 Tabs
- 文本域
- 吐司
- 切换按钮 Toggle
- 切换组
- 提示 Tooltip
- 排版
开始新项目? 使用 shadcn/create 来获取一个完全配置好的 Vite 应用,包含自定义主题、Base UI 或 Radix 以及图标库。
创建项目
使用 --rtl 标志和 vite 模板创建新项目。
如果你已经使用 shadcn/create 创建了项目,可以跳过此步骤。
pnpm dlx shadcn@latest create --template vite --rtl
这将创建一个带有 rtl: true 标志的 components.json 文件。
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "base-nova",
"rtl": true
}添加 DirectionProvider
在你的 index.html 文件中,给 html 标签添加 dir="rtl" 和 lang="ar" 属性。将 lang="ar" 替换为你的目标语言。
<!doctype html>
<html lang="ar" dir="rtl">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>然后在你的 main.tsx 文件中,用带有 direction="rtl" 属性的 DirectionProvider 组件包裹你的应用:
import { StrictMode } from "react"
import { createRoot } from "react-dom/client"
import { DirectionProvider } from "@/components/ui/direction"
import App from "./App"
import "./index.css"
createRoot(document.getElementById("root")!).render(
<StrictMode>
<DirectionProvider direction="rtl">
<App />
</DirectionProvider>
</StrictMode>
)添加字体
为了获得最佳的 RTL 体验,我们推荐使用对你的目标语言有良好支持的字体。 Noto 是一个非常好的字体系列,它与 Inter 和 Geist 配合良好。
使用 Fontsource 安装字体:
pnpm add @fontsource-variable/noto-sans-arabic
在你的 index.css 文件中导入该字体:
@import "tailwindcss";
@import "tw-animate-css";
@import "shadcn/tailwind.css";
@import "@fontsource-variable/noto-sans-arabic";
@theme inline {
--font-sans: "Noto Sans Arabic Variable", sans-serif;
}对于其他语言,例如希伯来语,你可以使用 @fontsource-variable/noto-sans-hebrew。
添加组件
现在你已经准备好向项目中添加组件了。CLI 会帮你处理 RTL 支持。
pnpm dlx shadcn@latest add item