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: ThemeComponentSizeType<"Switch">
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.
Type: (...args: any) => void
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" | "muted.50" | "muted.800" | "text.500" | "text.400" | "muted.500" | "text.900" | "muted.200" | "muted.300" | "muted.400" | "text.50" | "text.600" | "muted.700" | ... 342 more ... | "tertiary.900">
The track color of the Switch when off.
Type: ResponsiveValue<"gray.300" | "muted.50" | "muted.800" | "text.500" | "text.400" | "muted.500" | "text.900" | "muted.200" | "muted.300" | "muted.400" | "text.50" | "text.600" | "muted.700" | ... 342 more ... | "tertiary.900">
The thumb color of the Switch when on.
Type: ResponsiveValue<"gray.300" | "muted.50" | "muted.800" | "text.500" | "text.400" | "muted.500" | "text.900" | "muted.200" | "muted.300" | "muted.400" | "text.50" | "text.600" | "muted.700" | ... 342 more ... | "tertiary.900">
The thumb color of the Switch when off.
Type: ResponsiveValue<"gray.300" | "muted.50" | "muted.800" | "text.500" | "text.400" | "muted.500" | "text.900" | "muted.200" | "muted.300" | "muted.400" | "text.50" | "text.600" | "muted.700" | ... 342 more ... | "tertiary.900">
Color scheme to be used for the Switch
Props when Switch is hovered. Accepts all the Switch props.
Type: Omit<Partial<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.