{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"hover-expand-panels","type":"registry:component","title":"Expanding Panel Row","description":"A row of art panels where the hovered, focused or tapped one springs open while its neighbours compress. Each title runs up the panel edge and swings to horizontal as it opens, with a pointer-lit spot, a depth shift in the art and arrow-key navigation. Photos optional, no dependencies.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/hover-expand-panels.tsx","content":"\"use client\";\n\nimport { useState } from \"react\";\nimport type { CSSProperties, KeyboardEvent, PointerEvent } from \"react\";\n\nexport type HoverExpandPanel = {\n  id: string;\n  label: string;\n  /** Optional photo. Without one the panel paints its own CSS art. */\n  image?: string;\n  /** One line that resolves under the title once the panel is open. */\n  caption?: string;\n  /** Optional CSS background value to use instead of the built-in art. */\n  art?: string;\n};\n\nconst ART = [\n  \"radial-gradient(120% 75% at 12% 0%, #5b8cff 0%, transparent 58%), radial-gradient(90% 80% at 95% 100%, #b04bff 0%, transparent 60%), conic-gradient(from 200deg at 62% 38%, #070a1c, #1a2a73, #070a1c)\",\n  \"radial-gradient(85% 60% at 50% 8%, #ffd9a8 0%, #ff7a45 28%, transparent 66%), linear-gradient(180deg, #2a0f1f 0%, #0c0710 100%)\",\n  \"radial-gradient(100% 70% at 80% 12%, #4be3c4 0%, transparent 55%), radial-gradient(90% 70% at 10% 95%, #1673ff 0%, transparent 60%), linear-gradient(160deg, #06151a, #05070c)\",\n  \"conic-gradient(from 20deg at 30% 70%, #1b1b22, #7a7f92 22%, #1b1b22 48%, #c8ccd8 70%, #1b1b22), linear-gradient(0deg, #0a0b0e, #0a0b0e)\",\n  \"radial-gradient(70% 55% at 30% 20%, #ff8fc3 0%, transparent 62%), radial-gradient(80% 70% at 85% 85%, #ffb347 0%, transparent 58%), linear-gradient(200deg, #3a1054, #12081f)\",\n  \"radial-gradient(90% 60% at 70% 0%, #c4f26b 0%, transparent 56%), radial-gradient(80% 70% at 5% 100%, #0f9d6c 0%, transparent 62%), linear-gradient(170deg, #0a1a10, #050a07)\",\n];\n\nconst DEFAULT_PANELS: HoverExpandPanel[] = [\n  { id: \"01\", label: \"Aurora\", caption: \"Cold light over slow water\" },\n  { id: \"02\", label: \"Ember\", caption: \"A low sun, held a moment\" },\n  { id: \"03\", label: \"Tide\", caption: \"Teal edges, deep current\" },\n  { id: \"04\", label: \"Chrome\", caption: \"Brushed metal, one sweep\" },\n  { id: \"05\", label: \"Bloom\", caption: \"Soft petals of heat\" },\n];\n\nconst EASE = \"cubic-bezier(0.22,1.25,0.36,1)\";\nconst DUR = \"650ms\";\n\nexport function HoverExpandPanels({\n  panels = DEFAULT_PANELS,\n  expandRatio = 4,\n  showLabels = true,\n  vertical = false,\n  restIndex = null,\n  className = \"\",\n}: {\n  panels?: HoverExpandPanel[];\n  expandRatio?: number;\n  /** The title that rotates from the panel edge to horizontal as it opens. */\n  showLabels?: boolean;\n  /** Stack the panels instead of laying them out in a row. */\n  vertical?: boolean;\n  /** Zero-based panel that stays open while nothing is hovered or focused. */\n  restIndex?: number | null;\n  /** Extra classes for the row. The default height is h-64; override with e.g. !h-96. */\n  className?: string;\n}) {\n  const [active, setActive] = useState<number | null>(null);\n  const open = active ?? restIndex;\n  const ratio = Math.min(Math.max(expandRatio, 1), 12);\n\n  const move = (e: KeyboardEvent<HTMLButtonElement>, i: number) => {\n    const fwd = e.key === \"ArrowRight\" || e.key === \"ArrowDown\";\n    const back = e.key === \"ArrowLeft\" || e.key === \"ArrowUp\";\n    let to = -1;\n    if (fwd) to = Math.min(i + 1, panels.length - 1);\n    else if (back) to = Math.max(i - 1, 0);\n    else if (e.key === \"Home\") to = 0;\n    else if (e.key === \"End\") to = panels.length - 1;\n    if (to < 0) return;\n    e.preventDefault();\n    const sib = e.currentTarget.parentElement?.children[to];\n    if (sib instanceof HTMLElement) sib.focus();\n  };\n\n  const track = (e: PointerEvent<HTMLButtonElement>) => {\n    if (e.pointerType === \"touch\") return;\n    const el = e.currentTarget;\n    const r = el.getBoundingClientRect();\n    if (!r.width || !r.height) return;\n    // Layout pixels: ancestors may be transform-scaled.\n    const kx = el.offsetWidth / r.width;\n    const ky = el.offsetHeight / r.height;\n    const x = (e.clientX - r.left) * kx;\n    const y = (e.clientY - r.top) * ky;\n    el.style.setProperty(\"--hx\", x.toFixed(1));\n    el.style.setProperty(\"--hy\", y.toFixed(1));\n    el.style.setProperty(\"--nx\", ((x / el.offsetWidth) * 2 - 1).toFixed(3));\n    el.style.setProperty(\"--ny\", ((y / el.offsetHeight) * 2 - 1).toFixed(3));\n  };\n\n  return (\n    <div\n      role=\"group\"\n      aria-label=\"Expanding panels\"\n      onPointerLeave={(e) => {\n        if (e.pointerType !== \"touch\") setActive(null);\n      }}\n      className={\n        \"flex h-64 w-full gap-1.5 \" + (vertical ? \"flex-col \" : \"flex-row \") + className\n      }\n    >\n      {panels.map((panel, i) => {\n        const isOpen = open === i;\n        const dim = open !== null && !isOpen;\n        const art = panel.art ?? ART[i % ART.length] ?? \"\";\n        const titleTransform = vertical\n          ? isOpen\n            ? \"translate(4px, 0px) scale(1.45)\"\n            : \"translate(0px, 0px) scale(1)\"\n          : isOpen\n            ? \"translate(4px, -38px) rotate(0deg) scale(1.45)\"\n            : \"translate(1em, 0px) rotate(-90deg) scale(1)\";\n        const titleStyle: CSSProperties = {\n          left: vertical ? (isOpen ? 20 : 44) : 17,\n          bottom: vertical ? (isOpen ? 48 : \"calc(50% - 0.5em)\") : 18,\n          transform: titleTransform,\n          transformOrigin: \"0 100%\",\n          transition: `transform ${DUR} ${EASE}, bottom ${DUR} ${EASE}, left ${DUR} ${EASE}, opacity 300ms ease`,\n          opacity: showLabels ? 1 : 0,\n          textShadow: \"0 1px 12px rgba(0,0,0,0.45)\",\n        };\n        return (\n          <button\n            key={panel.id}\n            type=\"button\"\n            aria-label={panel.label}\n            aria-expanded={isOpen}\n            onPointerEnter={(e) => {\n              if (e.pointerType === \"touch\") return;\n              setActive(i);\n              e.currentTarget.style.setProperty(\"--lit\", \"1\");\n              track(e);\n            }}\n            onPointerMove={track}\n            onPointerLeave={(e) => {\n              e.currentTarget.style.setProperty(\"--lit\", \"0\");\n              e.currentTarget.style.setProperty(\"--nx\", \"0\");\n              e.currentTarget.style.setProperty(\"--ny\", \"0\");\n            }}\n            onClick={() => setActive(i)}\n            onFocus={() => setActive(i)}\n            onBlur={() => setActive(null)}\n            onKeyDown={(e) => move(e, i)}\n            className=\"group relative min-h-0 min-w-0 cursor-pointer overflow-hidden rounded-xl border-0 bg-[#0b0c10] p-0 text-left text-white outline-none transition-[flex-grow] duration-[650ms] ease-[cubic-bezier(0.22,1.25,0.36,1)] focus-visible:!outline-2 focus-visible:!-outline-offset-4 focus-visible:!outline-white motion-reduce:transition-none\"\n            style={{\n              flexGrow: isOpen ? ratio : 1,\n              flexBasis: 0,\n              boxShadow: isOpen\n                ? \"inset 0 0 0 1px rgba(255,255,255,0.2), 0 18px 40px -18px rgba(0,0,0,0.6)\"\n                : \"inset 0 0 0 1px rgba(255,255,255,0.08)\",\n              [\"--hx\" as string]: \"0\",\n              [\"--hy\" as string]: \"0\",\n              [\"--nx\" as string]: \"0\",\n              [\"--ny\" as string]: \"0\",\n              [\"--lit\" as string]: \"0\",\n            }}\n          >\n            {/* Art layer: oversized so the pointer parallax never shows an edge. */}\n            <span\n              aria-hidden\n              className=\"absolute -inset-[7%] block motion-reduce:!transform-none motion-reduce:!transition-none\"\n              style={{\n                background: art,\n                transform:\n                  \"translate3d(calc(var(--nx) * -9px), calc(var(--ny) * -9px), 0) scale(\" +\n                  (isOpen ? 1.04 : 1.12) +\n                  \")\",\n                transition: `transform 520ms cubic-bezier(0.22,1,0.36,1)`,\n              }}\n            >\n              {panel.image ? (\n                // eslint-disable-next-line @next/next/no-img-element\n                <img src={panel.image} alt=\"\" loading=\"lazy\" className=\"absolute inset-0 h-full w-full object-cover\" />\n              ) : null}\n            </span>\n\n            {/* Pointer-lit spot, only on the open panel. */}\n            <span\n              aria-hidden\n              className=\"pointer-events-none absolute left-0 top-0 block h-[260px] w-[260px] motion-reduce:hidden\"\n              style={{\n                transform: \"translate3d(calc(var(--hx) * 1px - 130px), calc(var(--hy) * 1px - 130px), 0)\",\n                background: \"radial-gradient(circle, rgba(255,255,255,0.26), rgba(255,255,255,0) 64%)\",\n                mixBlendMode: \"soft-light\",\n                opacity: isOpen ? \"var(--lit)\" : 0,\n                transition: \"opacity 300ms ease\",\n              }}\n            />\n\n            {/* Legibility scrim, deeper when open. */}\n            <span\n              aria-hidden\n              className=\"absolute inset-0 block\"\n              style={{\n                background:\n                  \"linear-gradient(0deg, rgba(0,0,0,0.62) 0%, rgba(0,0,0,0.12) 46%, rgba(0,0,0,0.28) 100%)\",\n                opacity: isOpen ? 1 : 0.8,\n                transition: \"opacity 400ms ease\",\n              }}\n            />\n\n            {/* Neighbours settle back a touch so the open panel carries the light. */}\n            <span\n              aria-hidden\n              className=\"absolute inset-0 block bg-black\"\n              style={{ opacity: dim ? 0.34 : 0, transition: \"opacity 400ms ease\" }}\n            />\n\n            <span className=\"absolute left-4 top-4 font-mono text-[10px] tracking-[0.14em] text-white/75\" style={{ fontFamily: \"ui-monospace, SFMono-Regular, Menlo, monospace\" }}>\n              {panel.id}\n            </span>\n\n            <span\n              aria-hidden\n              className=\"absolute right-3 top-3 flex h-7 w-7 items-center justify-center rounded-full motion-reduce:!transition-none\"\n              style={{\n                background: \"rgba(255,255,255,0.16)\",\n                boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.22)\",\n                opacity: isOpen ? 1 : 0,\n                transform: isOpen ? \"scale(1)\" : \"scale(0.6)\",\n                transition: `opacity 260ms ease ${isOpen ? \"200ms\" : \"0ms\"}, transform 420ms ${EASE} ${isOpen ? \"200ms\" : \"0ms\"}`,\n              }}\n            >\n              <svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"#fff\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                <path d=\"M3 9 9 3M4.5 3H9v4.5\" />\n              </svg>\n            </span>\n\n            <span\n              aria-hidden\n              className=\"pointer-events-none absolute whitespace-nowrap text-base font-semibold leading-none tracking-tight motion-reduce:!transition-none\"\n              style={titleStyle}\n            >\n              {panel.label}\n            </span>\n\n            {showLabels && panel.caption ? (\n              <span\n                aria-hidden\n                className=\"pointer-events-none absolute left-5 right-4 bottom-4 block text-xs leading-snug text-white/70 motion-reduce:!transition-none\"\n                style={{\n                  opacity: isOpen ? 1 : 0,\n                  transform: isOpen ? \"translateY(0)\" : \"translateY(6px)\",\n                  transition: isOpen\n                    ? \"opacity 300ms ease 220ms, transform 500ms cubic-bezier(0.22,1,0.36,1) 220ms\"\n                    : \"opacity 120ms ease, transform 120ms ease\",\n                  display: vertical && !isOpen ? \"none\" : undefined,\n                }}\n              >\n                {panel.caption}\n              </span>\n            ) : null}\n          </button>\n        );\n      })}\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/hover-expand-panels.tsx"}],"meta":{"tier":"free","tags":["hover","accordion","gallery","flex","spring","rotate","pointer","keyboard"],"href":"https://viberdy.dev/library/hover-expand-panels","aiPrompt":"Create a React + Tailwind component named HoverExpandPanels: an accordion row of art panels. React only, no dependencies, one self-contained \"use client\" file that runs on React 18 and 19.\n\nProps: panels (array of {id, label, image?, caption?, art?}, default five CSS-art panels), expandRatio (number, default 4, clamped 1-12), showLabels (boolean, default true), vertical (boolean, default false: stack rows instead of columns), restIndex (zero-based number or null, default null: the panel that stays open while nothing is hovered or focused), className (extra classes on the row; default height h-64).\n\nLayout: a flex row (flex-col when vertical) with gap-1.5 and role=\"group\" aria-label=\"Expanding panels\". Each panel is a <button type=\"button\"> with flex-basis 0, min-w-0 and min-h-0, flex-grow = expandRatio when open, else 1, transitioned on flex-grow only for 650ms with cubic-bezier(0.22,1.25,0.36,1) (a small spring overshoot). Rounded-xl, overflow hidden, 1px inset white/8% ring (white/20% plus a soft drop shadow when open). The open panel is the hovered/focused/tapped one, else restIndex.\n\nPanel layers, back to front: (1) an art layer inset -7%, painted with panel.art, else one of six built-in CSS gradient recipes cycled by index (layered radial and conic gradients: cobalt/violet aurora, ember orange, teal, chrome conic, pink/amber bloom, lime/green); an <img> object-cover over it if panel.image; it translates up to 9px against the pointer (--nx/--ny in -1..1) and scales 1.12 collapsed, 1.04 open, 520ms. (2) a 260px soft-light radial white spot (alpha 0.26) that follows the pointer, visible only on the open panel while a mouse is over it. (3) a bottom scrim linear-gradient(0deg, black 62%, black 12% at 46%, black 28%). (4) a black overlay at 34% opacity on non-open panels while any panel is open. (5) mono index top-left (10px, tracking 0.14em, white/75). (6) a 28px glass circle with a diagonal arrow top-right, fading and scaling in 200ms after opening. (7) the title: one element, text-base semibold, transform-origin bottom-left. Collapsed: translate(1em,0) rotate(-90deg) scale(1) at left 17px bottom 18px, reading up the edge. Open: translate(4px,-38px) rotate(0) scale(1.45). Transition transform 650ms with the same easing. Vertical mode never rotates: the title sits right of the index (left 44px) and centred in the collapsed row, moving to left 20px and moves to bottom 48px with the scale when open. (8) a caption (12px, white/70, wraps to two lines) at the bottom-left that fades up 220ms after the panel opens and hides at once on close.\n\nInteraction: pointer enter (mouse/pen only) opens; leaving the row closes (mouse only); click and tap open; focus opens, blur closes. Arrow keys (all four), Home and End move DOM focus between sibling panels. Map pointer coords to layout pixels with offsetWidth / rect.width. Set pointer CSS variables directly on the button element, not in React state.\n\nA11y: aria-label = the title, aria-expanded, visible white inset focus ring (focus-visible:!outline-2 focus-visible:!-outline-offset-4 focus-visible:!outline-white), decorative layers aria-hidden. prefers-reduced-motion: drop all transitions and parallax and hide the spot (motion-reduce utilities). Touch: no hover-only features; collapsed panels stay at least 40px wide in a 360px row of five. Paint all colours inline or with plain Tailwind values.","license":"https://viberdy.dev/license"}}