{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scoped-access-prompt",
  "title": "Scoped Access Prompt",
  "description": "A connection prompt that gives people real control: switch each permission on or off, pick how long access lasts, and see the risk change before allowing it.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/scoped-access-prompt/scoped-access-prompt.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type AccessLevel = \"read\" | \"write\" | \"admin\";\n\nexport interface AccessScope {\n  id: string;\n  label: string;\n  detail: string;\n  level: AccessLevel;\n  /** Always on, and shown with a lock. */\n  required?: boolean;\n  /** Starts switched on. */\n  defaultOn?: boolean;\n}\n\nexport interface AccessDuration {\n  id: string;\n  label: string;\n  /** Finishes the sentence \"Access ends ...\". */\n  ends: string;\n}\n\nexport interface AccessGrant {\n  scopes: string[];\n  duration: string;\n}\n\nexport interface ScopedAccessPromptProps extends Omit<\n  React.ComponentPropsWithoutRef<\"section\">,\n  \"title\"\n> {\n  theme?: \"dark\" | \"light\";\n  appName?: string;\n  publisher?: string;\n  workspace?: string;\n  scopes?: AccessScope[];\n  durations?: AccessDuration[];\n  defaultDuration?: string;\n  onAllow?: (grant: AccessGrant) => void;\n  onDeny?: () => void;\n  onRevoke?: () => void;\n}\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst ACCENT = \"#5E6AD2\";\nconst GREEN = \"#27A644\";\nconst ORANGE = \"#FC7840\";\nconst RED = \"#EB5757\";\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\n\nconst PALETTES = {\n  dark: {\n    card: \"#0F1011\",\n    inset: \"#161718\",\n    border: \"rgba(255,255,255,0.08)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.05)\",\n    tab: \"rgba(255,255,255,0.08)\",\n    off: \"rgba(255,255,255,0.14)\",\n    knob: \"#F7F8F8\",\n    btn: \"#E5E5E6\",\n    btnText: \"#08090A\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    inset: \"#F7F8F8\",\n    border: \"rgba(8,9,10,0.1)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.05)\",\n    tab: \"#FFFFFF\",\n    off: \"rgba(8,9,10,0.16)\",\n    knob: \"#FFFFFF\",\n    btn: \"#08090A\",\n    btnText: \"#F7F8F8\",\n  },\n};\n\nconst DEFAULT_SCOPES: AccessScope[] = [\n  {\n    id: \"profile\",\n    label: \"See your name and email\",\n    detail: \"Used to show who connected it.\",\n    level: \"read\",\n    required: true,\n  },\n  {\n    id: \"projects\",\n    label: \"Read projects\",\n    detail: \"Titles, status and due dates.\",\n    level: \"read\",\n    defaultOn: true,\n  },\n  {\n    id: \"comment\",\n    label: \"Post comments\",\n    detail: \"Comments appear under the app's name.\",\n    level: \"write\",\n    defaultOn: true,\n  },\n  {\n    id: \"edit\",\n    label: \"Edit tasks\",\n    detail: \"Change status, owner and dates.\",\n    level: \"write\",\n  },\n  {\n    id: \"members\",\n    label: \"Manage members\",\n    detail: \"Invite and remove people.\",\n    level: \"admin\",\n  },\n];\n\nconst DEFAULT_DURATIONS: AccessDuration[] = [\n  { id: \"hour\", label: \"1 hour\", ends: \"in one hour\" },\n  { id: \"day\", label: \"1 day\", ends: \"tomorrow\" },\n  { id: \"month\", label: \"30 days\", ends: \"in 30 days\" },\n  { id: \"always\", label: \"Always\", ends: \"when you revoke it\" },\n];\n\nconst RISK = {\n  read: { label: \"Low risk\", bars: 1, color: GREEN },\n  write: { label: \"Medium risk\", bars: 2, color: ORANGE },\n  admin: { label: \"High risk\", bars: 3, color: RED },\n};\n\nfunction Check({ color }: { color: string }) {\n  return (\n    <svg\n      aria-hidden=\"true\"\n      viewBox=\"0 0 16 16\"\n      width=\"16\"\n      height=\"16\"\n      fill=\"none\"\n      className=\"block shrink-0\"\n    >\n      <path\n        d=\"m3.5 8.5 3 3 6-7\"\n        stroke={color}\n        strokeWidth=\"1.5\"\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n      />\n    </svg>\n  );\n}\n\nexport function ScopedAccessPrompt({\n  theme = \"dark\",\n  appName = \"Atlas Sync\",\n  publisher = \"Atlas Labs\",\n  workspace = \"Northwind\",\n  scopes = DEFAULT_SCOPES,\n  durations = DEFAULT_DURATIONS,\n  defaultDuration = \"month\",\n  onAllow,\n  onDeny,\n  onRevoke,\n  className,\n  style,\n  ...rest\n}: ScopedAccessPromptProps) {\n  const c = PALETTES[theme];\n  const [on, setOn] = React.useState(\n    () =>\n      new Set(scopes.filter((s) => s.required || s.defaultOn).map((s) => s.id)),\n  );\n  const [duration, setDuration] = React.useState(defaultDuration);\n  const [outcome, setOutcome] = React.useState<\"open\" | \"allowed\" | \"denied\">(\n    \"open\",\n  );\n\n  const picked = scopes.filter((s) => on.has(s.id));\n  const level: AccessLevel = picked.some((s) => s.level === \"admin\")\n    ? \"admin\"\n    : picked.some((s) => s.level === \"write\")\n      ? \"write\"\n      : \"read\";\n  const risk = RISK[level];\n  const durationIndex = Math.max(\n    0,\n    durations.findIndex((d) => d.id === duration),\n  );\n  const span = durations[durationIndex];\n  const open = outcome === \"open\";\n  const permissions = `${picked.length} ${picked.length === 1 ? \"permission\" : \"permissions\"}`;\n\n  const toggle = (id: string) => {\n    setOn((prev) => {\n      const next = new Set(prev);\n      if (next.has(id)) next.delete(id);\n      else next.add(id);\n      return next;\n    });\n  };\n\n  const allow = () => {\n    setOutcome(\"allowed\");\n    onAllow?.({ scopes: picked.map((s) => s.id), duration });\n  };\n\n  const deny = () => {\n    setOutcome(\"denied\");\n    onDeny?.();\n  };\n\n  const reset = () => {\n    if (outcome === \"allowed\") onRevoke?.();\n    setOutcome(\"open\");\n  };\n\n  const layer = (shown: boolean) =>\n    `flex min-w-0 flex-col [grid-area:1/1] motion-safe:transition-[opacity,visibility] motion-safe:duration-200 ${shown ? \"visible opacity-100\" : \"invisible opacity-0\"}`;\n\n  return (\n    <section\n      aria-label={`${appName} access request`}\n      className={`grid w-full rounded-2xl border ${className ?? \"\"}`}\n      style={{\n        background: c.card,\n        borderColor: c.border,\n        color: c.text,\n        fontFamily: FONT,\n        ...style,\n      }}\n      {...rest}\n    >\n      {/* The result sits in the same cell as the form, so the card never changes size. */}\n      <div className={layer(open)} aria-hidden={!open}>\n        <header className=\"flex items-center gap-3 p-5 pb-4\">\n          <span\n            aria-hidden=\"true\"\n            className=\"flex size-10 shrink-0 items-center justify-center rounded-xl text-[16px] leading-[20px] font-[590]\"\n            style={{ background: ACCENT, color: \"#FFFFFF\" }}\n          >\n            {appName.slice(0, 1)}\n          </span>\n          <div className=\"min-w-0\">\n            <h3 className=\"m-0 text-[16px] leading-[22px] font-[590] tracking-[-0.014em]\">\n              {appName} wants access to {workspace}\n            </h3>\n            <p\n              className=\"m-0 text-[12.5px] leading-[18px] tracking-[-0.008em]\"\n              style={{ color: c.sub }}\n            >\n              By {publisher}. Turn off anything it doesn&apos;t need.\n            </p>\n          </div>\n        </header>\n\n        <ul\n          className=\"m-0 list-none border-y px-5 py-1\"\n          style={{ borderColor: c.border }}\n        >\n          {scopes.map((s) => {\n            const active = on.has(s.id);\n            return (\n              <li\n                key={s.id}\n                className=\"flex items-center justify-between gap-4 py-2.5\"\n              >\n                <div className=\"min-w-0\">\n                  <p className=\"m-0 flex items-center gap-2 text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\">\n                    <span className=\"truncate\">{s.label}</span>\n                    {s.level === \"admin\" && (\n                      <span\n                        className=\"shrink-0 text-[12px] leading-[16px] font-normal tracking-[-0.005em]\"\n                        style={{ color: RED }}\n                      >\n                        Admin\n                      </span>\n                    )}\n                  </p>\n                  <p\n                    className=\"m-0 truncate text-[12px] leading-[16px] tracking-[-0.005em]\"\n                    style={{ color: c.faint }}\n                  >\n                    {s.detail}\n                  </p>\n                </div>\n                {s.required ? (\n                  <span\n                    className=\"shrink-0 text-[12px] leading-[16px] tracking-[-0.005em]\"\n                    style={{ color: c.faint }}\n                  >\n                    Required\n                  </span>\n                ) : (\n                  <button\n                    type=\"button\"\n                    role=\"switch\"\n                    aria-checked={active}\n                    aria-label={s.label}\n                    data-scope={s.id}\n                    tabIndex={open ? 0 : -1}\n                    onClick={() => toggle(s.id)}\n                    className={`relative h-5 w-8 shrink-0 cursor-pointer rounded-full border-0 p-0 motion-safe:transition-colors motion-safe:duration-200 ${RING}`}\n                    style={{ background: active ? ACCENT : c.off }}\n                  >\n                    <span\n                      aria-hidden=\"true\"\n                      className=\"absolute top-0.5 left-0.5 size-4 rounded-full motion-safe:transition-transform motion-safe:duration-200\"\n                      style={{\n                        background: c.knob,\n                        transform: active ? \"translateX(12px)\" : \"none\",\n                      }}\n                    />\n                  </button>\n                )}\n              </li>\n            );\n          })}\n        </ul>\n\n        <div className=\"px-5 pt-4\">\n          <p\n            className=\"m-0 text-[12px] leading-[16px] tracking-[-0.005em]\"\n            style={{ color: c.sub }}\n          >\n            How long\n          </p>\n          <div\n            role=\"group\"\n            aria-label=\"How long\"\n            className=\"relative mt-2 grid h-8 rounded-full p-0.5\"\n            style={{\n              background: c.chip,\n              gridTemplateColumns: `repeat(${durations.length}, minmax(0, 1fr))`,\n            }}\n          >\n            <span\n              aria-hidden=\"true\"\n              className=\"absolute top-0.5 bottom-0.5 left-0.5 rounded-full motion-safe:transition-transform motion-safe:duration-300\"\n              style={{\n                width: `calc((100% - 4px) / ${durations.length})`,\n                transform: `translateX(${durationIndex * 100}%)`,\n                background: c.tab,\n              }}\n            />\n            {durations.map((d) => (\n              <button\n                key={d.id}\n                type=\"button\"\n                data-duration={d.id}\n                aria-pressed={d.id === duration}\n                tabIndex={open ? 0 : -1}\n                onClick={() => setDuration(d.id)}\n                className={`relative cursor-pointer truncate rounded-full border-0 bg-transparent px-1 text-[12.5px] leading-[18px] font-[510] tracking-[-0.011em] motion-safe:transition-colors motion-safe:duration-200 ${RING}`}\n                style={{ color: d.id === duration ? c.text : c.sub }}\n              >\n                {d.label}\n              </button>\n            ))}\n          </div>\n        </div>\n\n        <div\n          aria-live=\"polite\"\n          className=\"flex items-center justify-between gap-3 px-5 pt-3 text-[12.5px] leading-[18px] tracking-[-0.008em]\"\n          style={{ color: c.sub }}\n        >\n          <span className=\"truncate\">\n            {picked.length} of {scopes.length} permissions, ends {span?.ends}\n          </span>\n          <span className=\"flex shrink-0 items-center gap-1.5\">\n            <span aria-hidden=\"true\" className=\"flex items-end gap-0.5\">\n              {[0, 1, 2].map((i) => (\n                <span\n                  key={i}\n                  className=\"w-[3px] rounded-[1px] motion-safe:transition-colors motion-safe:duration-200\"\n                  style={{\n                    height: 6 + i * 3,\n                    background: i < risk.bars ? risk.color : c.off,\n                  }}\n                />\n              ))}\n            </span>\n            <span style={{ color: c.soft }}>{risk.label}</span>\n          </span>\n        </div>\n\n        <footer className=\"flex gap-2 p-5 pt-4\">\n          <button\n            type=\"button\"\n            tabIndex={open ? 0 : -1}\n            onClick={deny}\n            className={`h-9 flex-1 cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n            style={{ background: c.chip, color: c.soft }}\n          >\n            Deny\n          </button>\n          <button\n            type=\"button\"\n            tabIndex={open ? 0 : -1}\n            onClick={allow}\n            className={`h-9 flex-1 cursor-pointer rounded-full border-0 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n            style={{ background: c.btn, color: c.btnText }}\n          >\n            Allow {permissions}\n          </button>\n        </footer>\n      </div>\n\n      <div\n        className={`${layer(!open)} items-center justify-center p-8 text-center`}\n        aria-hidden={open}\n        aria-live=\"polite\"\n      >\n        <span\n          className=\"flex size-10 items-center justify-center rounded-full\"\n          style={{ background: c.chip }}\n        >\n          {outcome === \"denied\" ? (\n            <svg\n              aria-hidden=\"true\"\n              viewBox=\"0 0 16 16\"\n              width=\"16\"\n              height=\"16\"\n              fill=\"none\"\n              className=\"block\"\n            >\n              <path\n                d=\"m4.5 4.5 7 7m0-7-7 7\"\n                stroke={c.sub}\n                strokeWidth=\"1.5\"\n                strokeLinecap=\"round\"\n              />\n            </svg>\n          ) : (\n            <Check color={GREEN} />\n          )}\n        </span>\n        <h3 className=\"m-0 mt-4 text-[16px] leading-[22px] font-[590] tracking-[-0.014em]\">\n          {outcome === \"denied\" ? \"Request denied\" : `${appName} is connected`}\n        </h3>\n        <p\n          className=\"m-0 mt-1 max-w-[300px] text-[13px] leading-[20px] tracking-[-0.011em]\"\n          style={{ color: c.sub }}\n        >\n          {outcome === \"denied\"\n            ? `${appName} can't see anything in ${workspace}.`\n            : `It has ${permissions}, and access ends ${span?.ends}.`}\n        </p>\n        {outcome === \"allowed\" && (\n          <ul className=\"m-0 mt-4 w-full max-w-[280px] list-none p-0 text-left\">\n            {picked.map((s) => (\n              <li\n                key={s.id}\n                className=\"flex items-center gap-2 py-1 text-[13px] leading-[20px] tracking-[-0.011em]\"\n                style={{ color: c.soft }}\n              >\n                <Check color={c.faint} />\n                <span className=\"truncate\">{s.label}</span>\n              </li>\n            ))}\n          </ul>\n        )}\n        <button\n          type=\"button\"\n          tabIndex={open ? -1 : 0}\n          onClick={reset}\n          className={`mt-5 h-9 cursor-pointer rounded-full border-0 px-4 text-[13px] leading-[20px] font-[510] tracking-[-0.011em] ${RING}`}\n          style={{ background: c.chip, color: c.soft }}\n        >\n          {outcome === \"denied\" ? \"Review again\" : \"Revoke access\"}\n        </button>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}