Tally UI
UI

Toggle

A two-state button that can be toggled on or off.

Import

import { Toggle, Text } from '@tallyui/components';

Usage

Toggle is a pressable that tracks a boolean pressed state. Wrap a Text (or Icon) inside it -- child text styling is handled automatically through TextClassContext.

<Toggle onPressedChange={(pressed) => console.log(pressed)}>
  <Text>Bold</Text>
</Toggle>

Variants

VariantClass
defaultbg-transparent
outlineborder border-input bg-transparent

Both variants apply bg-accent text-accent-foreground when pressed is true.

Sizes

SizeClass
defaulth-10 px-3
smh-9 px-2.5
lgh-11 px-5

Props

PropTypeDefaultDescription
variant'default' | 'outline''default'Visual style of the toggle
size'default' | 'sm' | 'lg''default'Controls height and padding
pressedbooleanControlled pressed state
defaultPressedbooleanUncontrolled initial pressed state
onPressedChange(pressed: boolean) => voidCalled when the pressed state changes
disabledbooleanfalseDisables the toggle
asChildbooleanfalseRenders as a Slot, merging props onto the child element
classNamestringAdditional NativeWind classes merged via cn()

Plus all React Native PressableProps.

TextClassContext

Toggle wraps its children in a TextClassContext.Provider so that Text, Icon, and Loader components rendered inside automatically pick up the correct font size for the current size variant. Text classes use text-sm font-medium across all variants.

Examples

Controlled toggle

const [bold, setBold] = useState(false);

<Toggle pressed={bold} onPressedChange={setBold}>
  <Text>B</Text>
</Toggle>

Outline variant

<Toggle variant="outline">
  <Text>Italic</Text>
</Toggle>

With an icon

import { Icon } from '@tallyui/components';
import { Bold } from 'lucide-react-native';

<Toggle pressed={bold} onPressedChange={setBold}>
  <Icon><Bold /></Icon>
</Toggle>

Different sizes

<Toggle size="sm"><Text>S</Text></Toggle>
<Toggle size="default"><Text>M</Text></Toggle>
<Toggle size="lg"><Text>L</Text></Toggle>

Disabled

<Toggle disabled>
  <Text>Off</Text>
</Toggle>

On this page