Switch component is a customizable, animated toggle switch with iOS-style animations and interactions.
Import
Basic Usage
Props
The current state of the switch (on/off).
Callback function called when the switch is toggled. Receives the new value as an argument.
Fill color of the animated pill when expanded (visible when switch is OFF). Overrides variant color.
Track background color when pill is collapsed (visible when switch is ON). Overrides variant color.
The color of the thumb (circular part that slides). Overrides variant color.
Whether the switch is disabled. When disabled, the switch cannot be toggled and shows a disabled overlay.
The size preset for the switch. Each size has predefined dimensions:
mini: 38x20px with 16px thumbsmall: 48x26px with 22px thumbdefault: 56x30px with 26px thumblarge: 68x36px with 32px thumb
Predefined color variant for the switch. Available variants: Variant colors:
'primary', 'danger', 'warning', 'success', 'info'.primary: Blue (#2196F3)danger: Red (#E53935)warning: Orange (#FB8C00)success: Green (#43A047)info: Light Blue (#1E88E5)
Custom border color for the track (outer container).
Border width for the track in pixels.
Custom border color for the thumb (sliding circle).
Border width for the thumb in pixels.
Test identifier for automated testing.
Accessibility label for screen readers.
Accessibility hint providing additional context for screen readers.
Examples
Using Variants
Custom Colors
Different Sizes
With Borders
Disabled State
Accessibility
The Switch component includes built-in accessibility support:- Automatically sets
accessibilityRole="switch" - Provides
accessibilityStatewithdisabledandcheckedproperties - Supports custom
accessibilityLabelandaccessibilityHintprops - Keyboard and screen reader friendly