MiHCM
primitives/@mihcm/ui·v0.21.0·stable

Switch

Controlled on/off toggle. role="switch" with aria-checked driven by checked.

Switch

A binary on/off toggle for settings that take effect immediately.

When to use

  • Settings toggles — enable notifications, dark mode, feature flags.
  • Preferences — any boolean preference that applies instantly.

When NOT to use

  • For form fields that are submitted later — use Checkbox.
  • For choosing between multiple options — use radio buttons.

Import

import { Switch } from '@mihcm/ui/Switch';
import { Label } from '@mihcm/ui/Label';

Basic usage

const [enabled, setEnabled] = useState(false);
 
<div className="flex items-center gap-2">
  <Switch id="notifications" checked={enabled} onCheckedChange={setEnabled} />
  <Label htmlFor="notifications">Enable notifications</Label>
</div>

Switch is controlled-only. Pass checked and onCheckedChange from your state.

Sizes

SizeTrack heightUse when
sm20pxDense settings panels.
md24pxDefault for most UIs.
lg28pxTouch-friendly mobile settings.

Tones

ToneUse when
accentDefault. MiHCM orange in the on state.
primaryMiHCM navy. When the toggle reads as a primary action.

Composition

  • Always pair with a Label — clicking the label toggles the switch.
  • Switch applies changes immediately (no submit button needed). For deferred changes, use Checkbox.
  • disabled prevents toggling and applies reduced opacity.
  • On native, renders a Switch component with accessibilityRole="switch".
  • Checkbox — for form fields submitted later.
  • Toggle — button-style toggle.
  • Label — always pair with Switch.