Skip to content
Application

Toolbar

Groups buttons, links, and toggles with arrow-key navigation.

MotionControls use Kineto’s button and toggle transitions.

Install

Install Kineto and follow the theme setup once in your app.

bash
npm install kineto
tsx
import {
  Toolbar,
  ToolbarButton,
  ToolbarLink,
  ToolbarSeparator,
  ToolbarToggleGroup,
  ToolbarToggleItem,
} from "kineto/toolbar";

Preview

tsx
"use client";

import * as React from "react";
import * as ToolbarPrimitive from "@radix-ui/react-toolbar";
import type { VariantProps } from "class-variance-authority";

import { buttonVariants } from "@/components/ui/button";
import { toggleVariants } from "@/components/ui/toggle";
import { cn } from "@/lib/cn";

const Toolbar = React.forwardRef<
  React.ElementRef<typeof ToolbarPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof ToolbarPrimitive.Root>
>(({ className, ...props }, ref) => (
  <ToolbarPrimitive.Root
    ref={ref}
    className={cn("flex items-center gap-1.5 data-[orientation=vertical]:flex-col", className)}
    {...props}
  />
));
Toolbar.displayName = "Toolbar";

export interface ToolbarButtonProps
  extends React.ComponentPropsWithoutRef<typeof ToolbarPrimitive.Button>,
    VariantProps<typeof buttonVariants> {}

const ToolbarButton = React.forwardRef<
  React.ElementRef<typeof ToolbarPrimitive.Button>,
  ToolbarButtonProps
>(({ className, variant = "ghost", size = "sm", ...props }, ref) => (
  <ToolbarPrimitive.Button
    ref={ref}
    className={cn(buttonVariants({ variant, size }), className)}
    {...props}
  />
));
ToolbarButton.displayName = "ToolbarButton";

const ToolbarLink = React.forwardRef<
  React.ElementRef<typeof ToolbarPrimitive.Link>,
  React.ComponentPropsWithoutRef<typeof ToolbarPrimitive.Link>
>(({ className, ...props }, ref) => (
  <ToolbarPrimitive.Link
    ref={ref}
    className={cn(buttonVariants({ variant: "link", size: "sm" }), className)}
    {...props}
  />
));
ToolbarLink.displayName = "ToolbarLink";

const ToolbarSeparator = React.forwardRef<
  React.ElementRef<typeof ToolbarPrimitive.Separator>,
  React.ComponentPropsWithoutRef<typeof ToolbarPrimitive.Separator>
>(({ className, ...props }, ref) => (
  <ToolbarPrimitive.Separator
    ref={ref}
    className={cn("shrink-0 bg-border data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-5 data-[orientation=vertical]:w-px", className)}
    {...props}
  />
));
ToolbarSeparator.displayName = "ToolbarSeparator";

const ToolbarToggleGroup = ToolbarPrimitive.ToggleGroup;

const ToolbarToggleItem = React.forwardRef<
  React.ElementRef<typeof ToolbarPrimitive.ToggleItem>,
  React.ComponentPropsWithoutRef<typeof ToolbarPrimitive.ToggleItem>
>(({ className, ...props }, ref) => (
  <ToolbarPrimitive.ToggleItem
    ref={ref}
    className={cn(toggleVariants({ size: "sm" }), className)}
    {...props}
  />
));
ToolbarToggleItem.displayName = "ToolbarToggleItem";

export { Toolbar, ToolbarButton, ToolbarLink, ToolbarSeparator, ToolbarToggleGroup, ToolbarToggleItem };

src/components/ui/toolbar.tsx

Props

PropTypeDefaultDescription
orientation"horizontal" | "vertical""horizontal"Sets layout and keyboard navigation direction.
loopbooleantrueWraps focus when arrow keys reach either end.
aria-labelstring—Names the toolbar for assistive technology.