Toggle

A fully reusable, clean, and futuristic Toggle component inspired by premium operating systems. It features physics-based thumb animations, multiple visual variants, responsive sizes, and robust accessibility.

formclass-variance-authorityframer-motionlucide-react

Installation

$npx futureuikit add toggle

Import

import { Toggle } from "@/components/ui/toggle"
Layout Variant
Color Theme
Shape
Size
Spacing / Padding

Named Keys & Props

Pass these exact named keys as props on <Toggle />. Click any color pill to copy the prop.

colorDefault is "default"(Black & White)
variantVisual style
"solid""outline""ghost""glass""elevated""soft"
shapeCorner shape
"default""square""rounded""sharp"
spacingInner spacing
"default""2x""4x""6x""8x"
sizeComponent size
"default""sm""md""lg""xl"

Usage Example

A basic implementation example to get you started.

Example Implementation
import { Toggle } from"@/components/ui/toggle";
import { Check, X } from"lucide-react";

export default function Example() {
 return (
 <div className="flex flex-col gap-6">
 <Toggle 
 label="Enable Notifications"
 description="Receive updates on your account."
 variant="glass"
 />
 <Toggle 
 label="Auto Save"
 checkedIcon={<Check />} 
 uncheckedIcon={<X />} 
 defaultChecked 
 />
 </div>
 );
}

Features

Key capabilities and highlights.

Key Capabilities
  • ◆Built with Framer Motion for premium, physics-based thumb animations.
  • ◆Eight visual variants: Default, Soft, Elevated, Glass, Modern, Enterprise, Neon, and Scenic.
  • ◆Four sizes (sm, md, lg, xl) and four shapes (rounded, pill, squircle, square).
  • ◆Robust state support: Hover, Focus, Active, Disabled, Loading, and Read Only.
  • ◆Icon support: Seamlessly swap checked and unchecked icons with cross-fading.
  • ◆Scenic support: Automatically cross-fades checkedImage and uncheckedImage backgrounds.
  • ◆Fully accessible with proper ARIA roles, keyboard navigation, and focus rings.

Notes

Important implementation details to consider.

Implementation Details
  • ◆Overview: A premium Toggle component designed for modern, high-end interfaces. It uses Framer Motion for natural thumb interactions and CVA for extensive visual configuration.
  • ◆Installation: Run'npx futureuikit add toggle'to add the toggle component to your project.
  • ◆Usage: Import the component from'@/components/ui/toggle'and render it. Pass'label'or'description'props to automatically render an accessible label layout.
  • ◆Controlled Usage: Use the'checked'and'onCheckedChange'props to manage the toggle's state from a parent component.
  • ◆Uncontrolled Usage: Provide a'defaultChecked'prop to let the component manage its own internal state.
  • ◆Sizes: Adjust the component's scale by passing the'size'prop ('sm','md','lg','xl').
  • ◆Variants: Use the'variant'prop ('default','soft','elevated','glass','modern','enterprise','neon','scenic') to match your application's aesthetic.
  • ◆Shapes: Pass the'shape'prop ('rounded','pill','squircle','square') to control the corner radiuses of both the track and thumb.
  • ◆Accessibility: The toggle automatically implements standard ARIA attributes and keyboard controls. Always provide a'label'prop for screen readers.
  • ◆Best Practices: Use the'loading'prop during async operations to show a spinner. Avoid excessive'neon'variants in standard forms.
  • ◆API Reference: The component extends all standard HTMLButtonElement attributes. See the source file for the complete type definition.