Toggle

An on and off switch with a sliding knob. Works with a click, a tap or the space bar.

Options

Size
Colour

Code

import "./toggle.css";

export function Toggle({ checked, onChange, label }) {
  return (
    <button
      className="dh-toggle"
      type="button"
      role="switch"
      aria-checked={checked}
      aria-label={label}
      onClick={() => onChange(!checked)}
    >
      <span />
    </button>
  );
}