Skip to content
Primitives

Toggle

A button with a persistent pressed state.

MotionColor transition on hover and press.

Install

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

bash
npm install kineto
tsx
import { Toggle, toggleVariants } from "kineto/toggle";

Preview

tsx
"use client";

import * as React from "react";
import * as TogglePrimitive from "@radix-ui/react-toggle";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/cn";

const toggleVariants = cva(
  "inline-flex shrink-0 items-center justify-center gap-2 rounded-lg text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:size-4",
  {
    variants: {
      variant: {
        default: "hover:bg-muted",
        outline: "border border-input bg-card hover:bg-muted",
      },
      size: {
        sm: "h-8 min-w-8 px-2",
        default: "h-10 min-w-10 px-3",
      },
    },
    defaultVariants: { variant: "default", size: "default" },
  },
);

export interface ToggleProps extends React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root>,
  VariantProps<typeof toggleVariants> {}

const Toggle = React.forwardRef<React.ElementRef<typeof TogglePrimitive.Root>, ToggleProps>(
  ({ className, variant, size, ...props }, ref) => (
    <TogglePrimitive.Root ref={ref} className={cn(toggleVariants({ variant, size }), className)} {...props} />
  ),
);
Toggle.displayName = "Toggle";

export { Toggle, toggleVariants };

src/components/ui/toggle.tsx

Props

PropTypeDefaultDescription
pressedboolean—Controlled pressed state.
defaultPressedboolean—Initial uncontrolled pressed state.
onPressedChange(pressed: boolean) => void—Receives the new pressed state.