The Switch component is an alternative to the Checkbox component. You can switch between enabled or disabled states.
const Example = () => {
return <HStack alignItems="center" space={8}>
<Text fontSize="lg">Setting 1</Text>
<Switch />
</HStack>;
};
const Example = () => {
return <VStack space={4} alignItems="center">
<Heading>Switch Sizes</Heading>
<Switch size="sm" />
<Switch size="md" />
<Switch size="lg" />
</VStack>;
};
const Example = () => {
return <VStack space={4} alignItems="center">
<Heading>Switch Track & Thumb Color</Heading>
<Switch />
<Switch offTrackColor="rose.200" onTrackColor="lime.200" />
<Switch offThumbColor="rose.200" onThumbColor="lime.200" />
</VStack>;
};
const Example = () => {
return <VStack space={4} alignItems="center">
<Heading>Switch ColorScheme</Heading>
<Switch colorScheme="primary" />
<Switch colorScheme="secondary" />
<Switch colorScheme="emerald" />
</VStack>;
};
Switch implements
,
,
,
,
,
,
,
,
,
,
The size (width and height) of the switch.
If true, set the disabled to the invalid state.
The input name of the Switch when used in a form.
Function called when the state of the Switch changes.
If true, set the Switch to the checked state.
If true, the checkbox will be initially checked.
If true, set the switch to the invalid state.
The track color of the Switch when on.
The track color of the Switch when off.
The thumb color of the Switch when on.
The thumb color of the Switch when off.
Color scheme to be used for the Switch
Props when Switch is hovered. Accepts all the Switch props.
On mobile, uses native switch which is fully accessible.
On web, it uses checkbox with a
set to
switch.
Toggles the component's state.