{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"elastic-sheet","type":"registry:component","title":"Elastic Sheet","description":"A side panel on a desk, a bottom sheet in your hand.","dependencies":[],"categories":["navigation","dialog","sheet","focus","filters"],"files":[{"path":"components/lab/elastic-sheet/elastic-sheet.tsx","target":"components/lab/elastic-sheet/elastic-sheet.tsx","type":"registry:component","content":"\"use client\";\n\nimport {\n  useCallback,\n  useEffect,\n  useId,\n  useRef,\n  useSyncExternalStore,\n  type PointerEvent as ReactPointerEvent,\n  type ReactNode,\n} from \"react\";\nimport { createPortal } from \"react-dom\";\nimport \"./elastic-sheet.css\";\n\nexport type ElasticSheetProps = {\n  open: boolean;\n  onOpenChange: (open: boolean) => void;\n  title: string;\n  description?: string;\n  children: ReactNode;\n  /** Clicking the backdrop closes the sheet. Default true. */\n  closeOnBackdrop?: boolean;\n  /** Drag the mobile grab handle down to dismiss. Default false. */\n  swipeToDismiss?: boolean;\n  /** A wider desktop sheet; mobile remains a bottom sheet. */\n  size?: \"regular\" | \"wide\";\n  className?: string;\n};\n\nconst FOCUSABLE =\n  'a[href],button:not([disabled]),textarea:not([disabled]),input:not([disabled]),select:not([disabled]),[tabindex]:not([tabindex=\"-1\"])';\n\nlet lockCount = 0;\nlet restoreBody: (() => void) | null = null;\n\nfunction lockPage() {\n  if (typeof document === \"undefined\") return () => {};\n  lockCount += 1;\n  if (lockCount === 1) {\n    const body = document.body;\n    const html = document.documentElement;\n    const scrollbar = window.innerWidth - html.clientWidth;\n    const previous = {\n      bodyOverflow: body.style.overflow,\n      bodyPadding: body.style.paddingRight,\n      htmlOverflow: html.style.overflow,\n    };\n    body.style.overflow = \"hidden\";\n    html.style.overflow = \"hidden\";\n    if (scrollbar > 0) body.style.paddingRight = `${scrollbar}px`;\n    restoreBody = () => {\n      body.style.overflow = previous.bodyOverflow;\n      body.style.paddingRight = previous.bodyPadding;\n      html.style.overflow = previous.htmlOverflow;\n      restoreBody = null;\n    };\n  }\n  let released = false;\n  return () => {\n    if (released) return;\n    released = true;\n    lockCount = Math.max(0, lockCount - 1);\n    if (lockCount === 0) restoreBody?.();\n  };\n}\n\nconst noopSubscribe = () => () => {};\nfunction useClientReady() {\n  return useSyncExternalStore(\n    noopSubscribe,\n    () => true,\n    () => false,\n  );\n}\n\n/**\n * ELASTIC SHEET\n *\n * A side sheet on a wide viewport and a bottom sheet on a narrow one.\n * The panel lands with a short damped spring; the backdrop only changes\n * opacity, so the page behind keeps its context. Focus is trapped while\n * open, Escape closes, and focus returns to the trigger. The mobile\n * grab handle is inert unless `swipeToDismiss` is explicitly enabled.\n */\nexport function ElasticSheet({\n  open,\n  onOpenChange,\n  title,\n  description,\n  children,\n  closeOnBackdrop = true,\n  swipeToDismiss = false,\n  size = \"regular\",\n  className,\n}: ElasticSheetProps) {\n  const uid = useId();\n  const ready = useClientReady();\n  const panelRef = useRef<HTMLDivElement>(null);\n  const closeRef = useRef<HTMLButtonElement>(null);\n  const returnFocus = useRef<HTMLElement | null>(null);\n  const wasOpen = useRef(open);\n  const drag = useRef({ startY: 0, delta: 0, active: false });\n\n  const close = useCallback(() => onOpenChange(false), [onOpenChange]);\n\n  useEffect(() => {\n    if (open) {\n      returnFocus.current =\n        document.activeElement instanceof HTMLElement\n          ? document.activeElement\n          : null;\n      const panel = panelRef.current;\n      if (panel) {\n        panel.style.transform = \"\";\n        panel.style.transition = \"\";\n      }\n      const timer = window.setTimeout(() => closeRef.current?.focus(), 30);\n      return () => window.clearTimeout(timer);\n    }\n    if (!wasOpen.current) return;\n    const target = returnFocus.current;\n    const timer = window.setTimeout(() => {\n      if (target?.isConnected) target.focus();\n    }, 20);\n    return () => window.clearTimeout(timer);\n  }, [open]);\n\n  useEffect(() => {\n    wasOpen.current = open;\n  }, [open]);\n\n  useEffect(() => {\n    if (!open) return;\n    return lockPage();\n  }, [open]);\n\n  useEffect(() => {\n    if (!open) return;\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      const panel = panelRef.current;\n      if (!panel) return;\n      const nodes = [...panel.querySelectorAll<HTMLElement>(FOCUSABLE)].filter(\n        (node) => node.getClientRects().length > 0,\n      );\n      if (!nodes.length) {\n        event.preventDefault();\n        panel.focus();\n        return;\n      }\n      const first = nodes[0];\n      const last = nodes[nodes.length - 1];\n      if (!panel.contains(document.activeElement)) {\n        event.preventDefault();\n        first.focus();\n      } else if (event.shiftKey && document.activeElement === first) {\n        event.preventDefault();\n        last.focus();\n      } else if (!event.shiftKey && document.activeElement === last) {\n        event.preventDefault();\n        first.focus();\n      }\n    };\n    document.addEventListener(\"keydown\", onKeyDown);\n    return () => document.removeEventListener(\"keydown\", onKeyDown);\n  }, [open, close]);\n\n  const onBackdrop = (event: React.MouseEvent<HTMLDivElement>) => {\n    if (event.target === event.currentTarget && closeOnBackdrop) close();\n  };\n\n  const onPointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {\n    if (!swipeToDismiss || event.pointerType === \"mouse\") return;\n    drag.current = { startY: event.clientY, delta: 0, active: true };\n    event.currentTarget.setPointerCapture?.(event.pointerId);\n  };\n\n  const onPointerMove = (event: ReactPointerEvent<HTMLDivElement>) => {\n    if (!drag.current.active) return;\n    const panel = panelRef.current;\n    if (!panel) return;\n    const delta = Math.max(0, event.clientY - drag.current.startY);\n    drag.current.delta = delta;\n    panel.style.transition = \"none\";\n    panel.style.transform = `translate3d(0, ${delta}px, 0)`;\n  };\n\n  const endDrag = () => {\n    if (!drag.current.active) return;\n    const panel = panelRef.current;\n    const delta = drag.current.delta;\n    drag.current.active = false;\n    if (panel) {\n      panel.style.transition = \"\";\n      panel.style.transform = \"\";\n    }\n    if (delta > 92) close();\n  };\n\n  if (!ready) return null;\n\n  return createPortal(\n    <div\n      className=\"es-root\"\n      data-visible={open ? \"true\" : \"false\"}\n      data-size={size}\n      inert={!open}\n      aria-hidden={!open}\n    >\n      <div className=\"es-backdrop\" aria-hidden=\"true\" onClick={onBackdrop} />\n      <div\n        ref={panelRef}\n        className={`es-panel${className ? ` ${className}` : \"\"}`}\n        role=\"dialog\"\n        aria-modal=\"true\"\n        aria-labelledby={`${uid}-title`}\n        aria-describedby={description ? `${uid}-description` : undefined}\n        tabIndex={-1}\n      >\n        <div\n          className=\"es-grab\"\n          aria-hidden=\"true\"\n          onPointerDown={onPointerDown}\n          onPointerMove={onPointerMove}\n          onPointerUp={endDrag}\n          onPointerCancel={endDrag}\n        >\n          <span />\n          <i />\n          <i />\n        </div>\n        <header className=\"es-head\">\n          <div>\n            <h2 id={`${uid}-title`}>{title}</h2>\n            {description ? <p id={`${uid}-description`}>{description}</p> : null}\n          </div>\n          <button\n            ref={closeRef}\n            type=\"button\"\n            className=\"es-close\"\n            aria-label=\"Close sheet\"\n            onClick={close}\n          >\n            <svg viewBox=\"0 0 20 20\" aria-hidden=\"true\" focusable=\"false\">\n              <path\n                d=\"M5 5l10 10M15 5L5 15\"\n                fill=\"none\"\n                stroke=\"currentColor\"\n                strokeWidth=\"1.6\"\n                strokeLinecap=\"round\"\n              />\n            </svg>\n          </button>\n        </header>\n        <div className=\"es-body\">{children}</div>\n      </div>\n    </div>,\n    document.body,\n  );\n}\n"},{"path":"components/lab/elastic-sheet/elastic-sheet.css","target":"components/lab/elastic-sheet/elastic-sheet.css","type":"registry:file","content":".es-root {\n  --es-ink: #23252a;\n  --es-muted: #666a72;\n  --es-line: rgba(35, 37, 42, 0.12);\n  --es-surface: #fffdf8;\n  --es-soft: #f4f1e9;\n  --es-accent: #a3602a;\n  --es-focus: #23252a;\n  --es-ease: cubic-bezier(0.16, 1, 0.3, 1);\n  position: fixed;\n  inset: 0;\n  z-index: 80;\n  visibility: hidden;\n  pointer-events: none;\n  transition: visibility 0s linear 480ms;\n  color: var(--es-ink);\n  font: inherit;\n}\n\n.es-root[data-visible=\"true\"] {\n  visibility: visible;\n  pointer-events: auto;\n  transition: visibility 0s linear 0s;\n}\n\n.es-backdrop {\n  position: absolute;\n  inset: 0;\n  background: rgba(25, 23, 18, 0.34);\n  opacity: 0;\n  transition: opacity 220ms ease;\n}\n\n.es-root[data-visible=\"true\"] .es-backdrop {\n  opacity: 1;\n}\n\n.es-panel {\n  position: absolute;\n  top: 18px;\n  right: 18px;\n  bottom: 18px;\n  display: flex;\n  flex-direction: column;\n  width: min(430px, calc(100vw - 36px));\n  max-height: calc(100dvh - 36px);\n  overflow: hidden;\n  border: 1px solid var(--es-line);\n  border-radius: 16px;\n  background: var(--es-surface);\n  box-shadow:\n    0 1px 2px rgba(25, 23, 18, 0.08),\n    0 34px 80px -40px rgba(25, 23, 18, 0.55);\n  transform: translate3d(calc(100% + 28px), 0, 0);\n  opacity: 0;\n  transition:\n    transform 420ms var(--es-ease),\n    opacity 180ms ease;\n}\n\n.es-root[data-size=\"wide\"] .es-panel {\n  width: min(540px, calc(100vw - 36px));\n}\n\n.es-root[data-visible=\"true\"] .es-panel {\n  transform: translate3d(0, 0, 0);\n  opacity: 1;\n}\n\n.es-panel:focus {\n  outline: none;\n}\n\n.es-grab {\n  display: none;\n}\n\n.es-head {\n  display: flex;\n  align-items: flex-start;\n  justify-content: space-between;\n  gap: 16px;\n  padding: 24px 24px 18px;\n}\n\n.es-head h2 {\n  margin: 0;\n  font-size: 1.25rem;\n  font-weight: 600;\n  letter-spacing: -0.02em;\n  line-height: 1.2;\n}\n\n.es-head p {\n  margin: 6px 0 0;\n  color: var(--es-muted);\n  font-size: 0.8125rem;\n  line-height: 1.5;\n}\n\n.es-close {\n  flex: none;\n  display: grid;\n  place-items: center;\n  width: 36px;\n  height: 36px;\n  margin: -4px -4px 0 0;\n  border: 1px solid transparent;\n  border-radius: 9px;\n  background: transparent;\n  color: var(--es-muted);\n  cursor: pointer;\n  transition:\n    color 150ms ease,\n    background-color 150ms ease,\n    border-color 150ms ease;\n}\n\n.es-close:hover {\n  color: var(--es-ink);\n  background: var(--es-soft);\n  border-color: var(--es-line);\n}\n\n.es-close:focus-visible {\n  outline: 2px solid var(--es-focus);\n  outline-offset: 2px;\n}\n\n.es-close svg {\n  width: 18px;\n  height: 18px;\n}\n\n.es-body {\n  flex: 1;\n  min-height: 0;\n  overflow-y: auto;\n  overscroll-behavior: contain;\n  padding: 0 24px 24px;\n  border-top: 1px solid var(--es-line);\n  scrollbar-width: thin;\n}\n\n@media (max-width: 640px) {\n  .es-panel {\n    top: auto;\n    right: 0;\n    bottom: 0;\n    left: 0;\n    width: 100%;\n    max-height: min(88dvh, 760px);\n    border-radius: 20px 20px 0 0;\n    border-bottom: 0;\n    transform: translate3d(0, calc(100% + 12px), 0);\n    transition:\n      transform 460ms var(--es-ease),\n      opacity 180ms ease;\n  }\n\n  .es-root[data-size=\"wide\"] .es-panel {\n    width: 100%;\n  }\n\n  .es-root[data-visible=\"true\"] .es-panel {\n    transform: translate3d(0, 0, 0);\n  }\n\n  .es-grab {\n    display: grid;\n    justify-items: center;\n    gap: 3px;\n    padding: 10px 0 4px;\n    touch-action: none;\n    cursor: grab;\n  }\n\n  .es-grab span {\n    width: 38px;\n    height: 4px;\n    border-radius: 999px;\n    background: rgba(35, 37, 42, 0.2);\n  }\n\n  .es-grab i {\n    display: block;\n    width: 16px;\n    height: 1px;\n    background: rgba(35, 37, 42, 0.1);\n  }\n\n  .es-head {\n    padding: 10px 20px 16px;\n  }\n\n  .es-body {\n    padding: 0 20px 20px;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .es-panel,\n  .es-backdrop {\n    transition-duration: 0.01ms;\n  }\n\n  .es-root[data-visible=\"true\"] .es-panel {\n    transform: none;\n  }\n}\n"}]}