GitHub

toggle

iOS-style switch that renders a visually hidden <input type="checkbox"> with a custom track and thumb. No JavaScript required — state is read from FormData on submission.

Default

toggle({ name: 'notifications', label: 'Email notifications' })
toggle({ name: 'updates',       label: 'Product updates', checked: true })

With hint

Use hint to add supporting text below the switch.

Receive tips, product news, and special offers.

A summary of activity sent every Monday morning.

toggle({
  name:    'marketing',
  label:   'Marketing emails',
  hint:    'Receive tips, product news, and special offers.',
})
toggle({
  name:    'digest',
  label:   'Weekly digest',
  hint:    'A summary of activity sent every Monday morning.',
  checked: true,
})

Disabled

toggle({ name: 'a', label: 'Off and disabled', disabled: true })
toggle({ name: 'b', label: 'On and disabled',  disabled: true, checked: true })

In forms

The switch submits as 'on' under its name when checked. When unchecked, the field is absent from FormData entirely — the same behaviour as a native checkbox. Read it with formData.get('name') === 'on'.
PropTypeDefault
namestringField name — submitted in FormData
labelstringVisible label text
checkedbooleanfalseInitial on/off state
disabledbooleanfalse
hintstringHelper text below the switch
idstringOverride the generated id
classstring