Components
Toggle
A switch component that provides a visual toggle between two states. Built with Headless UI for accessibility and smooth animations.
Props
on
: boolean - The current state of the togglesetOn
: (on: boolean) => void - Function to update the toggle state
Usage Examples
Basic Toggle
With Label
In Form
With Description
Disabled State
Styling
The component uses Tailwind CSS for styling and includes:
- Smooth transitions
- Focus states
- Color variants
- Size consistency
- Dark mode support
- Disabled states
- Custom colors
Animation
The toggle includes smooth animations for:
- State changes
- Focus rings
- Hover effects
- Color transitions
Best Practices
-
Usage Guidelines:
- Use for boolean settings
- Provide clear labels
- Show immediate feedback
- Consider default states
-
Layout:
- Maintain consistent spacing
- Align with other controls
- Consider mobile touch targets
- Group related toggles
-
Accessibility:
- Include descriptive labels
- Support keyboard navigation
- Provide visual feedback
- Consider screen readers
Implementation Notes
- Built with @headlessui/react
- Maintains accessibility
- Handles keyboard events
- Supports customization
- Manages focus states
- Optimized transitions