Black Friday is here 🔥 Get Wensity Pro for 20% less with

Toggle

A React toggle button and toggle group on Base UI in default, icon, outline, and soft styles, with a sliding segmented mode or multi select for toolbars.

Loading preview

Examples

Practical examples and common states for the same installable component.

Default

Standard pressable toggles for binary settings and actions.

examples/toggle-default.tsx
"use client";
import * as React from "react";
import { Toggle } from "@/components/wensity/toggle";
export function ToggleDefault() {
const [pressed, setPressed] = React.useState(false);
return (
<Toggle pressed={pressed} onPressedChange={setPressed}>
Notifications
</Toggle>
);
}

Icon

Compact icon-only toggles for editor and formatting toolbars.

examples/toggle-icon.tsx
"use client";
import * as React from "react";
import { IconBold, IconItalic, IconUnderline } from "@tabler/icons-react";
import { ToggleGroup, ToggleGroupItem } from "@/components/wensity/toggle";
export function ToggleIcon() {
const [format, setFormat] = React.useState<string[]>(["bold"]);
return (
<ToggleGroup
type="multiple"
value={format}
onValueChange={(next) => Array.isArray(next) && setFormat(next)}
variant="icon"
aria-label="Formatting toolbar"
>
<ToggleGroupItem value="bold" aria-label="Bold">
<IconBold stroke={2.1} />
</ToggleGroupItem>
<ToggleGroupItem value="italic" aria-label="Italic">
<IconItalic stroke={2.1} />
</ToggleGroupItem>
<ToggleGroupItem value="underline" aria-label="Underline">
<IconUnderline stroke={2.1} />
</ToggleGroupItem>
</ToggleGroup>
);
}

Outline

Bordered toggles for billing cycles, view modes, and segmented choices.

examples/toggle-outline.tsx
"use client";
import * as React from "react";
import { ToggleGroup, ToggleGroupItem } from "@/components/wensity/toggle";
export function ToggleOutline() {
const [billing, setBilling] = React.useState("annual");
return (
<ToggleGroup
type="single"
value={billing}
onValueChange={(next) => typeof next === "string" && setBilling(next)}
variant="outline"
aria-label="Billing cycle"
>
<ToggleGroupItem value="monthly">Monthly</ToggleGroupItem>
<ToggleGroupItem value="annual">Annual</ToggleGroupItem>
<ToggleGroupItem value="custom">Custom</ToggleGroupItem>
</ToggleGroup>
);
}

Soft

Subtle filled toggles for quiet dashboards and secondary toolbars.

examples/toggle-soft.tsx
"use client";
import * as React from "react";
import { IconLayoutGrid, IconList } from "@tabler/icons-react";
import { ToggleGroup, ToggleGroupItem } from "@/components/wensity/toggle";
export function ToggleSoft() {
const [view, setView] = React.useState("list");
return (
<ToggleGroup
type="single"
value={view}
onValueChange={(next) => typeof next === "string" && setView(next)}
variant="soft"
aria-label="View mode"
>
<ToggleGroupItem value="list">
<IconList stroke={2} />
List
</ToggleGroupItem>
<ToggleGroupItem value="grid">
<IconLayoutGrid stroke={2} />
Grid
</ToggleGroupItem>
</ToggleGroup>
);
}

Group - single

One active option with a gliding segment indicator.

examples/toggle-group-single.tsx
"use client";
import * as React from "react";
import { ToggleGroup, ToggleGroupItem } from "@/components/wensity/toggle";
export function ToggleGroupSingle() {
const [density, setDensity] = React.useState("comfortable");
return (
<ToggleGroup
type="single"
value={density}
onValueChange={(next) => typeof next === "string" && setDensity(next)}
aria-label="Table density"
>
<ToggleGroupItem value="compact">Compact</ToggleGroupItem>
<ToggleGroupItem value="comfortable">Comfortable</ToggleGroupItem>
<ToggleGroupItem value="spacious">Spacious</ToggleGroupItem>
</ToggleGroup>
);
}

Group - multiple

Independent toggles for filters and multi-select toolbars.

examples/toggle-group-multiple.tsx
"use client";
import * as React from "react";
import { ToggleGroup, ToggleGroupItem } from "@/components/wensity/toggle";
export function ToggleGroupMultiple() {
const [filters, setFilters] = React.useState(["pro", "animated"]);
return (
<ToggleGroup
type="multiple"
value={filters}
onValueChange={(next) => Array.isArray(next) && setFilters(next)}
variant="outline"
aria-label="Component filters"
>
<ToggleGroupItem value="free">Free</ToggleGroupItem>
<ToggleGroupItem value="pro">Pro</ToggleGroupItem>
<ToggleGroupItem value="animated">Animated</ToggleGroupItem>
<ToggleGroupItem value="forms">Forms</ToggleGroupItem>
</ToggleGroup>
);
}

Disabled

Disabled toggles stay readable without accepting input.

examples/toggle-disabled.tsx
import { Toggle, ToggleGroup, ToggleGroupItem } from "@/components/wensity/toggle";
export function ToggleDisabled() {
return (
<ToggleGroup type="single" defaultValue="left" disabled variant="outline">
<ToggleGroupItem value="left">Left</ToggleGroupItem>
<ToggleGroupItem value="right">Right</ToggleGroupItem>
</ToggleGroup>
);
}

Overview

Toggle is a React and Tailwind CSS toggle button and toggle group built on Base UI, in Next.js or any React app. A single Toggle holds a pressed state you can control with pressed and onPressedChange, in default, icon, outline, or soft styles. Wrap items in ToggleGroup with type single and it becomes a segmented control whose highlight slides to the chosen option, horizontally or vertically. Type multiple keeps independent states for toolbar formatting such as bold and italic. The slide is instant under reduced motion. In single mode onValueChange returns a string, and in multiple mode an array.

Installation

Run the following command

~/your-project
pnpm dlx wensity@latest add toggle

Usage

Import Toggle from @/components/wensity/toggle and render it anywhere in your React or Next.js app. The source lands in your own repo, so every prop, class and animation below is yours to edit.

app/example.tsx
import { Toggle, ToggleGroup, ToggleGroupItem } from "@/components/wensity/toggle";
export function ToggleDemo() {
return (
<ToggleGroup type="single" defaultValue="list" variant="soft">
<ToggleGroupItem value="list">List</ToggleGroupItem>
<ToggleGroupItem value="grid">Grid</ToggleGroupItem>
</ToggleGroup>
);
}

Props

PropTypeDefaultDescription
pressedboolean-Controlled pressed state.
defaultPressedbooleanfalseInitial state when the toggle is uncontrolled.
onPressedChange(pressed: boolean) => void-Called when the pressed state changes.
variant"default" | "icon" | "outline" | "soft""default"Visual treatment. icon renders a square icon-only button.
size"sm" | "md" | "lg""md"Control height and padding.
disabledboolean-Disables the toggle.
  • Animated Tabs component preview

    Animated Tabs

    A physical stack of photo cards shuffled to the front by clipped tabs, with a tight image inset and copy in the footer.

  • Gooey Floating Toolbar component preview

    Gooey Floating Toolbar

    Tools share one liquid panel. It pours out of the icon you click, stretches to the next one, then drains back in.

  • Subscription Tier Card component preview

    Subscription Tier Card

    Pricing cards with a monthly and annual toggle, prices that spring to new values, and a highlighted plan in a brand glow.

  • Gooey Dock component preview

    Gooey Dock

    A dock of icons in a solid pill. The active capsule stretches to the item you pick and flips its icon and label inside.