Separator
A separator is a thin line that groups content in lists and layouts. You can give vertical or horizontal orientation with height or width.
Preview
import { Separator } from "@/components/Separator";
import React from "react";
const Page = () => {
return (
<div className="space-y-1">
<h4 className="text-sm font-medium leading-none">separator</h4>
<p className="text-sm text-muted-foreground">
You can adjust the width, height by giving a style.
</p>
</div>
<Separator className="my-4" />
);
};
export default Page;
Examples
Horizontal separator
You can adjust the width, height by giving a style.
vertical separator
Install the following dependencies:
npm install @radix-ui/react-separator
Copy and paste the following code into your project.
"use client";
import * as React from "react";
import * as SeparatorPrimitive from "@radix-ui/react-separator";
import { cn } from "@/lib/utils";
const Separator = React.forwardRef<
React.ElementRef<typeof SeparatorPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
>(
(
{ className, orientation = "horizontal", decorative = true, ...props },
ref
) => (
<SeparatorPrimitive.Root
ref={ref}
decorative={decorative}
orientation={orientation}
className={cn(
"shrink-0 bg-gray-400",
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
className
)}
{...props}
/>
)
);
Separator.displayName = SeparatorPrimitive.Root.displayName;
export { Separator };