Toggle Group
uiable/toggle-groupFreeComponent
Toggle Group component.
Live preview
live · rendered by the registry
Rendered by uiable on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://uiable.com/r/toggle-group.jsonSource
1"use client";23import { CSSProperties, createContext, useContext } from "react";45import { Toggle as TogglePrimitive } from "@base-ui/react/toggle";6import { ToggleGroup as ToggleGroupPrimitive } from "@base-ui/react/toggle-group";7import { type VariantProps } from "class-variance-authority";89import { cn } from "@/lib/utils";10import { toggleVariants } from "@/components/ui/toggle";1112const ToggleGroupContext = createContext<13 VariantProps<typeof toggleVariants> & {14 spacing?: number;15 orientation?: "horizontal" | "vertical";16 }17>({18 size: "default",19 variant: "default",20 spacing: 0,21 orientation: "horizontal"22});2324function ToggleGroup({25 className,26 variant,27 size,28 spacing = 0,29 orientation = "horizontal",30 children,31 ...props32}: ToggleGroupPrimitive.Props &33 VariantProps<typeof toggleVariants> & {34 spacing?: number;35 orientation?: "horizontal" | "vertical";36 }) {37 return (38 <ToggleGroupPrimitive39 data-slot="toggle-group"40 data-variant={variant}41 data-size={size}42 data-spacing={spacing}43 data-orientation={orientation}44 style={{ "--gap": spacing } as CSSProperties}45 className={cn(46 "group/toggle-group flex w-fit flex-row items-center gap-[--spacing(var(--gap))] rounded-lg data-vertical:flex-col data-vertical:items-stretch data-[size=sm]:rounded-[min(var(--radius),6px)]",47 className48 )}49 {...props}50 >51 <ToggleGroupContext.Provider52 value={{ variant, size, spacing, orientation }}53 >54 {children}55 </ToggleGroupContext.Provider>56 </ToggleGroupPrimitive>57 );58}5960function ToggleGroupItem({61 className,62 children,63 variant = "default",64 size = "default",65 ...props66}: TogglePrimitive.Props & VariantProps<typeof toggleVariants>) {67 const context = useContext(ToggleGroupContext);6869 return (70 <TogglePrimitive71 data-slot="toggle-group-item"72 data-variant={context.variant || variant}73 data-size={context.size || size}74 data-spacing={context.spacing}75 className={cn(76// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from uiable
All 730 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | uiable | Components | Free | 2 deps | |
| Alertalert | uiable | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | uiable | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | uiable | Components | Free | no deps | |
| Attachmentattachment | uiable | Components | Free | 2 deps | |
| Avataravatar | uiable | Components | Free | 1 dep | |
| Badgebadge | uiable | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | uiable | Components | Free | 2 deps |
