Toggle

Spring switch. The knob stretches while pressed. Inputs.

Open playground

About

Toggle is a React component in the Inputs category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { Toggle } from "@ashutoshswamy/smoui" and set label, checked, defaultChecked among its 4 props.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { Toggle } from "@ashutoshswamy/smoui";

<Toggle label="Notifications" defaultChecked onChange={(on) => console.log(on)} />

Props 4

label

Accessible name.

string
checked

Controlled value.

boolean
defaultChecked

Initial value when uncontrolled.

booleandefault false
onChange

Called on toggle.

(checked: boolean) => void