BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/Animate UI/components-base-toggle-group

Toggle Group

animate-ui/components-base-toggle-group
FreeComponent

Provides a shared state to a series of toggle buttons.

Install it

npx shadcn@latest add https://animate-ui.com/r/components-base-toggle-group.json

Source

registry/components/base/toggle-group/index.tsxanimate-ui.com/r/components-base-toggle-group.json
1import * as React from 'react';
2import { type VariantProps } from 'class-variance-authority';
3
4import {
5 ToggleGroup as ToggleGroupPrimitive,
6 Toggle as TogglePrimitive,
7 ToggleGroupHighlight as ToggleGroupHighlightPrimitive,
8 ToggleHighlight as ToggleHighlightPrimitive,
9 useToggleGroup as useToggleGroupPrimitive,
10 type ToggleGroupProps as ToggleGroupPrimitiveProps,
11 type ToggleProps as TogglePrimitiveProps,
12} from '@/components/animate-ui/primitives/base/toggle-group';
13import { toggleVariants } from '@/components/animate-ui/components/base/toggle';
14import { cn } from '@/lib/utils';
15import { getStrictContext } from '@/lib/get-strict-context';
16
17const [ToggleGroupProvider, useToggleGroup] =
18 getStrictContext<VariantProps<typeof toggleVariants>>('ToggleGroupContext');
19
20type ToggleGroupProps = ToggleGroupPrimitiveProps &
21 VariantProps<typeof toggleVariants>;
22
23function ToggleGroup({
24 className,
25 variant,
26 size,
27 children,
28 multiple,
29 ...props
30}: ToggleGroupProps) {
31 return (
32 <ToggleGroupPrimitive
33 data-variant={variant}
34 data-size={size}
35 className={cn(
36 'group/toggle-group flex gap-0.5 w-fit items-center rounded-lg data-[variant=outline]:shadow-xs data-[variant=outline]:border data-[variant=outline]:p-0.5',
37 className,
38 )}
39 multiple={multiple}
40 {...props}
41 >
42 <ToggleGroupProvider value={{ variant, size }}>
43 {!multiple ? (
44 <ToggleGroupHighlightPrimitive className="bg-accent rounded-md">
45 {children}
46 </ToggleGroupHighlightPrimitive>
47 ) : (
48 children
49 )}
50 </ToggleGroupProvider>
51 </ToggleGroupPrimitive>
52 );
53}
54
55type ToggleProps = TogglePrimitiveProps & VariantProps<typeof toggleVariants>;
56
57function Toggle({ className, children, variant, size, ...props }: ToggleProps) {
58 const { variant: contextVariant, size: contextSize } = useToggleGroup();
59 const { multiple } = useToggleGroupPrimitive();
60
61 return (
62 <ToggleHighlightPrimitive
63 value={props.value?.toString()}
64 className={cn(multiple && 'bg-accent rounded-md')}
65 >
66 <TogglePrimitive
67 data-variant={contextVariant || variant}
68 data-size={contextSize || size}
69 className={cn(
70 toggleVariants({
71 variant: contextVariant || variant,
72 size: contextSize || size,
73 }),
74 'min-w-0 border-0 flex-1 shrink-0 shadow-none rounded-md focus:z-10 focus-visible:z-10',
75 className,
76 )}
77// … truncated

What it pulls in

Other registry items

  • @animate-ui/primitives-base-toggle-group

Files it writes

  • registry/components/base/toggle-group/index.tsx

Facts

Registry
Animate UI
Type
registry:ui
Access
Free
Files written
1
Licence
the repository states none
First indexed
2026-08-02
Last confirmed
yesterday

Go to the source

animate-ui.com imskyleen/animate-ui on GitHub Raw registry item This item as JSON

More from Animate UI

All 580 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Avatar Groupcomponents-animate-avatar-groupAnimate UIComponentsFree1 dep
Codecomponents-animate-codeAnimate UIComponentsFree1 dep
Code Tabscomponents-animate-code-tabsAnimate UIComponentsFree1 dep
Cursorcomponents-animate-cursorAnimate UIComponentsFreeno deps
GitHub Stars Wheelcomponents-animate-github-stars-wheelAnimate UIComponentsFree1 dep
Tabscomponents-animate-tabsAnimate UIComponentsFreeno deps
Tooltipcomponents-animate-tooltipAnimate UIComponentsFree1 dep
Bubble Backgroundcomponents-backgrounds-bubbleAnimate UIComponentsFree1 dep
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex