suiss/ui · Component
Toggle
A two-state button that stays pressed until it's pressed again.
Toggle is an open-source component from suiss/ui for React, React Native, SwiftUI and Jetpack Compose. The @esuiss/ui CLI copies its source into your project, so you own the code.
Toggle wraps the toggle primitive of the chosen base. When pressed, it shows a tinted background and primary-colored content, and it scales down slightly while being pressed.
Use a toggle for a single on-off option such as bold text or a bookmark. To choose among related options, use ToggleGroup; for a setting that takes effect immediately, use Switch.
Installation
CLI
Works in any project with a components.json. See Installation for the one-line registry setup. Or use the suiss/ui CLI:
Manual
- Install the dependencies and add the
cnhelper:
- Copy the source into
components/ui/toggle.tsx:
- Update the import paths to match your project.
Usage
Use defaultPressed for an uncontrolled toggle, or pressed with onPressedChange to control it. Mark an icon beside a label with data-icon="inline-start" or data-icon="inline-end" to tighten the padding on that side.
Examples
Pressed
Starts in the pressed state.
Variants
Compares the default and outline variants.
Sizes
Compares the sm, default and lg sizes.
With text
Pairs an icon with a text label.
Disabled
Disables the toggle so it ignores clicks.
API Reference
Toggle
The pressable two-state button.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "outline" | "default" | Uses a borderless default style or an outline style with a border. |
size | "default" | "sm" | "lg" | "default" | Sets the height and padding: sm, default or lg. |
Also accepts the props of the primitive part it wraps.
Accessibility
- Renders a
buttonwitharia-pressedreflecting its state. EnterandSpacetoggle the focused button.- An icon-only toggle needs an
aria-label.
Notes
- Uses
data-slot="toggle". Pressed styles key offaria-pressed. toggleVariantsis exported so other components, such asToggleGroupItem, can share the styles.- The press animation is removed when reduced motion is preferred.

Toggle is a Pressable with an on and off state. When on, it shows a selected background and its text turns to the primary color; it scales down slightly while pressed. It has two variants, default and outline, and three sizes.
ToggleIcon is an Icon sized for use inside a toggle.
Installation
The CLI also adds what it builds on: Icon, Text.
Manual
-
Target iOS 17 or later.
-
Add the Swift package to your app:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Add the files to your app target.
- Set
minSdkto 24 or higher and add the dependencies:
- Copy the theme files every view uses:
- Copy the source and every file it uses:
- Update the
com.esuiss.uipackage names to match your project.
Usage
Control the state with pressed and onPressedChange(pressed, details), or leave it uncontrolled with defaultPressed. Put text in a Text and icons in ToggleIcon.
Icon-only toggles need an accessibilityLabel. To group toggles with single or multiple selection, use Toggle Group. toggleVariants, toggleStateClassName and toggleTextClassName are exported for reuse in custom components.
Examples
Pressed
An icon toggle that starts in the on state.

Variants
The default and outline variants.

Sizes
Outline toggles in the sm, default and lg sizes.

With text
An outline toggle with an icon and a text label.

Disabled
Disabled toggles in the off and on states.

API Reference
Toggle
The pressable two-state button.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "outline" | "default" | Visual style: default or outline. |
size | "default" | "sm" | "lg" | "default" | Height and padding: default, sm or lg. |
Also accepts the props of React.ComponentProps<typeof TogglePrimitive>.
ToggleIcon
An icon sized for a toggle.
Also accepts the props of React.ComponentProps<typeof Icon>.
Accessibility
- Uses the
togglebuttonrole and reportscheckedanddisabledinaccessibilityState. - Inside a single-select Toggle Group, it uses the
radiorole instead. - Icon-only toggles need an
accessibilityLabel.
Notes
- Changing the state triggers a selection haptic when a haptics adapter is provided through
HapticsContext. - Uses the
bg-accent,text-primaryandborder-bordertokens, withopacity-80while pressed andopacity-50when disabled. - Light and dark colors follow the system appearance.





