{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"side-sheet","type":"registry:block","title":"Side sheet","description":"A deployment log that slides in from the right, with staggered build steps, a copyable commit SHA and a queued rollback.","dependencies":["motion","lucide-react"],"registryDependencies":["utils"],"files":[{"path":"registry/prequel/side-sheet/side-sheet.tsx","type":"registry:component","content":"\"use client\";\n\nimport {\n  useCallback,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n} from \"react\";\nimport {\n  AnimatePresence,\n  MotionConfig,\n  motion,\n  useInView,\n  useReducedMotion,\n} from \"motion/react\";\nimport { Check, ChevronRight, Copy, X } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nconst EASE: [number, number, number, number] = [0.22, 1, 0.36, 1];\n\n/* ------------------------------------------------------------------ */\n/* types                                                               */\n/* ------------------------------------------------------------------ */\n\nexport type Deployment = {\n  id: string;\n  environment: string;\n  time: string;\n  status: \"Live\" | \"Ready\" | \"Expired\";\n};\n\nexport type SideSheetProps = {\n  className?: string;\n  title?: string;\n  description?: string;\n  deployments?: Deployment[];\n  /** Commit SHA shown in the sheet and copied by the footer button. */\n  commit?: string;\n};\n\n/* ------------------------------------------------------------------ */\n/* demo data                                                           */\n/* ------------------------------------------------------------------ */\n\nconst DEFAULT_DEPLOYMENTS: Deployment[] = [\n  { id: \"4f2c1a\", environment: \"Production\", time: \"6 minutes ago\", status: \"Live\" },\n  { id: \"9b81e3\", environment: \"Staging\", time: \"2 hours ago\", status: \"Ready\" },\n  { id: \"c07d44\", environment: \"Preview\", time: \"Yesterday\", status: \"Expired\" },\n];\n\nconst STEPS = [\n  { label: \"Installed dependencies\", duration: \"18s\" },\n  { label: \"Built application\", duration: \"51s\" },\n  { label: \"Uploaded edge assets\", duration: \"12s\" },\n  { label: \"Promoted to production\", duration: \"21s\" },\n];\n\n/* ------------------------------------------------------------------ */\n/* block                                                               */\n/* ------------------------------------------------------------------ */\n\nexport function SideSheet({\n  className,\n  title = \"Deployments\",\n  description = \"main · Northwind Labs\",\n  deployments = DEFAULT_DEPLOYMENTS,\n  commit = \"a91f0c2\",\n}: SideSheetProps) {\n  const cardRef = useRef<HTMLDivElement | null>(null);\n  const triggerRef = useRef<HTMLButtonElement | null>(null);\n  const panelRef = useRef<HTMLDivElement | null>(null);\n  const copyTimer = useRef<number | null>(null);\n\n  const inView = useInView(cardRef, { once: true, margin: \"-10% 0px\" });\n  const reduce = Boolean(useReducedMotion());\n  const uid = useId().replace(/:/g, \"\");\n  const titleId = `${uid}-sheet-title`;\n\n  const [open, setOpen] = useState(false);\n  const [copied, setCopied] = useState(false);\n  const [rolledBack, setRolledBack] = useState(false);\n\n  const list = deployments.length > 0 ? deployments : DEFAULT_DEPLOYMENTS;\n  const current = list[0];\n\n  const close = useCallback(() => {\n    setOpen(false);\n    triggerRef.current?.focus();\n  }, []);\n\n  useEffect(() => {\n    return () => {\n      if (copyTimer.current !== null) window.clearTimeout(copyTimer.current);\n    };\n  }, []);\n\n  useEffect(() => {\n    if (!open) return;\n\n    const previousOverflow = document.body.style.overflow;\n    document.body.style.overflow = \"hidden\";\n    const focusTimer = window.setTimeout(() => {\n      panelRef.current\n        ?.querySelector<HTMLElement>(\n          'button:not([disabled]), [href], [tabindex]:not([tabindex=\"-1\"])'\n        )\n        ?.focus();\n    }, 90);\n\n    const onKeyDown = (event: KeyboardEvent) => {\n      if (event.key === \"Escape\") {\n        event.preventDefault();\n        close();\n        return;\n      }\n      if (event.key !== \"Tab\") return;\n\n      const panel = panelRef.current;\n      if (!panel) return;\n      const focusable = panel.querySelectorAll<HTMLElement>(\n        'button:not([disabled]), input:not([disabled]), [href], [tabindex]:not([tabindex=\"-1\"])'\n      );\n      if (focusable.length === 0) return;\n\n      const first = focusable[0];\n      const last = focusable[focusable.length - 1];\n      const active = document.activeElement;\n\n      if (!panel.contains(active)) {\n        event.preventDefault();\n        first.focus();\n      } else if (event.shiftKey && active === first) {\n        event.preventDefault();\n        last.focus();\n      } else if (!event.shiftKey && active === last) {\n        event.preventDefault();\n        first.focus();\n      }\n    };\n\n    document.addEventListener(\"keydown\", onKeyDown);\n    return () => {\n      document.body.style.overflow = previousOverflow;\n      window.clearTimeout(focusTimer);\n      document.removeEventListener(\"keydown\", onKeyDown);\n    };\n  }, [open, close]);\n\n  const copyCommit = () => {\n    const showCopied = () => {\n      setCopied(true);\n      if (copyTimer.current !== null) window.clearTimeout(copyTimer.current);\n      copyTimer.current = window.setTimeout(() => setCopied(false), 2000);\n    };\n\n    if (navigator.clipboard?.writeText) {\n      navigator.clipboard.writeText(commit).then(showCopied, showCopied);\n    } else {\n      showCopied();\n    }\n  };\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <motion.div\n        ref={cardRef}\n        initial={{ opacity: 0, y: 16 }}\n        animate={inView ? { opacity: 1, y: 0 } : { opacity: 0, y: 16 }}\n        transition={{ duration: 0.6, ease: EASE }}\n        className={cn(\n          \"w-full rounded-xl border border-border bg-card p-5 text-card-foreground sm:p-6\",\n          className\n        )}\n      >\n        <div className=\"flex flex-wrap items-start justify-between gap-x-4 gap-y-2\">\n          <div className=\"min-w-0\">\n            <h2 className=\"text-[15px] font-semibold tracking-[-0.01em]\">{title}</h2>\n            <p className=\"mt-0.5 text-[12.5px] text-muted-foreground\">{description}</p>\n          </div>\n          <span className=\"rounded-md border border-border px-2 py-1 text-[11px] tabular-nums text-muted-foreground\">\n            3 this week\n          </span>\n        </div>\n\n        <div className=\"mt-4 divide-y divide-border overflow-hidden rounded-lg border border-border\">\n          {list.map((deployment, index) => {\n            const isCurrent = index === 0;\n            const live = deployment.status === \"Live\" || deployment.status === \"Ready\";\n            const rowClass = cn(\n              \"flex w-full items-center gap-3 px-3 py-2.5 text-left\",\n              isCurrent\n                ? \"transition-colors hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring\"\n                : \"text-muted-foreground\"\n            );\n            const content = (\n              <>\n                <span\n                  className={cn(\n                    \"h-1.5 w-1.5 flex-none rounded-full\",\n                    live ? \"bg-success\" : \"bg-muted-foreground/40\"\n                  )}\n                  aria-hidden=\"true\"\n                />\n                <span className=\"min-w-0 flex-1\">\n                  <span className=\"flex flex-wrap items-baseline gap-x-2\">\n                    <span className=\"break-all font-mono text-[12.5px] text-foreground\">\n                      {deployment.id}\n                    </span>\n                    <span className=\"text-[11.5px] text-muted-foreground\">\n                      {deployment.environment}\n                    </span>\n                  </span>\n                  <span className=\"mt-0.5 block text-[11px] text-muted-foreground\">\n                    {deployment.time}\n                  </span>\n                </span>\n                <span\n                  className={cn(\n                    \"flex-none text-[11px]\",\n                    live ? \"text-success\" : \"text-muted-foreground\"\n                  )}\n                >\n                  {deployment.status}\n                </span>\n                {isCurrent ? (\n                  <>\n                    <span className=\"hidden flex-none text-[11px] font-medium text-foreground sm:inline\">\n                      View log\n                    </span>\n                    <ChevronRight\n                      className=\"h-3.5 w-3.5 flex-none text-muted-foreground\"\n                      aria-hidden=\"true\"\n                    />\n                  </>\n                ) : null}\n              </>\n            );\n\n            return isCurrent ? (\n              <button\n                key={deployment.id}\n                ref={triggerRef}\n                type=\"button\"\n                aria-haspopup=\"dialog\"\n                aria-expanded={open}\n                onClick={() => {\n                  setRolledBack(false);\n                  setOpen(true);\n                }}\n                className={rowClass}\n              >\n                {content}\n              </button>\n            ) : (\n              <div key={deployment.id} className={rowClass}>\n                {content}\n              </div>\n            );\n          })}\n        </div>\n\n        <p className=\"mt-3 text-[11.5px] text-muted-foreground\">\n          Last deploy {current.time} · rollback window open for 24 hours.\n        </p>\n      </motion.div>\n\n      <AnimatePresence>\n        {open ? (\n          <motion.div\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            transition={{ duration: 0.2, ease: EASE }}\n            onClick={(event) => {\n              if (event.target === event.currentTarget) close();\n            }}\n            className=\"fixed inset-0 z-50 flex justify-end bg-background/70\"\n          >\n            <motion.div\n              ref={panelRef}\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-labelledby={titleId}\n              tabIndex={-1}\n              initial={{ x: \"100%\" }}\n              animate={{ x: 0 }}\n              exit={{ x: \"100%\" }}\n              transition={{ type: \"spring\", stiffness: 360, damping: 36, mass: 0.9 }}\n              className=\"flex h-dvh w-[min(24rem,100vw)] flex-col border-l border-border bg-card text-card-foreground shadow-2xl outline-none\"\n            >\n              <div className=\"flex items-start justify-between gap-3 border-b border-border p-4\">\n                <div className=\"min-w-0\">\n                  <p className=\"flex items-center gap-1.5 text-[11px] text-muted-foreground\">\n                    <span className=\"h-1.5 w-1.5 rounded-full bg-success\" aria-hidden=\"true\" />\n                    Live in production\n                  </p>\n                  <h2\n                    id={titleId}\n                    className=\"mt-1 flex flex-wrap items-baseline gap-x-2 text-[15px] font-semibold tracking-[-0.01em]\"\n                  >\n                    Deployment\n                    <span className=\"break-all font-mono text-[13px] font-medium text-muted-foreground\">\n                      {current.id}\n                    </span>\n                  </h2>\n                </div>\n                <button\n                  type=\"button\"\n                  onClick={close}\n                  aria-label=\"Close deployment log\"\n                  className=\"grid h-7 w-7 flex-none place-items-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n                >\n                  <X className=\"h-4 w-4\" aria-hidden=\"true\" />\n                </button>\n              </div>\n\n              <div className=\"min-h-0 flex-1 overflow-y-auto p-4\">\n                <dl className=\"grid grid-cols-2 gap-x-4 gap-y-3 text-[12px]\">\n                  <div className=\"min-w-0\">\n                    <dt className=\"text-[11px] text-muted-foreground\">Environment</dt>\n                    <dd className=\"mt-0.5\">Production</dd>\n                  </div>\n                  <div className=\"min-w-0\">\n                    <dt className=\"text-[11px] text-muted-foreground\">Duration</dt>\n                    <dd className=\"mt-0.5 tabular-nums\">1m 42s</dd>\n                  </div>\n                  <div className=\"min-w-0\">\n                    <dt className=\"text-[11px] text-muted-foreground\">Branch</dt>\n                    <dd className=\"mt-0.5 font-mono text-[11.5px]\">main</dd>\n                  </div>\n                  <div className=\"min-w-0\">\n                    <dt className=\"text-[11px] text-muted-foreground\">Commit</dt>\n                    <dd className=\"mt-0.5 font-mono text-[11.5px]\">{commit}</dd>\n                  </div>\n                </dl>\n\n                <p className=\"mt-5 text-[11.5px] text-muted-foreground\">Build steps</p>\n                <ol className=\"mt-2 space-y-4\">\n                  {STEPS.map((step, index) => (\n                    <motion.li\n                      key={step.label}\n                      initial={reduce ? false : { opacity: 0, x: 8 }}\n                      animate={{ opacity: 1, x: 0 }}\n                      transition={{\n                        duration: 0.35,\n                        ease: EASE,\n                        delay: reduce ? 0 : 0.12 + index * 0.06,\n                      }}\n                      className=\"relative pl-6\"\n                    >\n                      {index < STEPS.length - 1 ? (\n                        <span\n                          aria-hidden=\"true\"\n                          className=\"absolute bottom-[-16px] left-[3px] top-2 w-px bg-border\"\n                        />\n                      ) : null}\n                      <span\n                        aria-hidden=\"true\"\n                        className=\"absolute left-0 top-0.5 grid h-2 w-2 place-items-center rounded-full border border-success bg-card\"\n                      >\n                        <span className=\"h-1 w-1 rounded-full bg-success\" />\n                      </span>\n                      <span className=\"flex items-baseline justify-between gap-3\">\n                        <span className=\"text-[12.5px]\">{step.label}</span>\n                        <span className=\"flex-none text-[11px] tabular-nums text-muted-foreground\">\n                          {step.duration}\n                        </span>\n                      </span>\n                    </motion.li>\n                  ))}\n                </ol>\n\n                <div className=\"mt-5 flex items-center gap-2.5 border-t border-border pt-4\">\n                  <span className=\"grid h-8 w-8 flex-none place-items-center rounded-full bg-muted text-[11px] font-medium\">\n                    LF\n                  </span>\n                  <div className=\"min-w-0 text-[11.5px]\">\n                    <p className=\"truncate text-foreground\">Lucas Ferreira</p>\n                    <p className=\"text-muted-foreground\">Deployed 6 minutes ago</p>\n                  </div>\n                </div>\n\n                <AnimatePresence>\n                  {rolledBack ? (\n                    <motion.p\n                      initial={{ opacity: 0, y: 4 }}\n                      animate={{ opacity: 1, y: 0 }}\n                      exit={{ opacity: 0 }}\n                      transition={{ duration: 0.25, ease: EASE }}\n                      className=\"mt-4 rounded-md border border-border bg-muted/50 px-3 py-2 text-[11.5px] text-muted-foreground\"\n                    >\n                      Rollback queued · {current.id} → 9b81e3\n                    </motion.p>\n                  ) : null}\n                </AnimatePresence>\n              </div>\n\n              <div className=\"flex items-center justify-between gap-2 border-t border-border p-4\">\n                <button\n                  type=\"button\"\n                  onClick={copyCommit}\n                  className=\"inline-flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-[12px] font-medium transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n                >\n                  {copied ? (\n                    <Check className=\"h-3.5 w-3.5 text-success\" aria-hidden=\"true\" />\n                  ) : (\n                    <Copy className=\"h-3.5 w-3.5\" aria-hidden=\"true\" />\n                  )}\n                  {copied ? \"Copied\" : \"Copy SHA\"}\n                </button>\n                <button\n                  type=\"button\"\n                  disabled={rolledBack}\n                  onClick={() => setRolledBack(true)}\n                  className=\"rounded-md bg-primary px-3 py-1.5 text-[12px] font-medium text-primary-foreground transition-colors hover:bg-primary/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card disabled:cursor-not-allowed disabled:opacity-50\"\n                >\n                  {rolledBack ? \"Rollback queued\" : \"Roll back\"}\n                </button>\n              </div>\n            </motion.div>\n          </motion.div>\n        ) : null}\n      </AnimatePresence>\n    </MotionConfig>\n  );\n}\n\nexport default SideSheet;\n"}]}