{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"css-toggle-switch-collection-with-15-styles-on-a-real-checkbox-sizes-disabled-and-rtl","type":"registry:block","title":"CSS Toggle Switch Collection with 15 Styles on a Real Checkbox, Sizes, Disabled and RTL","description":"Free CSS toggle switches in 15 styles, each a native checkbox with role=switch. Pick small, medium or large, try disabled and right to left, then copy the code.","dependencies":[],"files":[{"path":"components/we-inc/css-toggle-switch-collection-with-15-styles-on-a-real-checkbox-sizes-disabled-and-rtl.tsx","type":"registry:component","content":"import { createElement, useEffect, useId, useMemo, useRef, useState } from \"react\";\nimport type { ReactNode } from \"react\";\n\n/* ---------- one tree, two outputs ----------\n  Every piece is written once as a small tree of elements. The same tree renders the live\n  preview and the HTML you copy, so the code you take is the code you saw working.\n  \"&\" in a class, id or CSS rule is replaced with the piece's own class name. */\ntype Attrs = Record<string, string | boolean | undefined>;\ntype El = { t: string; a: Attrs; k: HNode[] };\ntype HNode = string | El;\ntype Kid = HNode | (HNode | null | undefined)[] | null | false | undefined;\n\nfunction h(t: string, a: Attrs = {}, ...k: Kid[]): El {\n  const kids: HNode[] = [];\n  for (const x of k) {\n    if (x === null || x === false || x === undefined) continue;\n    if (Array.isArray(x)) kids.push(...x.filter((y) => y !== null && y !== undefined));\n    else kids.push(x);\n  }\n  return { t, a, k: kids };\n}\n\nconst sc = (s: string, name: string) => s.replace(/&/g, name);\nconst esc = (s: string) => s.replace(/</g, \"&lt;\").replace(/>/g, \"&gt;\");\nconst SVG_SELF = new Set([\"path\", \"circle\", \"line\", \"rect\", \"polyline\"]);\n\nfunction attrStr(a: Attrs, name: string): string {\n  return Object.entries(a)\n    .filter(([, v]) => v !== undefined && v !== false)\n    .map(([k, v]) => (v === true ? ` ${k}` : ` ${k}=\"${sc(String(v), name)}\"`))\n    .join(\"\");\n}\n\nfunction toHtml(n: HNode, name: string, d = 0): string {\n  const pad = \"  \".repeat(d);\n  if (typeof n === \"string\") return pad + esc(n);\n  const open = `<${n.t}${attrStr(n.a, name)}`;\n  if (SVG_SELF.has(n.t)) return `${pad}${open} />`;\n  if (n.t === \"input\") return `${pad}${open}>`;\n  if (!n.k.length) return `${pad}${open}></${n.t}>`;\n  if (n.k.every((c) => typeof c === \"string\")) return `${pad}${open}>${n.k.map((c) => esc(c as string)).join(\"\")}</${n.t}>`;\n  return `${pad}${open}>\\n${n.k.map((c) => toHtml(c, name, d + 1)).join(\"\\n\")}\\n${pad}</${n.t}>`;\n}\n\nconst RMAP: Record<string, string> = {\n  class: \"className\",\n  for: \"htmlFor\",\n  tabindex: \"tabIndex\",\n  checked: \"defaultChecked\",\n  \"stroke-width\": \"strokeWidth\",\n  \"stroke-linecap\": \"strokeLinecap\",\n  \"stroke-linejoin\": \"strokeLinejoin\",\n};\n\nfunction toReact(n: HNode, name: string, key?: number): ReactNode {\n  if (typeof n === \"string\") return n;\n  const p: Record<string, unknown> = { key };\n  for (const [k, v] of Object.entries(n.a)) {\n    if (v === undefined || v === false) continue;\n    p[RMAP[k] ?? k] = v === true ? (k.startsWith(\"aria-\") || k.startsWith(\"data-\") ? \"\" : true) : sc(String(v), name);\n  }\n  return createElement(n.t, p, ...n.k.map((c, i) => toReact(c, name, i)));\n}\n\n/* ---------- copy helpers and shared UI ---------- */\nasync function copyText(text: string): Promise<boolean> {\n  try {\n    await navigator.clipboard.writeText(text);\n    return true;\n  } catch {\n    return false;\n  }\n}\n\nconst ICON_COPY = \"M9 9h11v11H9zM5 15H4V4h11v1\";\nconst ICON_CHECK = \"M5 12.5l4.5 4.5L19 7\";\nconst ICON_CODE = \"M8 7l-5 5 5 5M16 7l5 5-5 5\";\n\nfunction Svg({ d, className = \"h-4 w-4\" }: { d: string; className?: string }) {\n  return (\n    <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth={2} strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\" className={className}>\n      <path d={d} />\n    </svg>\n  );\n}\n\nconst FOCUS = \"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n\n/** A live piece with its own Show code and Copy buttons. */\nfunction Card({\n  id,\n  name,\n  note,\n  code,\n  copyLabel,\n  stage,\n  stageClass,\n  wide,\n  ring,\n  onAnnounce,\n}: {\n  id: string;\n  name: string;\n  note?: string;\n  code: string;\n  copyLabel: string;\n  stage: ReactNode;\n  stageClass: string;\n  wide?: boolean;\n  ring: string;\n  onAnnounce: (s: string) => void;\n}) {\n  const [open, setOpen] = useState(false);\n  const [copied, setCopied] = useState(false);\n  const timer = useRef<ReturnType<typeof setTimeout> | null>(null);\n  useEffect(() => () => {\n    if (timer.current) clearTimeout(timer.current);\n  }, []);\n  async function copy() {\n    const ok = await copyText(code);\n    if (!ok) setOpen(true);\n    setCopied(ok);\n    onAnnounce(ok ? `${name}: ${copyLabel} copied` : \"Copy was blocked, the code is shown so you can select it\");\n    if (timer.current) clearTimeout(timer.current);\n    timer.current = setTimeout(() => setCopied(false), 1600);\n  }\n  return (\n    <li className={`overflow-hidden rounded-2xl border border-stone-200 bg-white shadow-[0_1px_2px_rgba(22,24,29,0.04)] ${wide || open ? \"col-span-full\" : \"\"}`}>\n      <div className={stageClass}>{stage}</div>\n      <div className=\"flex flex-wrap items-center gap-2 border-t border-stone-200 px-3 py-2.5\">\n        <div className=\"min-w-[7.5rem] flex-1\">\n          <p className=\"text-[13px] font-semibold leading-snug text-stone-900\">{name}</p>\n          {note && <p className=\"text-[12px] leading-snug text-stone-600\">{note}</p>}\n        </div>\n        <button\n          type=\"button\"\n          aria-expanded={open}\n          aria-controls={`${id}-code`}\n          aria-label={`${open ? \"Hide\" : \"Show\"} code for ${name}`}\n          onClick={() => setOpen(!open)}\n          className={`grid h-10 w-10 shrink-0 place-items-center rounded-lg text-stone-600 transition-colors hover:bg-stone-100 hover:text-stone-900 ${FOCUS} ${ring}`}\n        >\n          <Svg d={ICON_CODE} />\n        </button>\n        <button\n          type=\"button\"\n          onClick={copy}\n          aria-label={`Copy ${copyLabel} for ${name}`}\n          className={`inline-flex h-10 shrink-0 items-center gap-1.5 rounded-lg px-3 text-[12.5px] font-semibold transition-colors ${FOCUS} ${ring} ${copied ? \"bg-emerald-700 text-white\" : \"bg-stone-100 text-stone-900 hover:bg-stone-200\"}`}\n        >\n          <Svg d={copied ? ICON_CHECK : ICON_COPY} className=\"h-3.5 w-3.5\" />\n          {copied ? \"Copied\" : \"Copy\"}\n        </button>\n      </div>\n      {open && (\n        <pre id={`${id}-code`} tabIndex={0} className=\"max-h-96 overflow-auto whitespace-pre-wrap break-words border-t border-stone-800 bg-[#111318] p-4 font-mono text-[11.5px] leading-[1.65] text-slate-200\">\n          <code>{code}</code>\n        </pre>\n      )}\n    </li>\n  );\n}\n\n/** The view switcher at the top of each collection. */\nfunction Views<T extends string>({ views, value, onChange, ring, label }: { views: [T, string, number?][]; value: T; onChange: (v: T) => void; ring: string; label: string }) {\n  return (\n    <div className=\"flex flex-wrap gap-1.5\" role=\"group\" aria-label={label}>\n      {views.map(([k, text, n]) => {\n        const on = value === k;\n        return (\n          <button\n            key={k}\n            type=\"button\"\n            aria-pressed={on}\n            onClick={() => onChange(k)}\n            className={`inline-flex min-h-[40px] items-center gap-1.5 whitespace-nowrap rounded-full px-4 text-[13px] font-medium transition-colors ${FOCUS} ${ring} ${on ? \"bg-[#16181d] text-white\" : \"bg-white text-stone-700 ring-1 ring-inset ring-stone-300 hover:bg-stone-100\"}`}\n          >\n            {text}\n            {n !== undefined && <span className={`font-mono text-[11px] ${on ? \"text-white/70\" : \"text-stone-500\"}`}>{n}</span>}\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n\n/** A block of source code with one Copy button, used for the React + Tailwind versions. */\nfunction CodeBlock({ code, label, ring, onAnnounce, id }: { code: string; label: string; ring: string; onAnnounce: (s: string) => void; id: string }) {\n  const [copied, setCopied] = useState(false);\n  const [show, setShow] = useState(true);\n  async function copy() {\n    const ok = await copyText(code);\n    setCopied(ok);\n    if (!ok) setShow(true);\n    onAnnounce(ok ? `${label} copied` : \"Copy was blocked, the code is shown so you can select it\");\n    setTimeout(() => setCopied(false), 1600);\n  }\n  return (\n    <div className=\"overflow-hidden rounded-2xl border border-stone-800 bg-[#111318]\">\n      <div className=\"flex items-center justify-between gap-2 border-b border-white/10 px-3 py-2\">\n        <p className=\"font-mono text-[12px] text-slate-300\">{label}</p>\n        <div className=\"flex gap-1.5\">\n          <button type=\"button\" aria-expanded={show} aria-controls={id} onClick={() => setShow(!show)} className={`h-10 rounded-lg px-3 text-[12.5px] font-semibold text-slate-200 hover:bg-white/10 ${FOCUS} ${ring} focus-visible:ring-offset-[#111318]`}>\n            {show ? \"Hide code\" : \"Show code\"}\n          </button>\n          <button type=\"button\" onClick={copy} className={`inline-flex h-10 items-center gap-1.5 rounded-lg px-3 text-[12.5px] font-semibold ${FOCUS} ${ring} focus-visible:ring-offset-[#111318] ${copied ? \"bg-emerald-600 text-white\" : \"bg-white/10 text-white hover:bg-white/20\"}`}>\n            <Svg d={copied ? ICON_CHECK : ICON_COPY} className=\"h-3.5 w-3.5\" />\n            {copied ? \"Copied\" : \"Copy\"}\n          </button>\n        </div>\n      </div>\n      {show && (\n        <pre id={id} tabIndex={0} className=\"max-h-[520px] overflow-auto p-4 font-mono text-[11.5px] leading-[1.65] text-slate-200\">\n          <code>{code}</code>\n        </pre>\n      )}\n    </div>\n  );\n}\n\nconst SECTION_FONT = { fontFamily: 'Inter, ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif' };\n\n/* ---------- toggle switches ----------\n  Every switch is a real <input type=\"checkbox\" role=\"switch\"> inside its label, so it submits\n  with a form, toggles with Space and is announced as a switch. The track and thumb are drawn\n  next to it and read the input's state through :checked, :focus-visible and :disabled. */\nconst BASE = `.& {\n  position: relative; display: inline-flex; align-items: center; gap: .75em;\n  min-height: 44px; color: #1c1917; cursor: pointer;\n  font: 500 SIZE/1.3 system-ui, sans-serif;\n  --dir: 1; --origin: left;\n}\n.&[dir=\"rtl\"], [dir=\"rtl\"] .& { --dir: -1; --origin: right; }\n.&__input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }\n.&__track { position: relative; flex: none; display: inline-block; box-sizing: border-box; transition: background-color .2s, border-color .2s, box-shadow .2s; }\n.&__thumb { position: absolute; box-sizing: border-box; transition: transform .22s cubic-bezier(.2, .7, .2, 1), background-color .2s, border-color .2s, width .2s, box-shadow .2s; }\n.&__input:focus-visible + .&__track { outline: 2px solid #2563eb; outline-offset: 3px; }\n.&__input:disabled + .&__track { opacity: .45; }\n.&__input:disabled ~ .&__text { color: #78716c; }\n@media (prefers-reduced-motion: reduce) {\n  .& *, .& *::before { transition-duration: .01ms !important; }\n}`;\n\nconst move = (em: string, extra = \"\") => `transform: translateX(calc(${em} * var(--dir)))${extra};`;\nconst ON = \".&__input:checked + .&__track\";\n\ntype Kind = \"plain\" | \"row\" | \"two\" | \"onoff\" | \"icon\" | \"rocker\";\ntype Sw = { name: string; cls: string; note: string; text: string; on: boolean; kind: Kind; css: string; desc?: string; aria?: string };\n\nconst SWITCHES: Sw[] = [\n  {\n    name: \"Classic\", cls: \"switch-classic\", note: \"Rounded track, white thumb\", text: \"Email alerts\", on: true, kind: \"plain\",\n    css: `.&__track { width: 2.75em; height: 1.5em; border-radius: 999px; background: #a8a29e; }\n.&__thumb { top: .1875em; inset-inline-start: .1875em; width: 1.125em; height: 1.125em; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }\n${ON} { background: #15803d; }\n${ON} .&__thumb { ${move(\"1.25em\")} }`,\n  },\n  {\n    name: \"Thin track\", cls: \"switch-thin\", note: \"Thumb larger than the track\", text: \"Sync over mobile data\", on: false, kind: \"plain\",\n    css: `.&__track { width: 2.25em; height: .875em; border-radius: 999px; background: #a8a29e; }\n.&__thumb { top: -.1875em; inset-inline-start: -.125em; width: 1.25em; height: 1.25em; border-radius: 50%; background: #fafaf9; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }\n${ON} { background: #93b4f5; }\n${ON} .&__thumb { background: #1d4ed8; ${move(\"1.25em\")} }`,\n  },\n  {\n    name: \"Square\", cls: \"switch-square\", note: \"Sharp corners for dense admin UI\", text: \"Maintenance mode\", on: false, kind: \"plain\",\n    css: `.&__track { width: 3em; height: 1.5em; border-radius: 3px; background: #57534e; }\n.&__thumb { top: .1875em; inset-inline-start: .1875em; width: 1.125em; height: 1.125em; border-radius: 2px; background: #fff; }\n${ON} { background: #b45309; }\n${ON} .&__thumb { ${move(\"1.5em\")} }`,\n  },\n  {\n    name: \"On and off text\", cls: \"switch-text\", note: \"Words inside the track\", text: \"Auto-renew\", on: true, kind: \"onoff\",\n    css: `.&__track { width: 3.5em; height: 1.625em; border-radius: 999px; background: #e7e5e4; box-shadow: inset 0 0 0 1px #d6d3d1; }\n.&__thumb { top: .1875em; inset-inline-start: .1875em; width: 1.25em; height: 1.25em; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }\n.&__on, .&__off { position: absolute; top: 50%; transform: translateY(-50%); font-size: .625em; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }\n.&__on { inset-inline-start: .8em; color: #fff; opacity: 0; }\n.&__off { inset-inline-end: .8em; color: #57534e; }\n${ON} { background: #0f766e; box-shadow: none; }\n${ON} .&__thumb { ${move(\"1.875em\")} }\n${ON} .&__on { opacity: 1; }\n${ON} .&__off { opacity: 0; }`,\n  },\n  {\n    name: \"Icon thumb\", cls: \"switch-icon\", note: \"Cross or tick inside the thumb\", text: \"Two-step sign-in\", on: true, kind: \"icon\",\n    css: `.&__track { width: 2.75em; height: 1.5em; border-radius: 999px; background: #78716c; }\n.&__thumb { top: .1875em; inset-inline-start: .1875em; display: grid; place-items: center; width: 1.125em; height: 1.125em; border-radius: 50%; background: #fff; color: #57534e; }\n.&__thumb svg { grid-area: 1 / 1; width: .75em; height: .75em; transition: opacity .2s; }\n.&__thumb svg + svg { opacity: 0; }\n${ON} { background: #15803d; }\n${ON} .&__thumb { color: #15803d; ${move(\"1.25em\")} }\n${ON} .&__thumb svg { opacity: 0; }\n${ON} .&__thumb svg + svg { opacity: 1; }`,\n  },\n  {\n    name: \"Outline\", cls: \"switch-outline\", note: \"Bordered track, thumb grows when on\", text: \"Show weekends\", on: false, kind: \"plain\",\n    css: `.&__track { width: 2.75em; height: 1.5em; border-radius: 999px; border: .125em solid #57534e; background: transparent; }\n.&__thumb { top: .1875em; inset-inline-start: .1875em; width: .875em; height: .875em; border-radius: 50%; background: #57534e; }\n${ON} { border-color: #4338ca; background: #eef2ff; }\n${ON} .&__thumb { background: #4338ca; ${move(\"1.25em\", \" scale(1.15)\")} }`,\n  },\n  {\n    name: \"Inset\", cls: \"switch-inset\", note: \"Recessed track, raised thumb\", text: \"Sound effects\", on: true, kind: \"plain\",\n    css: `.&__track { width: 3em; height: 1.625em; border-radius: 999px; background: #e7e5e4; box-shadow: inset 0 2px 4px rgba(0, 0, 0, .18), inset 0 0 0 1px rgba(0, 0, 0, .08); }\n.&__thumb { top: .1875em; inset-inline-start: .1875em; width: 1.25em; height: 1.25em; border-radius: 50%; background: linear-gradient(#fff, #f1f0ee); box-shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 6px rgba(0, 0, 0, .12); }\n${ON} { background: #0369a1; box-shadow: inset 0 2px 4px rgba(0, 0, 0, .3); }\n${ON} .&__thumb { ${move(\"1.375em\")} }`,\n  },\n  {\n    name: \"Settings row\", cls: \"switch-row\", note: \"Text and hint first, switch at the end\", text: \"Public profile\", desc: \"Anyone with the link can see your projects.\", on: true, kind: \"row\",\n    css: `.& { justify-content: space-between; gap: 1em; width: 100%; max-width: 21em; padding: .75em 1em; border: 1px solid #e7e5e4; border-radius: .75em; background: #fff; }\n.&__copy { display: grid; gap: .15em; }\n.&__desc { color: #57534e; font-size: .8125em; font-weight: 400; }\n.&:has(.&__input:disabled) .&__text { color: #78716c; }\n.&__track { width: 2.75em; height: 1.5em; border-radius: 999px; background: #a8a29e; }\n.&__thumb { top: .1875em; inset-inline-start: .1875em; width: 1.125em; height: 1.125em; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }\n${ON} { background: #16181d; }\n${ON} .&__thumb { ${move(\"1.25em\")} }`,\n  },\n  {\n    name: \"Day and night\", cls: \"switch-sky\", note: \"Sun thumb becomes a crescent\", text: \"Dark theme\", on: false, kind: \"plain\",\n    css: `.&__track { width: 3.25em; height: 1.75em; border-radius: 999px; background: linear-gradient(#38bdf8, #7dd3fc); }\n.&__thumb { top: .1875em; inset-inline-start: .1875em; width: 1.375em; height: 1.375em; border-radius: 50%; background: #fcd34d; box-shadow: 0 0 0 .2em rgba(253, 224, 71, .35); }\n${ON} { background: #1e293b; }\n${ON} .&__thumb { background: #e2e8f0; box-shadow: inset -.35em -.1em 0 0 #94a3b8; ${move(\"1.5em\")} }`,\n  },\n  {\n    name: \"Stretch\", cls: \"switch-stretch\", note: \"Thumb widens while pressed\", text: \"Location sharing\", on: true, kind: \"plain\",\n    css: `.&__track { width: 2.75em; height: 1.5em; border-radius: 999px; background: #a8a29e; }\n.&__thumb { top: .1875em; inset-inline-start: .1875em; width: 1.125em; height: 1.125em; border-radius: 999px; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }\n.&:active .&__thumb { width: 1.5em; }\n${ON} { background: #be123c; }\n${ON} .&__thumb { ${move(\"1.25em\")} }\n.&:active ${ON} .&__thumb { ${move(\".875em\")} }`,\n  },\n  {\n    name: \"Two options\", cls: \"switch-choice\", note: \"Both choices named, like a billing period\", text: \"\", aria: \"Yearly billing\", on: true, kind: \"two\",\n    css: `.&__track { width: 2.5em; height: 1.375em; border-radius: 999px; background: #16181d; }\n.&__thumb { top: .1875em; inset-inline-start: .1875em; width: 1em; height: 1em; border-radius: 50%; background: #fff; }\n${ON} .&__thumb { ${move(\"1.125em\")} }\n.&__a { order: -1; }\n.&__a, .&__b { color: #57534e; }\n.&__input:not(:checked) ~ .&__a, .&__input:checked ~ .&__b { color: #16181d; font-weight: 650; }`,\n  },\n  {\n    name: \"Compact\", cls: \"switch-compact\", note: \"Small, for tables and dense lists\", text: \"Compact rows\", on: true, kind: \"plain\",\n    css: `.& { font-size: .875em; }\n.&__track { width: 2em; height: 1.125em; border-radius: 999px; background: #a8a29e; }\n.&__thumb { top: .1875em; inset-inline-start: .1875em; width: .75em; height: .75em; border-radius: 50%; background: #fff; }\n${ON} { background: #4338ca; }\n${ON} .&__thumb { ${move(\".875em\")} }`,\n  },\n  {\n    name: \"Rocker\", cls: \"switch-rocker\", note: \"Panel with I and O marks\", text: \"Studio lights\", on: true, kind: \"rocker\",\n    css: `.&__track { display: inline-flex; width: 3.5em; height: 1.75em; padding: .125em; border-radius: .375em; background: #d6d3d1; box-shadow: inset 0 1px 2px rgba(0, 0, 0, .2); }\n.&__mark { flex: 1; display: grid; place-items: center; color: #44403c; font-size: .75em; font-weight: 700; }\n.&__thumb { top: .125em; inset-inline-start: .125em; width: 1.625em; height: 1.5em; border-radius: .25em; background: linear-gradient(#fff, #efedea); box-shadow: 0 1px 0 #a8a29e, 0 3px 6px rgba(0, 0, 0, .14); }\n${ON} { background: #1c1917; }\n${ON} .&__mark { color: #e7e5e4; }\n${ON} .&__thumb { ${move(\"1.625em\")} }`,\n  },\n  {\n    name: \"Line\", cls: \"switch-line\", note: \"Thin rule with a ringed dot\", text: \"Captions\", on: false, kind: \"plain\",\n    css: `.&__track { width: 2.5em; height: .25em; border-radius: 999px; background: #a8a29e; }\n.&__thumb { top: -.375em; inset-inline-start: 0; width: 1em; height: 1em; border-radius: 50%; border: .125em solid #57534e; background: #fff; }\n${ON} { background: #0f766e; }\n${ON} .&__thumb { border-color: #0f766e; background: #0f766e; ${move(\"1.5em\")} }`,\n  },\n  {\n    name: \"Fill sweep\", cls: \"switch-sweep\", note: \"Colour washes in behind the thumb\", text: \"Focus mode\", on: true, kind: \"plain\",\n    css: `.&__track { width: 2.75em; height: 1.5em; border-radius: 999px; overflow: hidden; background: #a8a29e; }\n.&__track::before { content: \"\"; position: absolute; inset: 0; background: #4338ca; transform: scaleX(0); transform-origin: var(--origin); transition: transform .3s cubic-bezier(.2, .7, .2, 1); }\n.&__thumb { z-index: 1; top: .1875em; inset-inline-start: .1875em; width: 1.125em; height: 1.125em; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }\n${ON}::before { transform: none; }\n${ON} .&__thumb { ${move(\"1.25em\")} }`,\n  },\n];\n\nconst ICON_X = () => h(\"svg\", { viewBox: \"0 0 12 12\", fill: \"none\", stroke: \"currentColor\", \"stroke-width\": \"2\", \"stroke-linecap\": \"round\" }, h(\"path\", { d: \"M3 3l6 6M9 3L3 9\" }));\nconst ICON_TICK = () => h(\"svg\", { viewBox: \"0 0 12 12\", fill: \"none\", stroke: \"currentColor\", \"stroke-width\": \"2\", \"stroke-linecap\": \"round\", \"stroke-linejoin\": \"round\" }, h(\"path\", { d: \"M2.5 6.5l2.5 2.5 4.5-6\" }));\n\ntype Opts = { disabled: boolean; rtl: boolean };\n\nfunction swTree(it: Sw, o: Opts): El {\n  const input = h(\"input\", {\n    class: \"&__input\",\n    id: \"&-input\",\n    type: \"checkbox\",\n    role: \"switch\",\n    checked: it.on || undefined,\n    disabled: o.disabled || undefined,\n    \"aria-label\": it.aria,\n    \"aria-describedby\": it.desc ? \"&-desc\" : undefined,\n  });\n  const trackKids =\n    it.kind === \"onoff\" ? [h(\"span\", { class: \"&__on\" }, \"On\"), h(\"span\", { class: \"&__off\" }, \"Off\")] : it.kind === \"rocker\" ? [h(\"span\", { class: \"&__mark\" }, \"O\"), h(\"span\", { class: \"&__mark\" }, \"I\")] : [];\n  const thumb = h(\"span\", { class: \"&__thumb\" }, it.kind === \"icon\" ? [ICON_X(), ICON_TICK()] : []);\n  const track = h(\"span\", { class: \"&__track\", \"aria-hidden\": \"true\" }, trackKids, thumb);\n  const root = { class: \"&\", for: \"&-input\", dir: o.rtl ? \"rtl\" : undefined };\n  if (it.kind === \"row\") return h(\"label\", root, h(\"span\", { class: \"&__copy\" }, h(\"span\", { class: \"&__text\" }, it.text), h(\"span\", { class: \"&__desc\", id: \"&-desc\" }, it.desc ?? \"\")), input, track);\n  if (it.kind === \"two\") return h(\"label\", root, input, track, h(\"span\", { class: \"&__a\" }, \"Monthly\"), h(\"span\", { class: \"&__b\" }, \"Yearly\"));\n  return h(\"label\", root, input, track, h(\"span\", { class: \"&__text\" }, it.text));\n}\n\nconst SIZES: [string, string, string][] = [\n  [\"sm\", \"Small\", \"14px\"],\n  [\"md\", \"Medium\", \"16px\"],\n  [\"lg\", \"Large\", \"20px\"],\n];\nconst cssOf = (it: Sw, size: string) => `${BASE}\\n${it.css}`.replace(/SIZE/g, size);\nconst codeOf = (it: Sw, o: Opts, size: string) => `<!-- ${it.name} switch -->\\n${toHtml(swTree(it, o), it.cls)}\\n\\n<style>\\n${sc(cssOf(it, size), it.cls)}\\n</style>\\n`;\n\n/* ---------- React + Tailwind version (the code below is this exact component) ---------- */\nconst SW_SIZES = {\n  sm: { track: \"h-5 w-9\", thumb: \"h-4 w-4\", on: \"translate-x-4 rtl:-translate-x-4\" },\n  md: { track: \"h-6 w-11\", thumb: \"h-5 w-5\", on: \"translate-x-5 rtl:-translate-x-5\" },\n  lg: { track: \"h-8 w-14\", thumb: \"h-7 w-7\", on: \"translate-x-6 rtl:-translate-x-6\" },\n};\n\ntype SwitchProps = {\n  label: string;\n  defaultChecked?: boolean;\n  disabled?: boolean;\n  size?: keyof typeof SW_SIZES;\n  onChange?: (checked: boolean) => void;\n};\n\nfunction Switch({ label, defaultChecked = false, disabled = false, size = \"md\", onChange }: SwitchProps) {\n  const id = useId();\n  const [on, setOn] = useState(defaultChecked);\n  const s = SW_SIZES[size];\n  return (\n    <label htmlFor={id} className={\"flex min-h-[44px] items-center gap-3 \" + (disabled ? \"cursor-not-allowed\" : \"cursor-pointer\")}>\n      <input\n        id={id}\n        type=\"checkbox\"\n        role=\"switch\"\n        className=\"peer sr-only\"\n        checked={on}\n        disabled={disabled}\n        onChange={(e) => {\n          setOn(e.target.checked);\n          onChange?.(e.target.checked);\n        }}\n      />\n      <span\n        aria-hidden=\"true\"\n        className={\"inline-flex shrink-0 items-center rounded-full p-0.5 transition-colors duration-200 motion-reduce:transition-none peer-focus-visible:ring-2 peer-focus-visible:ring-emerald-600 peer-focus-visible:ring-offset-2 peer-disabled:opacity-50 \" + s.track + \" \" + (on ? \"bg-emerald-700\" : \"bg-stone-400\")}\n      >\n        <span className={\"rounded-full bg-white shadow transition-transform duration-200 motion-reduce:transition-none \" + s.thumb + \" \" + (on ? s.on : \"translate-x-0\")} />\n      </span>\n      <span className=\"text-[15px] text-stone-900 peer-disabled:text-stone-500\">{label}</span>\n    </label>\n  );\n}\n\nconst REACT_CODE = `import { useId, useState } from \"react\";\n\nconst SW_SIZES = {\n  sm: { track: \"h-5 w-9\", thumb: \"h-4 w-4\", on: \"translate-x-4 rtl:-translate-x-4\" },\n  md: { track: \"h-6 w-11\", thumb: \"h-5 w-5\", on: \"translate-x-5 rtl:-translate-x-5\" },\n  lg: { track: \"h-8 w-14\", thumb: \"h-7 w-7\", on: \"translate-x-6 rtl:-translate-x-6\" },\n};\n\ntype SwitchProps = {\n  label: string;\n  defaultChecked?: boolean;\n  disabled?: boolean;\n  size?: keyof typeof SW_SIZES;\n  onChange?: (checked: boolean) => void;\n};\n\nexport function Switch({ label, defaultChecked = false, disabled = false, size = \"md\", onChange }: SwitchProps) {\n  const id = useId();\n  const [on, setOn] = useState(defaultChecked);\n  const s = SW_SIZES[size];\n  return (\n    <label htmlFor={id} className={\"flex min-h-[44px] items-center gap-3 \" + (disabled ? \"cursor-not-allowed\" : \"cursor-pointer\")}>\n      <input\n        id={id}\n        type=\"checkbox\"\n        role=\"switch\"\n        className=\"peer sr-only\"\n        checked={on}\n        disabled={disabled}\n        onChange={(e) => {\n          setOn(e.target.checked);\n          onChange?.(e.target.checked);\n        }}\n      />\n      <span\n        aria-hidden=\"true\"\n        className={\"inline-flex shrink-0 items-center rounded-full p-0.5 transition-colors duration-200 motion-reduce:transition-none peer-focus-visible:ring-2 peer-focus-visible:ring-emerald-600 peer-focus-visible:ring-offset-2 peer-disabled:opacity-50 \" + s.track + \" \" + (on ? \"bg-emerald-700\" : \"bg-stone-400\")}\n      >\n        <span className={\"rounded-full bg-white shadow transition-transform duration-200 motion-reduce:transition-none \" + s.thumb + \" \" + (on ? s.on : \"translate-x-0\")} />\n      </span>\n      <span className=\"text-[15px] text-stone-900 peer-disabled:text-stone-500\">{label}</span>\n    </label>\n  );\n}\n\n// Usage\n// <Switch label=\"Email alerts\" defaultChecked />\n// <Switch label=\"Sync over mobile data\" size=\"sm\" onChange={(on) => savePreference(on)} />\n// <Switch label=\"Beta features\" disabled />\n`;\n\n/* ---------- reference ---------- */\nconst REF: [string, string][] = [\n  [\"role=\\\"switch\\\" on a checkbox\", \"The input keeps its checkbox behaviour (Space toggles it, it submits with a form) while assistive technology reports a switch that is on or off. Leave aria-checked off: the checked state already comes from the input.\"],\n  [\"The label is the click target\", \"Wrapping the input, track and text in one label element makes the words and the drawn track toggle the input, and gives the switch its accessible name.\"],\n  [\"Focus ring on the track\", \"The input is visually hidden, so .input:focus-visible + .track draws the ring where people are looking. Never remove it without a replacement.\"],\n  [\"disabled\", \"A disabled input cannot be focused or changed and is left out of form submission. The snippets dim the track and the text so the state is visible too.\"],\n  [\"Right to left\", \"The thumb is placed with inset-inline-start and moved by a --dir custom property that flips to -1 under dir=\\\"rtl\\\", so one stylesheet serves both directions.\"],\n  [\"Switch or checkbox\", \"Use a switch for a setting that takes effect at once, such as turning alerts on. Use a checkbox for a choice that is confirmed later with a Save or Submit button.\"],\n];\n\ntype View = \"styles\" | \"react\" | \"ref\";\n\nexport default function CssToggleSwitchCollection() {\n  const [view, setView] = useState<View>(\"styles\");\n  const [size, setSize] = useState(\"16px\");\n  const [disabled, setDisabled] = useState(false);\n  const [rtl, setRtl] = useState(false);\n  const [announce, setAnnounce] = useState(\"\");\n  const opts = { disabled, rtl };\n  const styleSheet = useMemo(() => SWITCHES.map((it, i) => sc(cssOf(it, size), `tsw${i}`)).join(\"\\n\"), [size]);\n  const ring = \"focus-visible:ring-emerald-700 focus-visible:ring-offset-white\";\n  const tool = (on: boolean) =>\n    `inline-flex h-10 items-center rounded-lg px-3 text-[13px] font-medium transition-colors ${FOCUS} ${ring} ${on ? \"bg-[#16181d] text-white\" : \"bg-white text-stone-700 ring-1 ring-inset ring-stone-300 hover:bg-stone-100\"}`;\n\n  return (\n    <section className=\"bg-white px-4 py-12 text-[#16181d] sm:px-8 sm:py-14\" style={SECTION_FONT}>\n      <style>{styleSheet}</style>\n      <div className=\"mx-auto max-w-6xl\">\n        <header className=\"max-w-3xl\">\n          <p className=\"font-mono text-[12px] uppercase tracking-[0.18em] text-stone-600\">Checkbox · role=switch · no JavaScript</p>\n          <h2 className=\"mt-3 text-[32px] font-semibold leading-[1.05] tracking-[-0.03em] sm:text-[44px]\">CSS toggle switches, built on a real checkbox</h2>\n          <p className=\"mt-4 max-w-2xl text-[15px] leading-relaxed text-stone-600\">\n            Fifteen switch styles that differ in shape, not only colour. Each one is a native checkbox with role=switch inside its label, so clicking the words works, Space toggles it and forms submit it. Pick a size, try the disabled look and flip the page to right to left; the code you copy follows those choices.\n          </p>\n        </header>\n\n        <div className=\"mt-7 flex flex-col gap-3 border-y border-stone-200 py-4 lg:flex-row lg:items-center lg:justify-between\">\n          <Views\n            label=\"Choose what to show\"\n            ring={ring}\n            value={view}\n            onChange={setView}\n            views={[\n              [\"styles\", \"Switch styles\", SWITCHES.length],\n              [\"react\", \"React + Tailwind\"],\n              [\"ref\", \"How it works\"],\n            ]}\n          />\n          {view === \"styles\" && (\n            <div className=\"flex flex-wrap items-center gap-1.5\">\n              <div className=\"flex gap-1.5\" role=\"group\" aria-label=\"Size\">\n                {SIZES.map(([k, label, px]) => (\n                  <button key={k} type=\"button\" aria-pressed={size === px} onClick={() => setSize(px)} className={tool(size === px)}>\n                    {label}\n                  </button>\n                ))}\n              </div>\n              <button type=\"button\" aria-pressed={disabled} onClick={() => setDisabled(!disabled)} className={tool(disabled)}>\n                Disabled\n              </button>\n              <button type=\"button\" aria-pressed={rtl} onClick={() => setRtl(!rtl)} className={tool(rtl)}>\n                Right to left\n              </button>\n            </div>\n          )}\n        </div>\n        <p className=\"sr-only\" aria-live=\"polite\">{announce}</p>\n\n        <div className=\"mt-6 h-[780px] overflow-y-auto overscroll-contain pr-1\" tabIndex={0} aria-label=\"Toggle switch examples\">\n          {view === \"styles\" && (\n            <ul className=\"grid grid-cols-1 items-start gap-3 sm:grid-cols-2 lg:grid-cols-3\">\n              {SWITCHES.map((it, i) => (\n                <Card\n                  key={it.cls}\n                  id={`tsw-${i}`}\n                  name={it.name}\n                  note={it.note}\n                  code={codeOf(it, opts, size)}\n                  copyLabel=\"HTML and CSS\"\n                  ring={ring}\n                  onAnnounce={setAnnounce}\n                  stageClass=\"grid h-28 place-items-center bg-stone-50 px-4\"\n                  stage={toReact(swTree(it, opts), `tsw${i}`)}\n                />\n              ))}\n            </ul>\n          )}\n\n          {view === \"react\" && (\n            <div className=\"grid gap-5 lg:grid-cols-[340px_1fr]\">\n              <div className=\"rounded-2xl border border-stone-200 bg-stone-50 p-5\">\n                <p className=\"text-[13px] font-semibold uppercase tracking-[0.12em] text-stone-600\">Live</p>\n                <div className=\"mt-3 divide-y divide-stone-200\">\n                  <Switch label=\"Email alerts\" defaultChecked />\n                  <Switch label=\"Sync over mobile data\" size=\"sm\" />\n                  <Switch label=\"Large type\" size=\"lg\" defaultChecked />\n                  <Switch label=\"Beta features\" disabled />\n                </div>\n                <div dir=\"rtl\" className=\"mt-4 rounded-xl border border-stone-200 bg-white px-4\">\n                  <Switch label=\"Right to left\" defaultChecked />\n                </div>\n              </div>\n              <CodeBlock id=\"tsw-react-code\" code={REACT_CODE} label=\"Switch.tsx\" ring={ring} onAnnounce={setAnnounce} />\n            </div>\n          )}\n\n          {view === \"ref\" && (\n            <div className=\"overflow-x-auto rounded-2xl border border-stone-200\">\n              <table className=\"w-full min-w-[560px] border-collapse text-left text-[13.5px]\">\n                <caption className=\"sr-only\">What each part of the switch markup does</caption>\n                <thead className=\"bg-stone-50\">\n                  <tr>\n                    <th scope=\"col\" className=\"w-56 px-4 py-3 font-semibold\">Part</th>\n                    <th scope=\"col\" className=\"px-4 py-3 font-semibold\">What it does</th>\n                  </tr>\n                </thead>\n                <tbody>\n                  {REF.map(([k, v]) => (\n                    <tr key={k} className=\"border-t border-stone-200 align-top\">\n                      <th scope=\"row\" className=\"px-4 py-3 font-semibold text-stone-900\">{k}</th>\n                      <td className=\"px-4 py-3 leading-relaxed text-stone-700\">{v}</td>\n                    </tr>\n                  ))}\n                </tbody>\n              </table>\n            </div>\n          )}\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
