Toggle

A button that can be switched between on and off states

Installation#

npmpnpmyarnbun
npx sugarcoat add toggle

Examples#

Default#

Default

Controlled#

Use pressed and onPressedChange for controlled state.

Controlled

Sizes#

Available in multiple sizes.

Sizes

Colors#

Toggle supports different color variants.

Colors

Variants#

Different visual styles for toggles.

Variants

With Icons#

Toggles work great with icons for toolbar-style buttons.

With Icons

Disabled#

Disabled

Usage#

Import
import { Toggle } from "@sugarcoat/ui-nxt";
Usage
<Toggle 
pressed={isPressed} 
onPressedChange={setIsPressed}
>
Toggle me
</Toggle>

Props#

PropTypeDefaultDescription
pressedboolean-Whether the toggle is pressed (controlled)
defaultPressedbooleanfalseInitial pressed state (uncontrolled)
onPressedChange(pressed: boolean) => void-Callback when pressed state changes
size"sm" | "md" | "lg""md"Size of the toggle button
color"default" | "primary" | "accent""default"Color variant
variant"outline" | "ghost" | "solid""outline"Visual style variant
disabledbooleanfalseWhether the toggle is disabled
cssSystemStyleObject-Additional CSS styles using Panda CSS syntax

Accessibility#

  • Built on Base UI Toggle for robust accessibility
  • Uses aria-pressed to communicate state to screen readers
  • Supports keyboard activation with Space and Enter keys
  • Focus visible styles included for keyboard users
  • Use aria-label when toggle only contains an icon
Customize Theme
Build your own sugarcoat/ui theme
PresetLime / Violet / Slate
Brand ColorLime
Accent ColorViolet
Gray ScaleSlate
Border RadiusLg