{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "connected-apps-toggle-list",
  "title": "Connected Apps Toggle List",
  "description": "An integrations list where each app has a switch that does the real flow: turning one on shows what it will be allowed to do before connecting, connected apps show the account and options to configure, expired ones ask to reconnect, and turning off asks for confirmation. With filters and search.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/connected-apps-toggle-list/connected-apps-toggle-list.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype State = \"off\" | \"consent\" | \"connecting\" | \"on\" | \"error\";\nexport interface ConnectedApp {\n  id: string;\n  name: string;\n  category: string;\n  description: string;\n  color: string;\n  scopes: string[];\n  options: { id: string; label: string; default: boolean }[];\n  state: \"off\" | \"on\" | \"error\";\n  account?: string;\n}\n\nexport interface ConnectedAppsToggleListProps {\n  apps?: ConnectedApp[];\n  onConnect?: (id: string) => Promise<string | void> | string | void;\n  onDisconnect?: (id: string) => void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.36)\", card: \"#121212\", well: \"rgba(255,255,255,0.035)\", border: \"rgba(255,255,255,0.08)\", track: \"rgba(255,255,255,0.12)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", green: \"#4ADE80\", amber: \"#FBBF24\", red: \"#F87171\", ring: \"rgba(245,244,241,0.6)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.42)\", card: \"#FFFFFF\", well: \"rgba(10,10,10,0.03)\", border: \"rgba(10,10,10,0.09)\", track: \"rgba(10,10,10,0.14)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", green: \"#15803D\", amber: \"#B45309\", red: \"#DC2626\", ring: \"rgba(10,10,10,0.5)\" },\n};\nconst APPS: ConnectedApp[] = [\n  { id: \"chatterbox\", name: \"Chatterbox\", category: \"Messaging\", description: \"Get alerts and share reports in channels.\", color: \"#A78BFA\", scopes: [\"See your channels\", \"Post messages as Nexora\", \"Read who's in a channel\"], options: [{ id: \"alerts\", label: \"Send usage alerts to #ops\", default: true }, { id: \"digest\", label: \"Weekly report to #general\", default: false }], state: \"on\", account: \"nexora.chatterbox.app\" },\n  { id: \"calendo\", name: \"Calendo\", category: \"Calendar\", description: \"Show deadlines and meetings on your calendar.\", color: \"#60A5FA\", scopes: [\"See your calendars\", \"Create and update events\"], options: [{ id: \"deadlines\", label: \"Add project deadlines\", default: true }], state: \"error\", account: \"lena@nexora.io\" },\n  { id: \"ledgerly\", name: \"Ledgerly\", category: \"Accounting\", description: \"Sync paid invoices and refunds automatically.\", color: \"#34D399\", scopes: [\"Read invoices and customers\", \"Create invoices\"], options: [{ id: \"refunds\", label: \"Include refunds\", default: true }], state: \"off\" },\n  { id: \"pagewise\", name: \"Pagewise\", category: \"Docs\", description: \"Embed live dashboards in your docs.\", color: \"#F59E0B\", scopes: [\"Read pages you share with Nexora\", \"Embed content\"], options: [{ id: \"public\", label: \"Allow embeds on public pages\", default: false }], state: \"off\" },\n  { id: \"trackr\", name: \"Trackr\", category: \"Issues\", description: \"Create issues from churn and error alerts.\", color: \"#F472B6\", scopes: [\"See projects\", \"Create and update issues\"], options: [{ id: \"auto\", label: \"Create issues automatically\", default: false }], state: \"off\" },\n];\ntype Tab = \"all\" | \"connected\" | \"available\";\n\nexport function ConnectedAppsToggleList({ apps = APPS, onConnect, onDisconnect, theme = \"dark\", className }: ConnectedAppsToggleListProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [state, setState] = React.useState<Record<string, State>>(() => Object.fromEntries(apps.map((a) => [a.id, a.state])));\n  const [accounts, setAccounts] = React.useState<Record<string, string>>(() => Object.fromEntries(apps.filter((a) => a.account).map((a) => [a.id, a.account!])));\n  const [opts, setOpts] = React.useState<Record<string, boolean>>(() => Object.fromEntries(apps.flatMap((a) => a.options.map((o) => [`${a.id}.${o.id}`, o.default]))));\n  const [open, setOpen] = React.useState<string | null>(null);\n  const [confirm, setConfirm] = React.useState<string | null>(null);\n  const [tab, setTab] = React.useState<Tab>(\"all\");\n  const [query, setQuery] = React.useState(\"\");\n  const [toast, setToast] = React.useState<string | null>(null);\n  const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const focusOnce = React.useCallback((el: HTMLElement | null) => el?.focus({ preventScroll: true }), []);\n\n  React.useEffect(() => {\n    if (!toast) return;\n    const t = setTimeout(() => setToast(null), 2200);\n    return () => clearTimeout(t);\n  }, [toast]);\n  React.useEffect(\n    () => () => {\n      if (timer.current) clearTimeout(timer.current);\n    },\n    [],\n  );\n\n  const connected = (id: string) => state[id] === \"on\" || state[id] === \"error\";\n  const shown = apps.filter((a) => (tab === \"all\" ? true : tab === \"connected\" ? connected(a.id) : !connected(a.id)) && (a.name + a.category).toLowerCase().includes(query.trim().toLowerCase()));\n  const authorize = (a: ConnectedApp) => {\n    setState((s) => ({ ...s, [a.id]: \"connecting\" }));\n    const done = (acct?: string | void) => {\n      setState((s) => ({ ...s, [a.id]: \"on\" }));\n      setAccounts((x) => ({ ...x, [a.id]: acct || \"lena@nexora.io\" }));\n      setOpen(a.id);\n      setToast(`${a.name} connected`);\n    };\n    const r = onConnect?.(a.id);\n    if (r instanceof Promise) r.then(done, () => setState((s) => ({ ...s, [a.id]: \"off\" })));\n    else timer.current = setTimeout(() => done(r), reduce ? 0 : 1200);\n  };\n  const toggle = (a: ConnectedApp) => {\n    const s = state[a.id];\n    if (s === \"off\") setState((x) => ({ ...x, [a.id]: \"consent\" }));\n    else if (s === \"consent\") setState((x) => ({ ...x, [a.id]: \"off\" }));\n    else if (s === \"on\" || s === \"error\") setConfirm(a.id);\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.card } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const btn = cn(\"flex h-8 shrink-0 cursor-pointer items-center justify-center gap-1.5 rounded-lg px-3 text-[12.5px] font-medium\", focus);\n  const fold = { initial: reduce ? false : { opacity: 0, height: 0 }, animate: { opacity: 1, height: \"auto\" }, exit: reduce ? undefined : { opacity: 0, height: 0 } } as const;\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <div className=\"mx-auto max-w-2xl px-4 py-10 @[640px]:px-6\">\n        <h2 className=\"m-0 text-[22px] font-semibold tracking-[-0.01em]\">Connected apps</h2>\n        <p className=\"m-0 mt-1 text-[13.5px]\" style={{ color: p.muted }}>\n          Bring your tools into Nexora. You can disconnect any app at any time.\n        </p>\n        <div className=\"mt-5 flex flex-wrap items-center gap-2\">\n          <div role=\"tablist\" aria-label=\"Filter apps\" className=\"flex rounded-lg border p-0.5\" style={{ borderColor: p.border }}>\n            {(\n              [\n                [\"all\", \"All\"],\n                [\"connected\", \"Connected\"],\n                [\"available\", \"Available\"],\n              ] as const\n            ).map(([k, label]) => (\n              <button key={k} type=\"button\" role=\"tab\" aria-selected={tab === k} onClick={() => setTab(k)} className={cn(\"relative h-7 cursor-pointer rounded-md border-0 bg-transparent px-3 text-[12.5px]\", \"outline-none focus-visible:ring-2\")} style={{ color: tab === k ? p.onText : p.muted, ...ring }}>\n                {tab === k && <motion.span layoutId={`${uid}-tab`} className=\"absolute inset-0 rounded-md\" style={{ background: p.on }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 520, damping: 38 }} />}\n                <span className=\"relative\">\n                  {label}\n                  {k === \"connected\" && <span className=\"ml-1 tabular-nums opacity-70\">{apps.filter((a) => connected(a.id)).length}</span>}\n                </span>\n              </button>\n            ))}\n          </div>\n          <input value={query} onChange={(e) => setQuery(e.target.value)} placeholder=\"Search apps\" aria-label=\"Search apps\" className={cn(\"h-8 min-w-0 flex-1 rounded-lg border px-3 text-[12.5px] @[480px]:max-w-[220px] @[480px]:flex-none\", focus)} style={{ borderColor: p.border, background: p.card, color: p.text, ...ring }} />\n        </div>\n\n        <ul className=\"m-0 mt-4 flex list-none flex-col gap-2.5 p-0\">\n          <AnimatePresence initial={false}>\n            {shown.map((a) => {\n              const s = state[a.id];\n              const isOn = s === \"on\" || s === \"error\" || s === \"connecting\";\n              return (\n                <motion.li key={a.id} layout={!reduce ? \"position\" : false} initial={reduce ? false : { opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, scale: 0.98 }} className=\"overflow-hidden rounded-2xl border\" style={{ background: p.card, borderColor: s === \"error\" ? `${p.amber}66` : p.border }}>\n                  <div className=\"flex items-center gap-3.5 px-4 py-3.5\">\n                    <span className=\"grid h-10 w-10 shrink-0 place-items-center rounded-xl text-[15px] font-bold text-white\" style={{ background: a.color }} aria-hidden=\"true\">\n                      {a.name[0]}\n                    </span>\n                    <div className=\"min-w-0 flex-1\">\n                      <p id={`${uid}-${a.id}`} className=\"m-0 flex flex-wrap items-center gap-x-2 text-[14px] font-medium\">\n                        {a.name}\n                        <span className=\"text-[11.5px] font-normal\" style={{ color: p.faint }}>\n                          {a.category}\n                        </span>\n                      </p>\n                      <p className={cn(\"m-0 mt-0.5 text-[12.5px]\", s !== \"error\" && \"truncate\")} style={{ color: s === \"error\" ? p.amber : s === \"on\" ? p.muted : p.faint }} aria-live=\"polite\">\n                        {s === \"error\" ? \"Access expired · reconnect to keep syncing\" : s === \"on\" ? `Connected as ${accounts[a.id]} · synced 2 min ago` : s === \"connecting\" ? \"Connecting…\" : a.description}\n                      </p>\n                    </div>\n                    {s === \"on\" && (\n                      <button type=\"button\" onClick={() => setOpen(open === a.id ? null : a.id)} aria-expanded={open === a.id} className={cn(btn, \"hidden border bg-transparent @[480px]:flex\")} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                        Configure\n                      </button>\n                    )}\n                    {s === \"error\" && (\n                      <button type=\"button\" onClick={() => authorize(a)} className={cn(btn, \"border-0\")} style={{ background: p.amber, color: \"#0A0A0A\", ...ring }}>\n                        Reconnect\n                      </button>\n                    )}\n                    {s === \"connecting\" ? (\n                      <motion.span className=\"h-5 w-5 shrink-0 rounded-full border-2\" style={{ borderColor: p.track, borderTopColor: p.green }} animate={reduce ? undefined : { rotate: 360 }} transition={{ repeat: Infinity, duration: 0.8, ease: \"linear\" }} aria-label=\"Connecting\" />\n                    ) : (\n                      <button type=\"button\" role=\"switch\" aria-checked={isOn} aria-labelledby={`${uid}-${a.id}`} onClick={() => toggle(a)} className={cn(\"relative h-6 w-11 shrink-0 cursor-pointer rounded-full border-0 transition-colors\", focus)} style={{ background: s === \"on\" ? p.green : s === \"error\" ? p.amber : s === \"consent\" ? p.faint : p.track, ...ring }}>\n                        <motion.span className=\"absolute top-0.5 h-5 w-5 rounded-full bg-white shadow\" initial={false} animate={{ left: isOn || s === \"consent\" ? 22 : 2 }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 600, damping: 34 }} />\n                      </button>\n                    )}\n                  </div>\n\n                  <AnimatePresence initial={false}>\n                    {s === \"consent\" && (\n                      <motion.div key=\"consent\" {...fold} className=\"overflow-hidden\">\n                        <div className=\"mx-4 mb-4 rounded-xl p-3.5\" style={{ background: p.well }} role=\"group\" aria-label={`Allow ${a.name}`}>\n                          <p className=\"m-0 text-[13px] font-medium\">Allow {a.name} to:</p>\n                          <ul className=\"m-0 mt-2 flex list-none flex-col gap-1.5 p-0\">\n                            {a.scopes.map((sc) => (\n                              <li key={sc} className=\"flex items-center gap-2 text-[12.5px]\" style={{ color: p.muted }}>\n                                <svg width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill=\"none\" stroke={p.green} strokeWidth=\"2.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                                  <path d=\"m5 12.5 4.5 4.5L19 7.5\" />\n                                </svg>\n                                {sc}\n                              </li>\n                            ))}\n                          </ul>\n                          <p className=\"m-0 mt-2.5 text-[11.5px]\" style={{ color: p.faint }}>\n                            You&apos;ll sign in to {a.name} in a new window. Nexora never sees your password.\n                          </p>\n                          <div className=\"mt-3 flex justify-end gap-2\">\n                            <button type=\"button\" onClick={() => setState((x) => ({ ...x, [a.id]: \"off\" }))} className={cn(btn, \"border bg-transparent\")} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                              Cancel\n                            </button>\n                            <button type=\"button\" ref={focusOnce} onClick={() => authorize(a)} className={cn(btn, \"border-0\")} style={{ background: p.on, color: p.onText, ...ring }}>\n                              Allow and connect\n                            </button>\n                          </div>\n                        </div>\n                      </motion.div>\n                    )}\n                    {s === \"on\" && open === a.id && (\n                      <motion.div key=\"cfg\" {...fold} className=\"overflow-hidden\">\n                        <div className=\"mx-4 mb-4 flex flex-col gap-2 rounded-xl p-3.5\" style={{ background: p.well }}>\n                          {a.options.map((o) => {\n                            const k = `${a.id}.${o.id}`;\n                            return (\n                              <label key={k} className=\"flex cursor-pointer items-center justify-between gap-3 text-[13px] has-[:focus-visible]:underline\">\n                                {o.label}\n                                <input type=\"checkbox\" checked={opts[k]} onChange={(e) => setOpts((x) => ({ ...x, [k]: e.target.checked }))} className=\"h-4 w-4 cursor-pointer\" style={{ accentColor: p.green }} />\n                              </label>\n                            );\n                          })}\n                        </div>\n                      </motion.div>\n                    )}\n                    {confirm === a.id && (\n                      <motion.div key=\"confirm\" {...fold} className=\"overflow-hidden\" role=\"alertdialog\" aria-label={`Disconnect ${a.name}?`}>\n                        <div className=\"mx-4 mb-4 flex flex-wrap items-center justify-between gap-3 rounded-xl border p-3\" style={{ borderColor: `${p.red}55` }}>\n                          <span className=\"text-[12.5px]\" style={{ color: p.muted }}>\n                            Disconnect {a.name}? Syncing stops and its settings are removed.\n                          </span>\n                          <span className=\"flex gap-2\">\n                            <button type=\"button\" ref={focusOnce} onClick={() => setConfirm(null)} className={cn(btn, \"border bg-transparent\")} style={{ borderColor: p.border, color: p.text, ...ring }}>\n                              Keep\n                            </button>\n                            <button\n                              type=\"button\"\n                              onClick={() => {\n                                setState((x) => ({ ...x, [a.id]: \"off\" }));\n                                setConfirm(null);\n                                setOpen(null);\n                                onDisconnect?.(a.id);\n                                setToast(`${a.name} disconnected`);\n                              }}\n                              className={cn(btn, \"border-0 text-white\")}\n                              style={{ background: p.red, ...ring }}\n                            >\n                              Disconnect\n                            </button>\n                          </span>\n                        </div>\n                      </motion.div>\n                    )}\n                  </AnimatePresence>\n                </motion.li>\n              );\n            })}\n          </AnimatePresence>\n          {!shown.length && (\n            <li className=\"py-10 text-center text-[13px]\" style={{ color: p.faint }}>\n              {tab === \"connected\" ? \"No apps connected yet.\" : \"No apps match.\"}\n            </li>\n          )}\n        </ul>\n      </div>\n      <AnimatePresence>\n        {toast && (\n          <motion.div key={toast} role=\"status\" initial={reduce ? false : { opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0 }} className=\"mx-auto mb-6 w-fit rounded-full border px-3.5 py-1.5 text-[12.5px]\" style={{ background: p.card, borderColor: p.border }}>\n            {toast}\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </section>\n  );\n}\n\nexport default ConnectedAppsToggleList;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}