Separator(分隔线)
在视觉或语义上分隔内容。
loading
安装
bash
npx shadcn@latest add separator1
1. 安装以下依赖:
bash
npm install @base-ui/react1
2. 将以下代码复制并粘贴到你的项目中。
tsx
import { Separator as SeparatorPrimitive } from "@base-ui/react/separator"
import { cn } from "cn"
function Separator({
className,
orientation = "horizontal",
...props
}: SeparatorPrimitive.Props) {
return (
<SeparatorPrimitive
data-slot="separator"
orientation={orientation}
className={cn(
"shrink-0 bg-border data-horizontal:h-px data-horizontal:w-full data-vertical:w-px data-vertical:self-stretch",
className
)}
{...props}
/>
)
}
export { Separator }1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
3. 更新导入路径,使其与项目配置一致。
用法
tsx
import { Separator } from "@/components/ui/separator"1
tsx
<Separator />1
垂直
使用 orientation="vertical" 创建垂直分隔线。
loading
菜单
在带描述的菜单项之间显示垂直分隔线。
loading
列表
在列表项之间显示水平分隔线。
loading
RTL
要在 shadcn/ui 中启用 RTL 支持,请参阅 RTL 配置指南。
loading
API 参考
请参阅 Base UI Separator 文档。