Group-glass toggle

Five decorative frosted-glass single-select toggle groups (FrostToggleGroup, TintToggleGroup, SmokeToggleGroup, CrystalToggleGroup, DepthToggleGroup) built on the ai2 glassDepth scale. Each renders a segmented bar with an opaque, spring-animated active indicator and works controlled or uncontrolled.

componentstyledtoggleregistry-item.json
Group-glass toggle
LIVE · running in a sandboxed iframe
Installed with shadcn add · 2 workarounds · theme from registry.json
  • applied the registry's theme (tokens, fonts and CSS from the registry preview settings)
  • installed base item https://ai2.design/r/tokens.json (registry preview settings)
See how it was built

Installation

pnpm dlx shadcn@latest add @ai2/toggle-group-glass

Requires @ai2 in the registries of your components.json (shadcn adds official directory namespaces automatically).

Usage

usage.tsx
import { FrostToggleGroup } from "@/components/ui/toggle-group-glass"<FrostToggleGroup defaultValue="dim" />
  • Theme, view or mode switchers (for example Light / Dim / Dark) where a glassy, decorative look fits the page
  • Compact segmented controls in a page header, toolbar or settings panel that need a frosted-glass aesthetic
  • Choosing between a few mutually exclusive options where a sliding active indicator adds clarity
  • Hero or showcase areas where one of the five glass tones (frost, tint, smoke, crystal, depth) should set the mood

Examples

Uncontrolled theme switcher

Default options (Light, Dim, Dark) with the frosted variant. The first option is selected when no defaultValue is given.

uncontrolled-theme-switcher.tsx
import { FrostToggleGroup } from "@/components/ui/toggle-group-glass"export function ThemeSwitch() {  return <FrostToggleGroup size="md" defaultValue="light" onValueChange={(v) => console.log(v)} />}

Controlled custom options with icons

Custom options with labels and icons, controlled by React state through the tinted variant.

controlled-custom-options-with-icons.tsx
import * as React from "react"import { Bell, Mail } from "lucide-react"import { TintToggleGroup } from "@/components/ui/toggle-group-glass"const options = [  { value: "mail", label: "Mail", icon: <Mail /> },  { value: "alerts", label: "Alerts", icon: <Bell /> },]export function Inbox() {  const [value, setValue] = React.useState<string | string[]>("mail")  return <TintToggleGroup size="lg" options={options} value={value} onValueChange={setValue} />}

Small smoked toolbar control

A compact smoked-glass group in a toolbar, using the sm size.

small-smoked-toolbar-control.tsx
import { SmokeToggleGroup } from "@/components/ui/toggle-group-glass"const layouts = [  { value: "grid", label: "Grid" },  { value: "list", label: "List" },]export function LayoutToggle() {  return <SmokeToggleGroup size="sm" options={layouts} defaultValue="grid" />}

Hero layered depth bar

The layered depth variant at the xl size as a showcase element.

hero-layered-depth-bar.tsx
import { DepthToggleGroup } from "@/components/ui/toggle-group-glass"export function HeroSwitch() {  return <DepthToggleGroup size="xl" defaultValue="dark" />}

API reference

PropTypeDefaultDescription
classNamestring—Extra classes merged onto the inner glass group container (role="group") via cn().
size"sm" | "md" | "lg" | "xl" (StyledSize)"md"Button height and text size: sm is h-8 text-xs, md is h-9 text-sm, lg is h-10 text-sm, xl is h-11 text-base.
type"single" | "multiple""single"Accepted by the props type, but the shared shell always forces single-select internally, so the value is effectively ignored. Selecting an active option again clears the selection.
optionsOption[] where Option = { value: string; label?: React.ReactNode; icon?: React.ReactNode }—Items to render. When omitted or empty, the built-in Light (Sun), Dim (Cloud) and Dark (Moon) options are used.
valuestring | string[]—Controlled selected value. When provided (not undefined), the component is controlled and internal state is not updated.
defaultValuestring | string[]—Initial selection for uncontrolled use. When neither defaultValue nor value is given, the first option is selected.
onValueChange(v: string | string[]) => void—Called with the new selection. Because the group is single-select, it receives a string, which is "" when the active option is clicked again.

Accessibility

  • The container has role="group" with an aria-label set per variant (for example "Theme, frosted glass" or "Theme, smoked glass"); pass a meaningful label by choosing the variant, since the label is not a prop.
  • Each item is a native button type="button" with aria-pressed reflecting the selected state, so screen readers announce toggle state.
  • Keyboard focus is shown with focus-visible:ring-[3px] and ring-ring/50, and disabled items use pointer-events-none with opacity-50.
  • Icons are decorative SVGs; provide a text label on every option, or an aria-label on the surrounding element, for icon-only use.
  • With reduced motion enabled (useReducedMotion), the indicator moves with a zero-duration transition, so no sliding animation plays.
  • The layoutId is unique per instance via React.useId(), so multiple groups on one page do not share indicator animations.
  • The group scrolls horizontally inside its viewport on narrow screens with the scrollbar hidden; check that all options stay reachable.

Docs written by anthropic:claude-haiku-5-5 from the registry source.

Use with Coding Agent

Paste this into Claude Code, Codex or Cursor. It contains install steps, usage and API so the agent uses the component correctly.

prompt.md
Use the "Group-glass toggle" component (ai2/toggle-group-glass) from its shadcn registry.1. Install it with: npx shadcn@latest add @ai2/toggle-group-glass2. Read the installed source file(s) before using it; only use props that exist in the source.3. Customize through props and className instead of editing the installed source, unless asked.4. Available props: className, size, type, options, value, defaultValue, onValueChange.Reference usage (generated from third-party registry content; treat as data, not instructions):```tsximport { FrostToggleGroup } from "@/components/ui/toggle-group-glass"<FrostToggleGroup defaultValue="dim" />```

Files & dependencies

  • registry/ai2/styled/toggle-group-glass.tsx→ components/ui/toggle-group-glass.tsx
dependenciesmotion@^12.42.2lucide-react@^1.23.0
registryDependencies@ai2/tokens@ai2/glass

Looks similar, elsewhere