{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"switch-cards-privacy","type":"registry:component","title":"Switch cards · Privacy","description":"Privacy and security switches with a Protected or At risk badge; turning off a sensitive one opens an inline confirmation first.","author":"GetUrUI <hello@geturui.dev>","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/geturui/examples/switch-cards/privacy.tsx","type":"registry:component","target":"components/examples/switch-cards/privacy.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { ShieldAlert, ShieldCheck } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface PrivacySetting {\n  id: string;\n  label: string;\n  description: string;\n  enabled: boolean;\n  /** Ask before turning this off; the text explains the consequence. */\n  confirmOff?: string;\n}\n\nexport interface PrivacySwitchCardProps {\n  settings?: PrivacySetting[];\n  onChange?: (id: string, enabled: boolean) => void;\n  className?: string;\n}\n\nconst SETTINGS: PrivacySetting[] = [\n  { id: \"presence\", label: \"Show when I’m online\", description: \"Teammates see a green dot next to your name.\", enabled: true },\n  { id: \"receipts\", label: \"Read receipts\", description: \"Let people know when you’ve read their message.\", enabled: false },\n  { id: \"analytics\", label: \"Share usage data\", description: \"Anonymous diagnostics that help us fix bugs faster.\", enabled: true },\n  { id: \"alerts\", label: \"Sign-in alerts\", description: \"Email me when a new device signs in.\", enabled: true, confirmOff: \"You won’t hear about sign-ins from new devices, including ones that aren’t yours.\" },\n  { id: \"2fa\", label: \"Two-step verification\", description: \"Ask for a code from your authenticator app.\", enabled: true, confirmOff: \"Anyone with your password could sign in. We recommend keeping this on.\" },\n];\nconst spring = { type: \"spring\", stiffness: 520, damping: 32 } as const;\nconst soft = { type: \"spring\", stiffness: 320, damping: 30 } as const;\n\n/** Privacy settings where risky switches ask first: turning one off springs open an inline confirmation that holds focus until you choose. */\nexport function PrivacySwitchCard({ settings = SETTINGS, onChange, className }: PrivacySwitchCardProps) {\n  const reduce = useReducedMotion();\n  const uid = React.useId();\n  const [state, setState] = React.useState(() => Object.fromEntries(settings.map((s) => [s.id, s.enabled])));\n  const [pending, setPending] = React.useState<string | null>(null);\n  const switchRefs = React.useRef<Record<string, HTMLButtonElement | null>>({});\n  const keepRef = React.useRef<HTMLButtonElement>(null);\n  const protectedCount = settings.filter((s) => s.confirmOff && state[s.id]).length;\n  const totalProtected = settings.filter((s) => s.confirmOff).length;\n\n  React.useEffect(() => {\n    if (pending) requestAnimationFrame(() => keepRef.current?.focus());\n  }, [pending]);\n\n  function set(id: string, value: boolean) {\n    setState((s) => ({ ...s, [id]: value }));\n    onChange?.(id, value);\n  }\n\n  function toggle(s: PrivacySetting) {\n    if (state[s.id] && s.confirmOff) return setPending(pending === s.id ? null : s.id);\n    setPending(null);\n    set(s.id, !state[s.id]);\n  }\n\n  function resolve(turnOff: boolean) {\n    if (!pending) return;\n    if (turnOff) set(pending, false);\n    switchRefs.current[pending]?.focus();\n    setPending(null);\n  }\n\n  const secure = protectedCount === totalProtected;\n\n  return (\n    <section aria-labelledby={`${uid}-t`} className={cn(\"w-full max-w-[460px] overflow-hidden rounded-lg border border-border bg-surface-raised shadow-sm\", className)}>\n      <header className=\"flex items-center justify-between gap-3 border-b border-border px-5 py-4\">\n        <div>\n          <h2 id={`${uid}-t`} className=\"font-display text-[16px] font-semibold text-ink\">Privacy and security</h2>\n          <p className=\"mt-0.5 text-[12.5px] text-ink-muted\">Control what others see and how you sign in.</p>\n        </div>\n        <AnimatePresence mode=\"wait\" initial={false}>\n          <motion.span\n            key={String(secure)}\n            role=\"status\"\n            initial={{ opacity: 0, scale: reduce ? 1 : 0.85 }}\n            animate={{ opacity: 1, scale: 1 }}\n            exit={{ opacity: 0, scale: reduce ? 1 : 0.85 }}\n            transition={spring}\n            className={cn(\"inline-flex shrink-0 items-center gap-1 rounded-full px-2 py-1 text-[11.5px] font-medium ring-1\", secure ? \"text-success ring-success/30\" : \"text-warning ring-warning/40\")}\n          >\n            {secure ? <ShieldCheck aria-hidden className=\"size-3.5\" /> : <ShieldAlert aria-hidden className=\"size-3.5\" />}\n            {secure ? \"Protected\" : \"At risk\"}\n          </motion.span>\n        </AnimatePresence>\n      </header>\n      <ul className=\"divide-y divide-border\">\n        {settings.map((s) => {\n          const on = !!state[s.id];\n          const asking = pending === s.id;\n          return (\n            <li key={s.id} className=\"px-5 py-3\">\n              <div className=\"flex items-center justify-between gap-4\">\n                <div className=\"min-w-0\">\n                  <p id={`${uid}-${s.id}`} className=\"text-[13.5px] font-medium text-ink\">{s.label}</p>\n                  <p id={`${uid}-${s.id}-d`} className=\"text-[12px] text-ink-subtle\">{s.description}</p>\n                </div>\n                <motion.button\n                  ref={(el) => {\n                    switchRefs.current[s.id] = el;\n                  }}\n                  type=\"button\"\n                  role=\"switch\"\n                  aria-checked={on}\n                  aria-labelledby={`${uid}-${s.id}`}\n                  aria-describedby={`${uid}-${s.id}-d`}\n                  aria-expanded={s.confirmOff ? asking : undefined}\n                  aria-controls={s.confirmOff ? `${uid}-${s.id}-c` : undefined}\n                  onClick={() => toggle(s)}\n                  whileTap=\"press\"\n                  className={cn(\n                    \"relative inline-flex h-6 w-10 shrink-0 items-center rounded-full border p-[2px] outline-none transition-colors duration-200 focus-visible:shadow-[var(--focus-ring)]\",\n                    on ? \"border-transparent bg-volt\" : \"border-border-strong bg-surface-sunken\",\n                    asking && \"ring-2 ring-danger/50\",\n                  )}\n                >\n                  <motion.span animate={{ x: asking ? 8 : on ? 16 : 0 }} variants={{ press: { scaleX: 1.25 } }} transition={spring} style={{ originX: on ? 1 : 0 }} className={cn(\"block size-[18px] rounded-full shadow-sm\", on ? \"bg-on-volt\" : \"bg-ink-subtle\")} />\n                </motion.button>\n              </div>\n              <AnimatePresence initial={false}>\n                {asking && (\n                  <motion.div\n                    id={`${uid}-${s.id}-c`}\n                    role=\"alertdialog\"\n                    aria-labelledby={`${uid}-${s.id}-q`}\n                    aria-describedby={`${uid}-${s.id}-w`}\n                    initial={{ height: 0, opacity: 0 }}\n                    animate={{ height: \"auto\", opacity: 1 }}\n                    exit={{ height: 0, opacity: 0 }}\n                    transition={reduce ? { duration: 0 } : soft}\n                    onKeyDown={(e) => {\n                      if (e.key !== \"Escape\") return;\n                      e.stopPropagation();\n                      resolve(false);\n                    }}\n                    className=\"overflow-hidden\"\n                  >\n                    <div className=\"mt-3 rounded-md border border-danger/30 bg-surface-sunken p-3\">\n                      <p id={`${uid}-${s.id}-q`} className=\"flex items-center gap-1.5 text-[13px] font-medium text-danger\">\n                        <ShieldAlert aria-hidden className=\"size-4\" />\n                        Turn off {s.label.toLowerCase()}?\n                      </p>\n                      <p id={`${uid}-${s.id}-w`} className=\"mt-1 text-[12.5px] text-ink-muted\">{s.confirmOff}</p>\n                      <div className=\"mt-3 flex justify-end gap-2\">\n                        <button ref={keepRef} type=\"button\" onClick={() => resolve(false)} className=\"h-8 rounded-full bg-ink px-3.5 text-[12.5px] font-semibold text-bg outline-none focus-visible:shadow-[var(--focus-ring)]\">\n                          Keep it on\n                        </button>\n                        <motion.button type=\"button\" whileTap={{ scale: 0.96 }} onClick={() => resolve(true)} className=\"h-8 rounded-full border border-danger/50 px-3.5 text-[12.5px] font-medium text-danger outline-none transition-colors hover:bg-danger/10 focus-visible:shadow-[var(--focus-ring)]\">\n                          Turn off\n                        </motion.button>\n                      </div>\n                    </div>\n                  </motion.div>\n                )}\n              </AnimatePresence>\n            </li>\n          );\n        })}\n      </ul>\n    </section>\n  );\n}\n"},{"path":"LICENSE-geturui.md","type":"registry:file","target":"LICENSE-geturui.md","content":"MIT License\n\nCopyright (c) 2026 geturui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"}],"categories":["examples","switch","toggle","settings","preferences","notifications","privacy","features","form"],"meta":{"tier":"free","license":"MIT","docs":"https://geturui.com/docs/switch-cards#privacy"}}