Toggle
animate-ui/components-base-toggleFreeComponent
A two-state button that can be on or off.
Install it
npx shadcn@latest add https://animate-ui.com/r/components-base-toggle.jsonSource
1import * as React from 'react';2import { cva, type VariantProps } from 'class-variance-authority';34import {5 Toggle as TogglePrimitive,6 ToggleItem as ToggleItemPrimitive,7 ToggleHighlight as ToggleHighlightPrimitive,8 type ToggleProps as TogglePrimitiveProps,9 type ToggleItemProps as ToggleItemPrimitiveProps,10} from '@/components/animate-ui/primitives/base/toggle';11import { cn } from '@/lib/utils';1213const toggleVariants = cva(14 "inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium hover:bg-muted/40 hover:text-muted-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] outline-none transition-[color,background-color,box-shadow] duration-200 ease-in-out aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive whitespace-nowrap",15 {16 variants: {17 variant: {18 default: 'bg-transparent',19 outline:20 'border border-input bg-transparent shadow-xs hover:bg-accent/40 hover:text-accent-foreground',21 },22 size: {23 default: 'h-9 px-2 min-w-9',24 sm: 'h-8 px-1.5 min-w-8',25 lg: 'h-10 px-2.5 min-w-10',26 icon: 'size-9',27 },28 },29 defaultVariants: {30 variant: 'default',31 size: 'default',32 },33 },34);3536type ToggleProps = TogglePrimitiveProps &37 ToggleItemPrimitiveProps &38 VariantProps<typeof toggleVariants>;3940function Toggle({41 className,42 variant,43 size,44 pressed,45 defaultPressed,46 onPressedChange,47 disabled,48 ...props49}: ToggleProps) {50 return (51 <TogglePrimitive52 pressed={pressed}53 defaultPressed={defaultPressed}54 onPressedChange={onPressedChange}55 disabled={disabled}56 className="relative"57 >58 <ToggleHighlightPrimitive className="bg-accent rounded-md" />59 <ToggleItemPrimitive60 className={cn(toggleVariants({ variant, size, className }))}61 {...props}62 />63 </TogglePrimitive>64 );65}6667export { Toggle, toggleVariants, type ToggleProps };
What it pulls in
Other registry items
Files it writes
More from Animate UI
All 580 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Avatar Groupcomponents-animate-avatar-group | Animate UI | Components | Free | 1 dep | |
| Codecomponents-animate-code | Animate UI | Components | Free | 1 dep | |
| Code Tabscomponents-animate-code-tabs | Animate UI | Components | Free | 1 dep | |
| Cursorcomponents-animate-cursor | Animate UI | Components | Free | no deps | |
| GitHub Stars Wheelcomponents-animate-github-stars-wheel | Animate UI | Components | Free | 1 dep | |
| Tabscomponents-animate-tabs | Animate UI | Components | Free | no deps | |
| Tooltipcomponents-animate-tooltip | Animate UI | Components | Free | 1 dep | |
| Bubble Backgroundcomponents-backgrounds-bubble | Animate UI | Components | Free | 1 dep |
