Toggle Group (Base UI)
iconiq-ui/b-togglegroupFreeComponent
Segmented toggle group with the same fluid wipe fill, sheen sweep, and icon press feedback as the standalone toggle, over Base UI toggle-group primitives.
Live preview
live · rendered by the registry
Rendered by Iconiq UI on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.iconiqui.com/r/b-togglegroup.jsonSource
1"use client";23import { Toggle as TogglePrimitive } from "@base-ui/react/toggle";4import { ToggleGroup as ToggleGroupPrimitive } from "@base-ui/react/toggle-group";5import { cva, type VariantProps } from "class-variance-authority";6import { animate, motion, useMotionValue, useTransform } from "motion/react";7import * as React from "react";89import { cn } from "@/lib/utils";1011const toggleCornerClassName =12 "rounded-lg supports-[corner-shape:squircle]:corner-squircle supports-[corner-shape:squircle]:rounded-[11px]";1314const toggleCornerSmClassName =15 "rounded-[min(var(--radius-md),12px)] supports-[corner-shape:squircle]:corner-squircle supports-[corner-shape:squircle]:rounded-[14px]";1617const togglePressedTextBase =18 "text-muted-foreground aria-pressed:text-foreground data-pressed:text-foreground";1920const toggleFillClassName =21 "pointer-events-none absolute inset-0 z-0 rounded-[inherit] bg-muted supports-[corner-shape:squircle]:[corner-shape:inherit]";2223const ICON_REST = 0.93;2425const FLUID_FILL = {26 type: "spring" as const,27 stiffness: 210,28 damping: 28,29 mass: 1.08,30};31const FLUID_ICON = {32 type: "spring" as const,33 stiffness: 340,34 damping: 32,35 mass: 0.92,36};37const FLUID_TAP = {38 type: "spring" as const,39 stiffness: 520,40 damping: 34,41 mass: 0.72,42};43const FLUID_SNAP = {44 type: "spring" as const,45 duration: 0.45,46 bounce: 0.32,47};48const FLUID_SHEEN = {49 duration: 0.58,50 ease: [0.22, 1, 0.36, 1] as const,51};5253function runSheenSweep(54 sheenX: ReturnType<typeof useMotionValue<number>>,55 sheenOpacity: ReturnType<typeof useMotionValue<number>>56) {57 sheenX.set(-0.4);58 sheenOpacity.set(0.85);5960 animate(sheenX, 1.4, FLUID_SHEEN);61 animate(sheenOpacity, 0, {62 duration: 0.58,63 ease: [0.4, 0, 0.2, 1],64 });65}6667function resolveIsPressed({68 isPressed,69 "data-state": dataState,70 "data-pressed": dataPressed,71 "aria-pressed": ariaPressed,72}: {73 isPressed?: boolean;74 "data-state"?: string;75 "data-pressed"?: string | boolean;76 "aria-pressed"?: boolean | "true" | "false" | "mixed";77}) {78 if (isPressed !== undefined) {79 return isPressed;80 }8182 if (dataState === "on") {83 return true;84 }8586 if (dataState === "off") {87 return false;88 }8990 if (dataPressed === true || dataPressed === "true" || dataPressed === "") {91 return true;92 }9394 if (dataPressed === false || dataPressed === "false") {95 return false;96 }9798 if (ariaPressed === true || ariaPressed === "true") {99 return true;100 }101102// … truncated
What it pulls in
npm packages
Files it writes
More from Iconiq UI
All 119 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | Iconiq UI | Components | Free | 2 deps | |
| AI Inputai-input | Iconiq UI | Components | Free | 3 deps | |
| Alertalert | Iconiq UI | Components | Free | 2 deps | |
| Avataravatar | Iconiq UI | Components | Free | 3 deps | |
| Accordion (Base UI)b-accordion | Iconiq UI | Components | Free | 2 deps | |
| Alert Dialog (Base UI)b-alert-dialog | Iconiq UI | Components | Free | 3 deps | |
| Autocomplete (Base UI)b-autocomplete | Iconiq UI | Components | Free | 3 deps | |
| Avatar (Base UI)b-avatar | Iconiq UI | Components | Free | 2 deps |
