Pre-alphaThe registry and the CLI are not published yet.Roadmap

Switch

Themed toggle.

Settings

Notifications

Alerts
Allow notifications
Quiet hours
Email digestRequires a verified email

Quiet hours mute alerts from 22:00 to 07:00.

Sizes
Medium · small

Installation

npx axiom add switch
pnpm dlx axiom add switch
yarn dlx axiom add switch
bun x axiom add switch

Usage

import { Switch } from "@/components/ui/switch";

<Switch value={enabled} onValueChange={setEnabled} />;

Props

PropTypeDefaultDescription
valueboolean—Whether the switch is on. Use with onValueChange for a controlled switch.
defaultValuebooleanfalseInitial value when the switch manages its own state.
onValueChange(value: boolean) => void—Called with the new value when the user flips the switch.
disabledbooleanfalseBlocks changes and dims the switch with the disabled tokens.
hapticHapticKind | false'light'Haptic played when the user flips the switch. false turns it off.
size'sm' | 'md''md'md matches the iOS system switch (51×31pt), sm is 40×24pt for dense rows. The touch area stays 44pt.
accessibilityLabelstring—What the switch controls. Not needed when the switch sits in an OptionItem, which labels it.
styleStyleProp<ViewStyle>—Extra styles for the track.

Track and thumb colors come from switch.default.{default,checked,disabled}.{track,thumb} in the component tokens. The on/off logic and the thumb animation live in use-switch.ts, shared by every styling variant.

Haptics

The switch plays a light haptic when the user flips it, like the iOS system switch. A change of value made in code plays nothing. Pass haptic={false} to turn it off, or another kind to change it. Nothing plays until your app connects a haptics library: see Haptics.

Use cases

Settings that apply immediately

A switch means the change takes effect right away, with no Save button. Label the row, not the switch.

Privacy

Show online status
Read receipts
Share usage data

If you turn off read receipts, you won’t see them from others either.

<OptionItem
	label="Read receipts"
	trailing={
		<Switch
			value={settings.readReceipts}
			onValueChange={(v) => update({ readReceipts: v })}
		/>
	}
/>

Revealing dependent options

Turning the switch on shows the options that only make sense when the feature is on.

Downtime

Scheduled
From

22:00

To

07:00

Allowed
Calls from favorites
<Switch
	value={scheduled}
	onValueChange={setScheduled}
	accessibilityLabel="Scheduled downtime"
/>;
{
	scheduled && (
		<>
			<OptionItem
				label="From"
				trailing={<TimeValue value={from} />}
				onPress={pickFrom}
			/>
			<OptionItem
				label="To"
				trailing={<TimeValue value={to} />}
				onPress={pickTo}
			/>
		</>
	);
}

Pending server change

While the request runs, keep the new position and disable the switch. Revert it if the request fails.

Security

Two-factor authTurning on…
Couldn’t turn on two-factor auth.Retry
const [enabled, setEnabled] = useState(user.twoFactor);
const mutation = useMutation({
	mutationFn: setTwoFactor,
	onError: () => setEnabled((v) => !v),
});

<Switch
	value={enabled}
	disabled={mutation.isPending}
	onValueChange={(v) => {
		setEnabled(v);
		mutation.mutate(v);
	}}
/>;