{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"expandable-cards","type":"registry:ui","title":"Expandable Cards","description":"A list of cards where the one you pick morphs into a detail view with a shared-layout spring, closing on Escape or backdrop click.","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/ui/expandable-cards.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState, type ReactNode } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { X } from \"lucide-react\";\n\nexport interface ExpandableCardItem {\n  id: string;\n  title: string;\n  subtitle: string;\n  image: string;\n  /** Detail content shown when expanded. */\n  content: ReactNode;\n  /** Label of the action pill. */\n  cta?: string;\n  onCta?: () => void;\n}\n\nexport interface ExpandableCardsProps {\n  items: ExpandableCardItem[];\n  /** Corner radius of cards in px. */\n  radius?: number;\n  /** Spring bounce of the expand animation, 0 to 0.5. */\n  bounce?: number;\n  /** Dim + blur the list behind the open card. */\n  backdrop?: boolean;\n  className?: string;\n}\n\nexport function ExpandableCards({ items, radius = 20, bounce = 0.15, backdrop = true, className }: ExpandableCardsProps) {\n  const [activeId, setActiveId] = useState<string | null>(null);\n  const uid = useId();\n  const reduce = useReducedMotion();\n  const closeBtn = useRef<HTMLButtonElement>(null);\n  const triggers = useRef(new Map<string, HTMLButtonElement>());\n  const lastId = useRef<string | null>(null);\n\n  const active = items.find((i) => i.id === activeId) ?? null;\n  const t = reduce ? { duration: 0 } : { type: \"spring\" as const, bounce, duration: 0.5 };\n  const lid = (part: string, id: string) => `${uid}-${part}-${id}`;\n\n  useEffect(() => {\n    if (activeId) {\n      lastId.current = activeId;\n      closeBtn.current?.focus({ preventScroll: true });\n    } else if (lastId.current) {\n      triggers.current.get(lastId.current)?.focus({ preventScroll: true });\n    }\n  }, [activeId]);\n\n  return (\n    <div className={`relative flex w-full flex-col justify-center ${className ?? \"\"}`}>\n      <ul className=\"flex w-full flex-col gap-2\" inert={activeId !== null}>\n        {items.map((item) => {\n          const open = item.id === activeId;\n          return (\n            <li key={item.id}>\n              <motion.button\n                ref={(el: HTMLButtonElement | null) => {\n                  if (el) triggers.current.set(item.id, el);\n                  else triggers.current.delete(item.id);\n                }}\n                type=\"button\"\n                layoutId={open ? undefined : lid(\"card\", item.id)}\n                transition={t}\n                onClick={() => setActiveId(item.id)}\n                aria-haspopup=\"dialog\"\n                className={`group flex w-full items-center gap-4 border border-border bg-card p-3 text-left outline-none transition-colors hover:bg-muted focus-visible:ring-2 focus-visible:ring-ring ${open ? \"invisible\" : \"\"}`}\n                style={{ borderRadius: radius }}\n              >\n                <motion.img\n                  layoutId={open ? undefined : lid(\"image\", item.id)}\n                  transition={t}\n                  src={item.image}\n                  alt=\"\"\n                  draggable={false}\n                  className=\"size-14 shrink-0 object-cover\"\n                  style={{ borderRadius: radius * 0.6 }}\n                />\n                <div className=\"min-w-0 flex-1\">\n                  <motion.p layoutId={open ? undefined : lid(\"title\", item.id)} transition={t} className=\"truncate font-semibold text-foreground\">\n                    {item.title}\n                  </motion.p>\n                  <motion.p layoutId={open ? undefined : lid(\"sub\", item.id)} transition={t} className=\"truncate text-sm text-muted-foreground\">\n                    {item.subtitle}\n                  </motion.p>\n                </div>\n                <span className=\"shrink-0 rounded-full bg-muted px-3 py-1.5 text-xs font-medium text-foreground transition-colors group-hover:bg-primary group-hover:text-primary-foreground\">\n                  {item.cta ?? \"Open\"}\n                </span>\n              </motion.button>\n            </li>\n          );\n        })}\n      </ul>\n\n      <AnimatePresence>\n        {active && (\n          <motion.div\n            key=\"backdrop\"\n            aria-hidden\n            onClick={() => setActiveId(null)}\n            className={`absolute -inset-4 z-10 ${backdrop ? \"bg-background/60 backdrop-blur-sm\" : \"\"}`}\n            style={{ borderRadius: radius }}\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1 }}\n            exit={{ opacity: 0 }}\n            transition={{ duration: reduce ? 0 : 0.2 }}\n          />\n        )}\n      </AnimatePresence>\n\n      <AnimatePresence>\n        {active && (\n          <div key=\"dialog\" className=\"pointer-events-none absolute inset-0 z-20 grid place-items-center\">\n            <motion.div\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-labelledby={lid(\"title\", active.id)}\n              layoutId={lid(\"card\", active.id)}\n              transition={t}\n              onKeyDown={(e) => {\n                if (e.key === \"Escape\") {\n                  e.stopPropagation();\n                  setActiveId(null);\n                }\n              }}\n              className=\"pointer-events-auto flex max-h-full w-full max-w-md flex-col overflow-hidden border border-border bg-card shadow-[0_40px_80px_-30px_rgba(0,0,0,.8)]\"\n              style={{ borderRadius: radius }}\n            >\n              <div className=\"relative\">\n                <motion.img\n                  layoutId={lid(\"image\", active.id)}\n                  transition={t}\n                  src={active.image}\n                  alt=\"\"\n                  draggable={false}\n                  className=\"h-44 w-full object-cover\"\n                  style={{ borderRadius: 0 }}\n                />\n                <button\n                  ref={closeBtn}\n                  type=\"button\"\n                  aria-label=\"Close\"\n                  onClick={() => setActiveId(null)}\n                  className=\"absolute right-3 top-3 grid size-8 place-items-center rounded-full bg-black/50 text-white outline-none backdrop-blur transition-colors hover:bg-black/70 focus-visible:ring-2 focus-visible:ring-white\"\n                >\n                  <X className=\"size-4\" />\n                </button>\n              </div>\n              <div className=\"flex items-start justify-between gap-4 p-5 pb-3\">\n                <div className=\"min-w-0\">\n                  <motion.p id={lid(\"title\", active.id)} layoutId={lid(\"title\", active.id)} transition={t} className=\"text-lg font-semibold text-foreground\">\n                    {active.title}\n                  </motion.p>\n                  <motion.p layoutId={lid(\"sub\", active.id)} transition={t} className=\"text-sm text-muted-foreground\">\n                    {active.subtitle}\n                  </motion.p>\n                </div>\n                <button\n                  type=\"button\"\n                  onClick={active.onCta}\n                  className=\"shrink-0 rounded-full bg-primary px-4 py-2 text-sm font-medium text-primary-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-card\"\n                >\n                  {active.cta ?? \"Open\"}\n                </button>\n              </div>\n              <motion.div\n                initial={{ opacity: 0, y: reduce ? 0 : 12 }}\n                animate={{ opacity: 1, y: 0 }}\n                exit={{ opacity: 0, transition: { duration: 0.05 } }}\n                transition={{ delay: reduce ? 0 : 0.12, duration: reduce ? 0 : 0.3 }}\n                className=\"min-h-0 overflow-y-auto px-5 pb-5 text-sm leading-relaxed text-muted-foreground\"\n              >\n                {active.content}\n              </motion.div>\n            </motion.div>\n          </div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n"}]}