Separator
A gently wandering pen rule, horizontal or vertical.
Ballpoint
Components drawn in blue ballpoint.
import { Separator } from "@/components/ui/separator";
export default function SeparatorDemo() {
return (
<div className="w-full max-w-sm">
<p className="text-lg font-bold">Ballpoint</p>
<p className="text-ink-3">Components drawn in blue ballpoint.</p>
<Separator className="my-4" seed="sep-h" />
<div className="flex h-6 items-center gap-4">
<span>Docs</span>
<Separator orientation="vertical" seed="sep-v1" />
<span>Components</span>
<Separator orientation="vertical" seed="sep-v2" />
<span>Source</span>
</div>
</div>
);
}Installation
pnpm dlx shadcn@latest add @ballpoint/ separator"use client";
import { useMemo } from "react";
import { cn } from "@/lib/utils";
import { Separator as SeparatorPrimitive } from "@base-ui/react/separator";
import { penStyle, useInkBox, useInkSeed, usePen, type Pen } from "@/hooks/use-ink-box";
import { inkClassName, InkSvg, Stroke } from "@/lib/ink";
import { ruleStroke, verticalStroke } from "@/lib/ink-sketch";
// Drawn long and stretched along its length only, so the line keeps its
// weight at any size and never needs redrawing as it resizes.
const LENGTH = 700;
/**
* A wandering pen rule. Give it children and they are written in the middle
* of a rule that runs both sides: the "or" between two ways to sign in.
*/
function Separator({ children, ...props }: SeparatorProps) {
if (!children) return <Rule {...props} />;
const { className, ...rule } = props;
return (
<div role="separator" aria-orientation="horizontal" className={cn("flex w-full items-center gap-3 text-sm text-ink-3", className)}>
<Rule {...rule} aria-hidden="true" role="presentation" className="flex-1" />
<span>{children}</span>
<Rule {...rule} aria-hidden="true" role="presentation" className="flex-1" delay={(rule.delay ?? 0) + 200} />
</div>
);
}
type SeparatorProps = SeparatorPrimitive.Props & Pick<Pen, "draw" | "weight" | "speed"> & { seed?: string | number; delay?: number };
function Rule({
className,
orientation = "horizontal",
seed,
delay = 0,
draw,
weight,
speed,
...props
}: SeparatorProps) {
const pen = usePen({ draw, weight, speed });
const s = useInkSeed(seed);
const [ref] = useInkBox([LENGTH, 4]);
const horizontal = orientation === "horizontal";
const d = useMemo(() => (horizontal ? ruleStroke(s, LENGTH) : verticalStroke(s, LENGTH)), [horizontal, s]);
const mode = pen.draw ?? "auto";
return (
<SeparatorPrimitive
data-slot="separator"
orientation={orientation}
className={inkClassName(
"relative shrink-0 text-ink-4 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:w-px data-[orientation=vertical]:self-stretch",
className,
)}
{...props}
>
<InkSvg
ref={ref}
pending={mode === "auto"}
box={horizontal ? [0, -1, LENGTH, 5] : [0, -1, 3, LENGTH + 2]}
stretch
className={horizontal ? "inset-x-0 -top-0.5 h-[5px] w-full" : "-left-[1px] inset-y-0 h-full w-[3px]"}
style={penStyle(pen)}
>
<Stroke d={d} draw={mode} delay={delay} duration={700} width={1.1} />
</InkSvg>
</SeparatorPrimitive>
);
}
export { Separator };Usage
import { Separator } from "@/components/ui/separator"
<Separator />
<Separator orientation="vertical" />Examples
Between sections
Rules that divide a settings page, with the danger zone last.
Account
Your name and email.
Notebooks
Where your pages live.
Danger zone
Delete everything. There is no undo.
import { Separator } from "@/components/ui/separator";
export default function SeparatorSections() {
return (
<div className="flex w-full max-w-md flex-col gap-5">
<section>
<h3 className="text-lg font-bold">Account</h3>
<p className="text-ink-3">Your name and email.</p>
</section>
<Separator seed="ss-1" />
<section>
<h3 className="text-lg font-bold">Notebooks</h3>
<p className="text-ink-3">Where your pages live.</p>
</section>
<Separator seed="ss-2" />
<section>
<h3 className="text-lg font-bold text-destructive">Danger zone</h3>
<p className="text-ink-3">Delete everything. There is no undo.</p>
</section>
</div>
);
}With a label
Write in the middle of a rule: the or between two ways in.
"use client";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Separator } from "@/components/ui/separator";
export default function SeparatorLabel() {
return (
<div className="flex w-full max-w-sm flex-col gap-5">
<Button variant="outline" seed="sl-google">
Continue with a pen name
</Button>
<Separator seed="sl-or">or</Separator>
<form className="flex flex-col gap-3" onSubmit={(event) => event.preventDefault()}>
<Input type="email" aria-label="Email" placeholder="you@example.com" seed="sl-email" />
<Button seed="sl-send">Email me a link</Button>
</form>
</div>
);
}In a toolbar
Vertical rules dividing groups of buttons.
import { Button } from "@/components/ui/button";
import { InkIcon } from "@/components/ui/ink-icons";
import { Separator } from "@/components/ui/separator";
export default function SeparatorToolbar() {
return (
<div role="toolbar" aria-label="Formatting" className="flex h-9 items-center gap-1">
<Button variant="ghost" size="icon-sm" seed="st-bold">
<InkIcon name="bold" />
<span className="sr-only">Bold</span>
</Button>
<Button variant="ghost" size="icon-sm" seed="st-italic">
<InkIcon name="italic" />
<span className="sr-only">Italic</span>
</Button>
<Button variant="ghost" size="icon-sm" seed="st-underline">
<InkIcon name="underline" />
<span className="sr-only">Underline</span>
</Button>
<Separator orientation="vertical" seed="st-a" className="mx-2" />
<Button variant="ghost" size="icon-sm" seed="st-left">
<InkIcon name="align-left" />
<span className="sr-only">Align left</span>
</Button>
<Button variant="ghost" size="icon-sm" seed="st-center">
<InkIcon name="align-center" />
<span className="sr-only">Align centre</span>
</Button>
<Separator orientation="vertical" seed="st-b" className="mx-2" />
<Button variant="ghost" size="icon-sm" seed="st-link">
<InkIcon name="link" />
<span className="sr-only">Link</span>
</Button>
</div>
);
}API reference
- orientationdefault
"horizontal" "horizontal" | "vertical"Which way the rule runs.
- delaydefault
0 numberms after the pen gets to it before the rule is drawn. Rising delays rule a list off one line after another.
- children
ReactNodeIf given, written in the middle of a rule that runs both sides of it. The wrapper is the separator for assistive technology.
- seed
string | numberPins the drawing.
Every other prop goes to Base UI's Separator.
Pen settings
The drawing also takes draw, weight and speed, as props or from the nearest InkProvider. What each one does.