Align items
Learn MoreInstallation
CLI
npx shadcn@latest add "https://eo-n.vercel.app/r/toolbar"
Manual
Copy and paste the following code into your project.
"use client";
import * as React from "react";
import { Toolbar as ToolbarPrimitive } from "@base-ui-components/react/toolbar";
import { cn } from "@/lib/utils";
function Toolbar({
className,
...props
}: React.ComponentProps<typeof ToolbarPrimitive.Root>) {
return (
<ToolbarPrimitive.Root
data-slot="toolbar"
className={cn(
"flex w-fit items-center gap-1 overflow-hidden rounded-lg border p-1",
className
)}
{...props}
/>
);
}
function ToolbarButton({
className,
...props
}: React.ComponentProps<typeof ToolbarPrimitive.Button>) {
return (
<ToolbarPrimitive.Button
data-slot="toolbar-button"
className={cn(
"focus-visible:border-ring focus-visible:ring-ring/50 inline-flex h-9 shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap outline-none focus-visible:ring-[3px] data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
/>
);
}
function ToolbarLink({
className,
...props
}: React.ComponentProps<typeof ToolbarPrimitive.Link>) {
return (
<ToolbarPrimitive.Link
data-slot="toolbar-link"
className={cn(
"text-primary focus-visible:border-ring focus-visible:ring-ring/50 inline-flex h-9 shrink-0 cursor-pointer items-center justify-center gap-1 rounded-md px-4 text-xs underline-offset-4 transition-[color] outline-none hover:underline focus-visible:ring-[3px] [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-3.5",
className
)}
{...props}
/>
);
}
function ToolbarInput({
className,
...props
}: React.ComponentProps<typeof ToolbarPrimitive.Input>) {
return (
<ToolbarPrimitive.Input
data-slot="toolbar-input"
className={cn(
"data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
className
)}
{...props}
/>
);
}
function ToolbarGroup({
className,
...props
}: React.ComponentProps<typeof ToolbarPrimitive.Group>) {
return (
<ToolbarPrimitive.Group
data-slot="toolbar-group"
className={cn("flex items-center gap-1", className)}
{...props}
/>
);
}
function ToolbarSeparator({
className,
...props
}: React.ComponentProps<typeof ToolbarPrimitive.Separator>) {
return (
<ToolbarPrimitive.Separator
data-slot="toolbar-separator"
className={cn("bg-border h-8 w-px shrink-0", className)}
{...props}
/>
);
}
export {
Toolbar,
ToolbarButton,
ToolbarLink,
ToolbarInput,
ToolbarGroup,
ToolbarSeparator,
};
Update the import paths to match your project setup.
Usage
Import all parts and piece them together.
import {
Toolbar,
ToolbarButton,
ToolbarGroup,
ToolbarSeparator,
} from "@/components/ui/toolbar";
<Toolbar>
<ToolbarButton />
<ToolbarSeparator />
<ToolbarGroup>
<ToolbarButton />
</ToolbarGroup>
</Toolbar>