{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "modal-shared-layout",
  "type": "registry:component",
  "title": "Shared Layout Modal",
  "description": "Cards that grow into a modal and shrink back into the same spot. The card morphs by measuring its box, the content crossfades, and everything stays inside its own frame.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "modal",
    "shared layout",
    "morph",
    "card",
    "transition",
    "dialog"
  ],
  "docs": "https://hyperblur.dev/effects/modal-shared-layout",
  "files": [
    {
      "path": "registry/hyperblur/modal-shared-layout.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/modal-shared-layout.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SharedLayoutCard {\n  id: string;\n  eyebrow?: string;\n  title: string;\n  from?: string;\n  to?: string;\n  body?: React.ReactNode;\n  action?: string;\n}\n\nexport interface ModalSharedLayoutProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  cards?: SharedLayoutCard[];\n  value?: string | null;\n  defaultValue?: string | null;\n  onChange?: (id: string | null) => void;\n  height?: number;\n  autoDemo?: number;\n  accent?: string;\n}\n\nconst defaults: SharedLayoutCard[] = [\n  {\n    id: \"weekend\",\n    eyebrow: \"Guide\",\n    title: \"A slow weekend in Lisbon\",\n    from: \"#ff9a62\",\n    to: \"#7a2f6b\",\n    body: \"Start with coffee in Alfama, ride tram 28 before the crowds, and book dinner in Principe Real by Thursday. Everything is walkable.\",\n    action: \"Save itinerary\",\n  },\n  {\n    id: \"kit\",\n    eyebrow: \"Pack list\",\n    title: \"The rain-ready travel kit\",\n    from: \"#6fd0c4\",\n    to: \"#14304f\",\n    body: \"A packable shell, quick-dry socks, a dry bag for your phone and one pair of shoes you do not mind soaking. That covers most trips.\",\n    action: \"Add to trip\",\n  },\n];\n\nconst css = `\n.hb-za7 {\n  --hb-za7-c: #2f7bff;\n  --hb-za7-h: 200px;\n  box-sizing: border-box;\n  position: relative;\n  width: 100%;\n  height: var(--hb-za7-h);\n  overflow: hidden;\n  font-family: inherit;\n  color: #ededed;\n  background: #0d0d0d;\n  border: 1px solid #262626;\n  border-radius: 18px;\n  isolation: isolate;\n}\n.hb-za7 *, .hb-za7 *::before, .hb-za7 *::after { box-sizing: border-box; }\n.hb-za7-grid { display: grid; grid-template-columns: repeat(var(--hb-za7-n), minmax(0, 1fr)); gap: 10px; height: 100%; padding: 10px; }\n.hb-za7-card {\n  position: relative;\n  display: flex;\n  flex-direction: column;\n  justify-content: space-between;\n  min-width: 0;\n  margin: 0;\n  padding: 12px;\n  overflow: hidden;\n  font: inherit;\n  color: #ffffff;\n  text-align: left;\n  background: linear-gradient(155deg, var(--from), var(--to));\n  border: 1px solid rgba(255, 255, 255, 0.1);\n  border-radius: 14px;\n  cursor: pointer;\n  transition: transform 0.3s cubic-bezier(0.22, 0.9, 0.24, 1), box-shadow 0.3s ease;\n}\n.hb-za7-card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4); }\n.hb-za7-card:active { transform: scale(0.98); }\n.hb-za7-card:focus-visible { outline: 2px solid var(--hb-za7-c); outline-offset: 2px; }\n.hb-za7-card[data-hidden=\"true\"] { visibility: hidden; }\n.hb-za7-card::after {\n  content: \"\";\n  position: absolute;\n  right: -28px;\n  bottom: -34px;\n  width: 110px;\n  height: 110px;\n  background: radial-gradient(circle, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 68%);\n  pointer-events: none;\n}\n.hb-za7-eyebrow { display: block; font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: rgba(255, 255, 255, 0.72); }\n.hb-za7-title { display: block; margin-top: 4px; font-size: 17px; font-weight: 650; line-height: 1.15; letter-spacing: -0.02em; text-wrap: balance; }\n.hb-za7-more {\n  position: relative;\n  z-index: 1;\n  align-self: flex-start;\n  display: inline-flex;\n  align-items: center;\n  gap: 5px;\n  padding: 4px 9px;\n  font-size: 11px;\n  font-weight: 600;\n  color: #ffffff;\n  background: rgba(0, 0, 0, 0.32);\n  border-radius: 999px;\n  backdrop-filter: blur(6px);\n  -webkit-backdrop-filter: blur(6px);\n}\n.hb-za7-more svg { width: 10px; height: 10px; }\n.hb-za7-scrim {\n  position: absolute;\n  inset: 0;\n  z-index: 5;\n  background: rgba(0, 0, 0, 0.6);\n  opacity: 1;\n  transition: opacity 0.28s ease;\n  animation: hb-za7-fade 0.3s ease backwards;\n}\n.hb-za7-scrim[data-closing=\"true\"] { opacity: 0; }\n.hb-za7-shell {\n  position: absolute;\n  z-index: 6;\n  left: 10px;\n  top: 10px;\n  right: 10px;\n  bottom: 10px;\n  overflow: hidden;\n  color: #ffffff;\n  background: linear-gradient(155deg, var(--from), var(--to));\n  border: 1px solid rgba(255, 255, 255, 0.12);\n  border-radius: 16px;\n  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);\n  outline: none;\n}\n.hb-za7-head { position: absolute; left: 0; right: 0; top: 0; padding: 12px; padding-right: 48px; }\n.hb-za7-sheet {\n  position: absolute;\n  left: 0;\n  right: 0;\n  bottom: 0;\n  top: 66px;\n  display: flex;\n  flex-direction: column;\n  gap: 10px;\n  padding: 12px;\n  overflow: auto;\n  color: #d4d4d4;\n  background: #121212;\n  border-radius: 14px 14px 0 0;\n  box-shadow: 0 -1px 0 rgba(255, 255, 255, 0.08);\n  animation: hb-za7-sheet 0.42s cubic-bezier(0.22, 0.9, 0.24, 1) 0.14s backwards;\n  transition: opacity 0.18s ease, transform 0.25s ease;\n}\n.hb-za7-shell[data-closing=\"true\"] .hb-za7-sheet { opacity: 0; transform: translateY(12px); }\n.hb-za7-body { margin: 0; font-size: 12.5px; line-height: 1.5; }\n.hb-za7-cta {\n  align-self: flex-start;\n  margin: 0;\n  padding: 7px 14px;\n  font: inherit;\n  font-size: 12px;\n  font-weight: 600;\n  color: #0a0a0a;\n  background: #ededed;\n  border: 0;\n  border-radius: 999px;\n  cursor: pointer;\n  transition: background 0.2s ease, transform 0.2s ease;\n}\n.hb-za7-cta:hover { background: #ffffff; }\n.hb-za7-cta:active { transform: scale(0.96); }\n.hb-za7-cta:focus-visible { outline: 2px solid var(--hb-za7-c); outline-offset: 2px; }\n.hb-za7-x {\n  position: absolute;\n  top: 10px;\n  right: 10px;\n  z-index: 2;\n  display: grid;\n  place-items: center;\n  width: 28px;\n  height: 28px;\n  margin: 0;\n  padding: 0;\n  color: #ffffff;\n  background: rgba(0, 0, 0, 0.35);\n  border: 0;\n  border-radius: 999px;\n  cursor: pointer;\n  backdrop-filter: blur(6px);\n  -webkit-backdrop-filter: blur(6px);\n  transition: background 0.2s ease, opacity 0.2s ease, transform 0.2s ease;\n  animation: hb-za7-fade 0.3s ease 0.2s backwards;\n}\n.hb-za7-x:hover { background: rgba(0, 0, 0, 0.55); }\n.hb-za7-x:active { transform: scale(0.92); }\n.hb-za7-x:focus-visible { outline: 2px solid #ffffff; outline-offset: 2px; }\n.hb-za7-shell[data-closing=\"true\"] .hb-za7-x { opacity: 0; }\n.hb-za7-x svg { width: 12px; height: 12px; }\n@keyframes hb-za7-fade { from { opacity: 0; } to { opacity: 1; } }\n@keyframes hb-za7-sheet { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-za7-card, .hb-za7-scrim, .hb-za7-sheet, .hb-za7-x, .hb-za7-cta { transition: none; animation: none; }\n}\n`;\n\nconst easing = \"cubic-bezier(0.22, 0.9, 0.24, 1)\";\nconst INSET = 10;\n\nexport function ModalSharedLayout({\n  cards,\n  value,\n  defaultValue = null,\n  onChange,\n  height = 200,\n  autoDemo = 0,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  onPointerEnter,\n  onPointerLeave,\n  onFocus,\n  onBlur,\n  ...rest\n}: ModalSharedLayoutProps) {\n  const items = cards && cards.length ? cards : defaults;\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState<string | null>(defaultValue);\n  const active = controlled ? value : inner;\n  const [shown, setShown] = React.useState<string | null>(active);\n  const frameRef = React.useRef<HTMLDivElement>(null);\n  const shellRef = React.useRef<HTMLDivElement>(null);\n  const scrimRef = React.useRef<HTMLDivElement>(null);\n  const closeRef = React.useRef<HTMLButtonElement>(null);\n  const cardRefs = React.useRef(new Map<string, HTMLButtonElement>());\n  const opened = React.useRef<string | null>(null);\n  const closingRef = React.useRef(false);\n  const [busy, setBusy] = React.useState(false);\n  const latest = React.useRef(onChange);\n\n  React.useEffect(() => {\n    latest.current = onChange;\n  }, [onChange]);\n\n  if (active !== null && shown !== active) setShown(active);\n\n  const setActive = React.useCallback(\n    (id: string | null) => {\n      if (!controlled) setInner(id);\n      latest.current?.(id);\n    },\n    [controlled],\n  );\n\n  function rectOf(el: HTMLElement) {\n    const frame = frameRef.current as HTMLDivElement;\n    const f = frame.getBoundingClientRect();\n    const r = el.getBoundingClientRect();\n    return {\n      left: r.left - f.left - frame.clientLeft,\n      top: r.top - f.top - frame.clientTop,\n      width: r.width,\n      height: r.height,\n    };\n  }\n\n  React.useLayoutEffect(() => {\n    const frame = frameRef.current;\n    const shell = shellRef.current;\n    if (!frame || !shell || !shown) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const card = cardRefs.current.get(shown);\n    const finalRect = {\n      left: INSET,\n      top: INSET,\n      width: frame.clientWidth - INSET * 2,\n      height: frame.clientHeight - INSET * 2,\n    };\n    if (active === shown && opened.current !== shown) {\n      opened.current = shown;\n      closeRef.current?.focus({ preventScroll: true });\n      if (!card || reduce) return;\n      const from = rectOf(card);\n      shell.animate(\n        [\n          { left: `${from.left}px`, top: `${from.top}px`, width: `${from.width}px`, height: `${from.height}px`, borderRadius: \"14px\" },\n          { left: `${finalRect.left}px`, top: `${finalRect.top}px`, width: `${finalRect.width}px`, height: `${finalRect.height}px`, borderRadius: \"16px\" },\n        ],\n        { duration: 520, easing },\n      );\n    } else if (active === null && !closingRef.current) {\n      closingRef.current = true;\n      shell.dataset.closing = \"true\";\n      if (scrimRef.current) scrimRef.current.dataset.closing = \"true\";\n      const done = () => {\n        opened.current = null;\n        closingRef.current = false;\n        setShown(null);\n        cardRefs.current.get(shown)?.focus({ preventScroll: true });\n      };\n      if (!card || reduce) {\n        done();\n        return;\n      }\n      const to = rectOf(card);\n      const anim = shell.animate(\n        [\n          { left: `${finalRect.left}px`, top: `${finalRect.top}px`, width: `${finalRect.width}px`, height: `${finalRect.height}px`, borderRadius: \"16px\" },\n          { left: `${to.left}px`, top: `${to.top}px`, width: `${to.width}px`, height: `${to.height}px`, borderRadius: \"14px\" },\n        ],\n        { duration: 420, easing, fill: \"forwards\", delay: 60 },\n      );\n      anim.onfinish = done;\n    }\n  }, [shown, active]);\n\n  const firstId = items[0].id;\n\n  React.useEffect(() => {\n    if (!autoDemo || busy || controlled) return;\n    let id = 0;\n    let demoOpen = false;\n    function opening() {\n      id = window.setTimeout(() => {\n        demoOpen = true;\n        setActive(firstId);\n        id = window.setTimeout(() => {\n          demoOpen = false;\n          setActive(null);\n          opening();\n        }, 2600);\n      }, autoDemo);\n    }\n    opening();\n    return () => {\n      window.clearTimeout(id);\n      if (demoOpen) setActive(null);\n    };\n  }, [autoDemo, busy, controlled, firstId, setActive]);\n\n  const current = items.find((c) => c.id === shown) ?? null;\n  const open = current !== null;\n\n  const vars = {\n    \"--hb-za7-c\": accent,\n    \"--hb-za7-h\": `${height}px`,\n    \"--hb-za7-n\": items.length,\n    ...style,\n  } as React.CSSProperties;\n\n  return (\n    <div\n      ref={frameRef}\n      className={`hb-za7 ${className}`}\n      style={vars}\n      onPointerEnter={(e) => {\n        onPointerEnter?.(e);\n        setBusy(true);\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        setBusy(false);\n      }}\n      onFocus={(e) => {\n        onFocus?.(e);\n        setBusy(true);\n      }}\n      onBlur={(e) => {\n        onBlur?.(e);\n        setBusy(false);\n      }}\n      onKeyDown={(e) => {\n        onKeyDown?.(e);\n        if (!open) return;\n        if (e.key === \"Escape\") {\n          e.preventDefault();\n          e.stopPropagation();\n          setActive(null);\n        } else if (e.key === \"Tab\") {\n          const nodes = shellRef.current?.querySelectorAll<HTMLElement>(\"button\");\n          if (!nodes || !nodes.length) return;\n          const first = nodes[0];\n          const last = nodes[nodes.length - 1];\n          if (e.shiftKey && document.activeElement === first) {\n            e.preventDefault();\n            last.focus();\n          } else if (!e.shiftKey && document.activeElement === last) {\n            e.preventDefault();\n            first.focus();\n          }\n        }\n      }}\n      {...rest}\n    >\n      <style href=\"hb-modal-shared-layout\" precedence=\"default\">{css}</style>\n      <div className=\"hb-za7-grid\" inert={open}>\n        {items.map((card) => (\n          <button\n            key={card.id}\n            ref={(el) => {\n              if (el) cardRefs.current.set(card.id, el);\n              else cardRefs.current.delete(card.id);\n            }}\n            type=\"button\"\n            className=\"hb-za7-card\"\n            data-hidden={shown === card.id}\n            aria-haspopup=\"dialog\"\n            style={{ \"--from\": card.from ?? \"#2f7bff\", \"--to\": card.to ?? \"#101a33\" } as React.CSSProperties}\n            onClick={() => setActive(card.id)}\n          >\n            <span>\n              {card.eyebrow ? <span className=\"hb-za7-eyebrow\">{card.eyebrow}</span> : null}\n              <span className=\"hb-za7-title\">{card.title}</span>\n            </span>\n            <span className=\"hb-za7-more\">\n              Read\n              <svg viewBox=\"0 0 10 10\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                <path d=\"M2 5h6M5.5 2.5 8 5 5.5 7.5\" />\n              </svg>\n            </span>\n          </button>\n        ))}\n      </div>\n      {current ? (\n        <>\n          <div ref={scrimRef} className=\"hb-za7-scrim\" onClick={() => setActive(null)} />\n          <div\n            ref={shellRef}\n            className=\"hb-za7-shell\"\n            role=\"dialog\"\n            aria-modal=\"true\"\n            aria-label={current.title}\n            style={{ \"--from\": current.from ?? \"#2f7bff\", \"--to\": current.to ?? \"#101a33\" } as React.CSSProperties}\n          >\n            <div className=\"hb-za7-head\">\n              {current.eyebrow ? <span className=\"hb-za7-eyebrow\">{current.eyebrow}</span> : null}\n              <span className=\"hb-za7-title\">{current.title}</span>\n            </div>\n            <button ref={closeRef} type=\"button\" className=\"hb-za7-x\" aria-label=\"Close\" onClick={() => setActive(null)}>\n              <svg viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                <path d=\"m2.5 2.5 7 7M9.5 2.5l-7 7\" />\n              </svg>\n            </button>\n            <div className=\"hb-za7-sheet\">\n              {typeof current.body === \"string\" ? <p className=\"hb-za7-body\">{current.body}</p> : current.body}\n              {current.action ? (\n                <button type=\"button\" className=\"hb-za7-cta\" onClick={() => setActive(null)}>\n                  {current.action}\n                </button>\n              ) : null}\n            </div>\n          </div>\n        </>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ]
}