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={4}>
<Text>Bluetooth</Text>
<Switch size="sm" />
</HStack>;
};
const Example = () => {
return <VStack space={4} alignItems="center">
<Heading mb="10">Sizes</Heading>
<Switch size="sm" />
<Switch size="md" />
<Switch size="lg" />
</VStack>;
};
const Example = () => {
return <VStack space={4} alignItems="center">
<Heading textAlign="center" mb="10">
Track & Thumb color
</Heading>
<Switch />
<Switch offTrackColor="orange.100" onTrackColor="orange.200" onThumbColor="orange.500" offThumbColor="orange.50" />
<Switch offTrackColor="indigo.100" onTrackColor="indigo.200" onThumbColor="indigo.500" offThumbColor="indigo.50" />
</VStack>;
};
const Example = () => {
return <VStack space={4} alignItems="center">
<Heading textAlign="center" mb="10">
Color Scheme
</Heading>
<Switch defaultIsChecked colorScheme="primary" />
<Switch defaultIsChecked colorScheme="secondary" />
<Switch defaultIsChecked colorScheme="emerald" />
</VStack>;
};
Switch implements
,
,
,
,
,
,
,
,
,
The size (width and height) of the switch.
Type: ResponsiveValue<number | "px" | "0" | (string & {}) | "full" | "sm" | "6" | "2xs" | "8" | "xs" | "12" | "md" | "16" | "xl" | "24" | "32" | "2" | "0.5" | "4" | "3" | "lg" | "1" | "2xl" | "container" | ... 30 more ... | "5/6">
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.
Type: ResponsiveValue<(string & {}) | "gray.300" | "trueGray.400" | "gray.500" | "contrastThreshold" | "white" | "black" | "lightText" | "darkText" | "coolGray.50" | "coolGray.100" | "coolGray.200" | ... 233 more ... | "dark.900">
The track color of the Switch when off.
Type: ResponsiveValue<(string & {}) | "gray.300" | "trueGray.400" | "gray.500" | "contrastThreshold" | "white" | "black" | "lightText" | "darkText" | "coolGray.50" | "coolGray.100" | "coolGray.200" | ... 233 more ... | "dark.900">
The thumb color of the Switch when on.
Type: ResponsiveValue<(string & {}) | "gray.300" | "trueGray.400" | "gray.500" | "contrastThreshold" | "white" | "black" | "lightText" | "darkText" | "coolGray.50" | "coolGray.100" | "coolGray.200" | ... 233 more ... | "dark.900">
The thumb color of the Switch when off.
Type: ResponsiveValue<(string & {}) | "gray.300" | "trueGray.400" | "gray.500" | "contrastThreshold" | "white" | "black" | "lightText" | "darkText" | "coolGray.50" | "coolGray.100" | "coolGray.200" | ... 233 more ... | "dark.900">
Color scheme to be used for the Switch
Props when Switch is hovered. Accepts all the Switch props.
Type: Omit<ISwitchProps, "_hover">
On mobile, uses native switch which is fully accessible.
On web, it uses checkbox with a
set to
switch.
Toggles the component's state.