The Switch provides an alternative to the Checkbox component. It also allows a user to switch between enabled or disabled states.
const Example = () => {
return <Switch size="lg" />;
};
const Example = () => {
return <HStack alignItems="center" space={4}>
<Text>Bluetooth</Text>
<Switch size="sm" />
</HStack>;
};
const Example = () => {
return <VStack space={4} alignItems="center">
<Switch size="sm" />
<Switch size="md" />
<Switch size="lg" />
</VStack>;
};
const Example = () => {
return <VStack space={4} alignItems="center">
<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">
<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 | "full" | "sm" | "6" | "2xs" | "8" | "xs" | "12" | "md" | "16" | "xl" | "24" | "32" | "2" | "0.5" | "4" | "3" | "lg" | "1" | "2xl" | "10" | "20" | "64" | "0" | "px" | (string & {}) | ... 28 more ... | "5/6">
If true, set the disabled to the invalid state.
If true, set the hovered 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<"gray.300" | "primary.500" | "gray.500" | (string & {}) | "contrastThreshold" | "white" | "black" | "lightText" | "darkText" | "primary.50" | "primary.100" | "primary.200" | ... 333 more ... | "tertiary.900">
The track color of the Switch when off.
Type: ResponsiveValue<"gray.300" | "primary.500" | "gray.500" | (string & {}) | "contrastThreshold" | "white" | "black" | "lightText" | "darkText" | "primary.50" | "primary.100" | "primary.200" | ... 333 more ... | "tertiary.900">
The thumb color of the Switch when on.
Type: ResponsiveValue<"gray.300" | "primary.500" | "gray.500" | (string & {}) | "contrastThreshold" | "white" | "black" | "lightText" | "darkText" | "primary.50" | "primary.100" | "primary.200" | ... 333 more ... | "tertiary.900">
The thumb color of the Switch when off.
Type: ResponsiveValue<"gray.300" | "primary.500" | "gray.500" | (string & {}) | "contrastThreshold" | "white" | "black" | "lightText" | "darkText" | "primary.50" | "primary.100" | "primary.200" | ... 333 more ... | "tertiary.900">
Color scheme to be used for the Switch
Props when Switch is hovered. Accepts all the Switch props.
Type: Omit<InterfaceSwitchProps, "_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.