跳至正文
获取 Pro
基础原语U.27

分割线

FreeRegistry
components/linyi/separator.tsx
@base-ui/reactclass-variance-authority
"use client";
 
import * as React from "react";
import { Separator as BaseSeparator } from "@base-ui/react/separator";
import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/cn";
 
export const separatorVariants = cva("shrink-0", {
variants: {
orientation: {
horizontal: "h-px w-full",
vertical: "w-px self-stretch min-h-[1em]",
},
tone: {
subtle: "bg-line",
strong: "bg-line-strong",
},
},
defaultVariants: {
orientation: "horizontal",
tone: "subtle",
},
});
 
export interface SeparatorProps
extends Omit<
React.ComponentPropsWithRef<typeof BaseSeparator>,
"className" | "orientation"
>,
VariantProps<typeof separatorVariants> {
className?: string;
label?: React.ReactNode;
}
 
export function Separator({
className,
orientation = "horizontal",
tone = "subtle",
label,
...props
}: SeparatorProps) {
const resolvedOrientation = orientation ?? "horizontal";
 
if (label && resolvedOrientation === "horizontal") {
return (
<div
role="separator"
aria-orientation="horizontal"
className={cn("flex w-full items-center gap-3", className)}
>
<span
aria-hidden="true"
className={cn(
"h-px flex-1",
tone === "strong" ? "bg-line-strong" : "bg-line"
)}
/>
<span className="shrink-0 text-[11px] text-fg-muted select-none">
{label}
</span>
<span
aria-hidden="true"
className={cn(
"h-px flex-1",
tone === "strong" ? "bg-line-strong" : "bg-line"
)}
/>
</div>
);
}
 
return (
<BaseSeparator
orientation={resolvedOrientation}
className={cn(
separatorVariants({ orientation: resolvedOrientation, tone }),
className
)}
{...props}
/>
);
}