Skip to main content

Starwind UI v3.0 is now available! Migration guide

Installation

Usage

---
import { Toggle } from "@/components/starwind/toggle";
---
<Toggle variant="outline">Toggle</Toggle>

Variants

Sizes

Synced Groups

Use the syncGroup prop to keep multiple toggles in sync. When one toggle in the group is pressed, all toggles with the same syncGroup will mirror its state.

Event Handling

Whenever toggled, the Toggle root emits starwind:pressed-change. Read the next state from event.detail.pressed.

Toggle is currently: off

API Reference

Styled Component API

These props are added or materially changed by the installed styled component. Standard HTML attributes remain available through the inherited interfaces noted below. Expand a prop to see named type definitions and framework-specific imports. Follow the Primitive and Runtime links for lower-level behavior props.

Toggle

Inherits button attributes. Omits `aria-pressed`, `defaultPressed`, `disabled`, `onChange`, `type`, and `value`.

Contains the following additional props:

Prop Type Default Toggle details
defaultPressed boolean
Description
Sets the initial pressed state when the control is uncontrolled.
Classification
Primitive override
Primitive prop
toggle.Root.defaultPressed
nativeButton boolean
Description
Uses native button semantics for the interactive control.
Classification
Primitive override
Primitive prop
toggle.Root.nativeButton
size "sm" | "md" | "lg" "md"
Description
Selects the component's visual size.
Classification
Styled variant
variant "default" | "outline" "default"
Description
Selects the component's visual variant.
Classification
Styled variant

Primitive And Runtime API

Use these references when you need the lower-level behavior APIs behind Toggle.

Primitive API

Runtime API

Toggle primitive
createToggle from @starwind-ui/runtime/toggle

Changelog

View version history v2.0.1 5 releases

v2.0.1

  • Updated React Runtime state synchronization so canceled proposals stay uncommitted and accepted changes remain aligned.

v2.0.0

  • Rebuilt Toggle on Starwind Runtime for pressed state and pressed-change events.
  • See the Toggle Primitive for the underlying unstyled anatomy and behavior API.

v1.0.3

  • Refactor tailwind variants functions into separate variants.ts file

v1.0.1

  • Add starwind:init event listener to enable initialization of additional Toggles loaded after an initial page load, such as when using server islands

v1.0.0

  • Initial release with starwind v1.12.0