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.











