Tally UI
UI

Switch

A styled toggle switch with a sliding thumb, built on the Switch primitive.

Import

import { Switch } from '@tallyui/components';

Usage

<Switch checked={enabled} onCheckedChange={setEnabled} />

Switch is a pre-styled wrapper around Switch.Root and Switch.Thumb from @tallyui/primitives. The thumb slides between positions when toggled. See the Switch primitive for behavior and accessibility details.

Default Styling

PartStateClasses
TrackBaseinline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent
TrackOffbg-input
TrackOnbg-primary
TrackDisabledopacity-50 web:cursor-not-allowed
TrackFocus (web)ring-2 ring-ring ring-offset-2 ring-offset-background
ThumbBasepointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0
ThumbOfftranslate-x-0
ThumbOntranslate-x-5

Props

PropTypeDefaultDescription
checkedboolean---Controlled on/off state
defaultCheckedbooleanfalseInitial state (uncontrolled)
onCheckedChange(checked: boolean) => void---Called when state changes
disabledbooleanfalsePrevents interaction and applies opacity-50
classNamestring---Additional NativeWind classes for the track, merged via cn()

Plus all React Native PressableProps.

Examples

With a label

import { useState } from 'react';
import { View } from 'react-native';
import { Switch, Label, Text } from '@tallyui/components';

function NotificationsToggle() {
  const [enabled, setEnabled] = useState(false);

  return (
    <View className="flex-row items-center justify-between">
      <Label nativeID="notifications">
        <Text>Enable notifications</Text>
      </Label>
      <Switch checked={enabled} onCheckedChange={setEnabled} />
    </View>
  );
}

Disabled

<Switch disabled />
<Switch disabled checked />

Settings row pattern

<View className="flex-row items-center justify-between rounded-lg border border-border px-4 py-3">
  <VStack className="gap-0.5">
    <Text className="text-sm font-medium">Dark mode</Text>
    <Text className="text-xs text-muted-foreground">Use the dark theme across the app</Text>
  </VStack>
  <Switch checked={darkMode} onCheckedChange={setDarkMode} />
</View>

On this page