{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"dark-mode-toggle-sun-and-moon-switch","type":"registry:component","title":"Dark Mode Toggle Sun And Moon Switch","description":"Free dark mode toggle switch with a sliding sun and moon knob that follows the device setting, recolours its block and works with the keyboard.","dependencies":[],"files":[{"path":"components/we-inc/dark-mode-toggle-sun-and-moon-switch.tsx","type":"registry:component","content":"import { useEffect, useState } from \"react\";\n\n// A sun and moon switch that flips the theme of the block around it. Starts from the device setting.\nexport default function DarkModeToggleSunAndMoonSwitch() {\n  const [dark, setDark] = useState(false);\n\n  useEffect(() => {\n    // Follow prefers-color-scheme until the visitor picks for themselves.\n    const mq = window.matchMedia(\"(prefers-color-scheme: dark)\");\n    setDark(mq.matches);\n    const onChange = (e: MediaQueryListEvent) => setDark(e.matches);\n    mq.addEventListener(\"change\", onChange);\n    return () => mq.removeEventListener(\"change\", onChange);\n  }, []);\n\n  return (\n    <section className={`px-5 py-14 transition-colors duration-300 motion-reduce:transition-none ${dark ? \"bg-slate-950\" : \"bg-slate-100\"}`}>\n      <div className={`mx-auto max-w-md rounded-2xl border p-6 transition-colors duration-300 motion-reduce:transition-none ${dark ? \"border-slate-800 bg-slate-900\" : \"border-slate-200 bg-white\"}`}>\n        <div className=\"flex items-center justify-between gap-4\">\n          <div>\n            <h2 className={`text-base font-semibold ${dark ? \"text-white\" : \"text-slate-900\"}`}>Appearance</h2>\n            <p id=\"dm1-desc\" className={`text-sm ${dark ? \"text-slate-400\" : \"text-slate-600\"}`}>{dark ? \"Dark theme is on\" : \"Light theme is on\"}</p>\n          </div>\n          <button\n            type=\"button\"\n            role=\"switch\"\n            aria-checked={dark}\n            aria-label=\"Dark mode\"\n            aria-describedby=\"dm1-desc\"\n            onClick={() => setDark(!dark)}\n            className={`relative h-10 w-[76px] shrink-0 rounded-full p-1 transition-colors duration-300 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 motion-reduce:transition-none ${dark ? \"bg-indigo-950 ring-offset-slate-900 focus-visible:ring-indigo-300\" : \"bg-sky-200 ring-offset-white focus-visible:ring-sky-600\"}`}\n          >\n            <span className={`absolute inset-y-1 left-1 grid w-8 place-items-center rounded-full shadow transition-transform duration-300 ease-[cubic-bezier(.3,1.4,.5,1)] motion-reduce:transition-none ${dark ? \"translate-x-9 bg-slate-200 text-indigo-950\" : \"translate-x-0 bg-amber-300 text-amber-700\"}`}>\n              {dark ? (\n                <svg viewBox=\"0 0 20 20\" width=\"16\" height=\"16\" aria-hidden=\"true\" className=\"fill-current\"><path d=\"M15.5 13.2A7 7 0 0 1 6.8 4.5 7 7 0 1 0 15.5 13.2z\" /></svg>\n              ) : (\n                <svg viewBox=\"0 0 20 20\" width=\"18\" height=\"18\" aria-hidden=\"true\" className=\"fill-current\"><circle cx=\"10\" cy=\"10\" r=\"4\" /><path d=\"M9 1h2v3H9zm0 15h2v3H9zM1 9h3v2H1zm15 0h3v2h-3zM3.3 4.7l1.4-1.4 2.1 2.1-1.4 1.4zm10 10 1.4-1.4 2.1 2.1-1.4 1.4zM3.3 15.3l2.1-2.1 1.4 1.4-2.1 2.1zm10-10 2.1-2.1 1.4 1.4-2.1 2.1z\" /></svg>\n              )}\n            </span>\n          </button>\n        </div>\n        <div className={`mt-6 rounded-xl p-4 text-sm transition-colors duration-300 motion-reduce:transition-none ${dark ? \"bg-slate-800 text-slate-300\" : \"bg-slate-50 text-slate-700\"}`}>\n          <p className={`font-semibold ${dark ? \"text-white\" : \"text-slate-900\"}`}>Trailhead Journal</p>\n          <p className=\"mt-1\">Your entries, maps and packing lists switch with the theme. Night reading is easier on the eyes in the tent.</p>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
