Componentform0.58 KB gzipZero dependencies

Toggle

Two-state button with aria-pressed, springy press animation, and default/outline/accent variants.

Preview

Live Preview
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add toggle

Or install the full npm package:

npm install bigbullui

Usage

tsx3 lines
import { Toggle } from "@/components/ui/toggle"; <Toggle pressed={pressed} onPressedChange={setPressed} variant="outline">Bold</Toggle>

Source code

toggle.tsx + 1 helper

Zero third-party dependencies (2 local files shown in tabs below).

tsxtoggle.tsx67 lines
"use client"; import * as React from "react";import { cn } from "./lib/utils"; export type ToggleVariant = "default" | "outline" | "accent";export type ToggleSize = "sm" | "default" | "lg"; export type ToggleProps = Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "pressed" | "onPressedChange"> & {  pressed?: boolean;  defaultPressed?: boolean;  onPressedChange?: (pressed: boolean) => void;  variant?: ToggleVariant;  size?: ToggleSize;}; const variants: Record<ToggleVariant, string> = {  default: "bg-card border border-border",

Props

Interactive Prop Playground

Tweak parsed AST props below to generate ready-to-paste JSX.

tsx3 lines
import { Toggle } from "@/components/ui/toggle"; <Toggle />
PropTypeDescription
pressedbooleanControlled state.
defaultPressedbooleanUncontrolled initial state.
onPressedChange(pressed: boolean) => voidState change handler.
variantToggleVariantVisual style.
sizeToggleSizeSize preset.