{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"expand-gallery","type":"registry:ui","title":"Expand Gallery","description":"A row of tall panels where the hovered or focused one widens to show its title and caption.","dependencies":["motion"],"registryDependencies":["https://ui.mekaigames.com/r/theme.json"],"files":[{"path":"components/ui/expand-gallery.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { useId, useRef, useState, type CSSProperties, type KeyboardEvent, type ReactNode } from \"react\";\n\nexport type ExpandItem = {\n  id?: string;\n  title: string;\n  caption?: string;\n  /** Small label above the title. */\n  eyebrow?: string;\n  /** Image URL, shown as the panel background. */\n  src?: string;\n  alt?: string;\n  /** Any panel background. Takes priority over src. */\n  content?: ReactNode;\n};\n\ntype ExpandGalleryProps = {\n  items: ExpandItem[];\n  /** How many times wider the open panel is than a closed one. */\n  expandedRatio?: number;\n  /** Row height in pixels. The stacked layout on narrow containers is a bit taller. */\n  height?: number;\n  /** Panel that stays open while nothing is hovered or focused. */\n  defaultIndex?: number;\n  /** Called when a panel is clicked or chosen with Enter. */\n  onSelect?: (index: number) => void;\n  /** Accessible name of the gallery. */\n  label?: string;\n  className?: string;\n};\n\nfunction Media({ item }: { item: ExpandItem }) {\n  if (item.content !== undefined) return <>{item.content}</>;\n  if (item.src) {\n    return <span role=\"img\" aria-label={item.alt ?? \"\"} className=\"block size-full bg-cover bg-center\" style={{ backgroundImage: `url(\"${item.src}\")` }} />;\n  }\n  return null;\n}\n\nexport function ExpandGallery({\n  items,\n  expandedRatio = 4,\n  height = 380,\n  defaultIndex = 0,\n  onSelect,\n  label = \"Gallery\",\n  className = \"\",\n}: ExpandGalleryProps) {\n  const autoId = useId();\n  const reduce = Boolean(useReducedMotion());\n  const [pinned, setPinned] = useState(defaultIndex);\n  const [hovered, setHovered] = useState<number | null>(null);\n  const [focused, setFocused] = useState<number | null>(null);\n  const panels = useRef<(HTMLButtonElement | null)[]>([]);\n  const open = hovered ?? focused ?? pinned;\n  const ratio = Math.max(1.2, expandedRatio);\n\n  function onKeyDown(i: number, e: KeyboardEvent<HTMLButtonElement>) {\n    const last = items.length - 1;\n    let next: number | null = null;\n    if (e.key === \"ArrowRight\" || e.key === \"ArrowDown\") next = i === last ? 0 : i + 1;\n    else if (e.key === \"ArrowLeft\" || e.key === \"ArrowUp\") next = i === 0 ? last : i - 1;\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = last;\n    if (next === null) return;\n    e.preventDefault();\n    panels.current[next]?.focus();\n  }\n\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, stiffness: 210, damping: 28, mass: 0.9 };\n\n  return (\n    <div className={`@container w-full ${className}`}>\n      <div\n        role=\"group\"\n        aria-label={label}\n        onPointerLeave={() => setHovered(null)}\n        className=\"flex h-[calc(var(--h)*1.35)] flex-col gap-2 @xl:h-[var(--h)] @xl:flex-row\"\n        style={{ \"--h\": `${height}px` } as CSSProperties}\n      >\n        {items.map((item, i) => {\n          const isOpen = open === i;\n          return (\n            <motion.button\n              key={item.id ?? i}\n              ref={(el) => {\n                panels.current[i] = el;\n              }}\n              type=\"button\"\n              id={`${autoId}-${i}`}\n              aria-expanded={isOpen}\n              onPointerEnter={(e) => {\n                if (e.pointerType === \"mouse\") setHovered(i);\n              }}\n              onFocus={() => setFocused(i)}\n              onBlur={() => setFocused((f) => (f === i ? null : f))}\n              onClick={() => {\n                setPinned(i);\n                onSelect?.(i);\n              }}\n              onKeyDown={(e) => onKeyDown(i, e)}\n              className=\"group relative min-h-0 min-w-0 overflow-hidden rounded-2xl bg-ink-800 text-left ring-1 ring-inset ring-white/5\"\n              style={{ flexBasis: 0 }}\n              initial={false}\n              animate={{ flexGrow: isOpen ? ratio : 1 }}\n              transition={spring}\n            >\n              <span className=\"absolute inset-0 transition-transform duration-700 ease-out group-hover:scale-105\">\n                <Media item={item} />\n              </span>\n              <motion.span\n                aria-hidden=\"true\"\n                className=\"pointer-events-none absolute inset-0 bg-gradient-to-t from-ink-950/90 via-ink-950/30 to-ink-950/10\"\n                initial={false}\n                animate={{ opacity: isOpen ? 1 : 0.55 }}\n                transition={{ duration: reduce ? 0 : 0.3 }}\n              />\n              <motion.span\n                aria-hidden=\"true\"\n                className=\"pointer-events-none absolute inset-0 bg-ink-950\"\n                initial={false}\n                animate={{ opacity: isOpen ? 0 : 0.45 }}\n                transition={{ duration: reduce ? 0 : 0.3 }}\n              />\n\n              {/* Closed panels show the title on its side; the open one shows everything. */}\n              <motion.span\n                aria-hidden=\"true\"\n                className=\"pointer-events-none absolute inset-0 flex items-center px-4 @xl:items-end @xl:justify-center @xl:px-0 @xl:pb-5\"\n                initial={false}\n                animate={{ opacity: isOpen ? 0 : 1 }}\n                transition={{ duration: reduce ? 0 : 0.2, delay: isOpen || reduce ? 0 : 0.15 }}\n              >\n                <span className=\"flex items-center gap-2 whitespace-nowrap font-display text-sm font-bold text-bone @xl:rotate-180 @xl:[writing-mode:vertical-rl]\">\n                  <span className=\"font-display text-xs tabular-nums text-bone-dim\">{String(i + 1).padStart(2, \"0\")}</span>\n                  {item.title}\n                </span>\n              </motion.span>\n\n              <motion.span\n                className=\"absolute inset-x-0 bottom-0 block p-5 @xl:p-6\"\n                initial={false}\n                animate={isOpen ? { opacity: 1, y: 0 } : { opacity: 0, y: reduce ? 0 : 14 }}\n                transition={{ duration: reduce ? 0 : 0.3, delay: isOpen && !reduce ? 0.18 : 0 }}\n              >\n                {item.eyebrow ? (\n                  <span className=\"mb-2 block text-[0.68rem] font-bold uppercase tracking-[0.24em] text-ember\">{item.eyebrow}</span>\n                ) : null}\n                <span className=\"block font-display text-xl font-extrabold leading-tight text-bone @xl:text-2xl\">{item.title}</span>\n                {item.caption ? <span className=\"mt-1.5 block max-w-[40ch] text-sm leading-relaxed text-bone-muted\">{item.caption}</span> : null}\n              </motion.span>\n            </motion.button>\n          );\n        })}\n      </div>\n    </div>\n  );\n}\n"}]}