{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"apple-card-carousel","type":"registry:ui","title":"AppleCardCarousel","description":"Horizontal card carousel where the focused card expands into a spring-animated full-screen view","author":"fancy-ui <https://fancy-ui.rama.app>","categories":["cards"],"registryDependencies":["https://fancy-ui.rama.app/r/internals.json","https://fancy-ui.rama.app/r/internals-dom.json","https://fancy-ui.rama.app/r/internals-motion.json","https://fancy-ui.rama.app/r/sound.json","https://fancy-ui.rama.app/r/utils.json"],"files":[{"path":"react/src/components/apple-card-carousel/AppleCard.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useState } from \"react\";\nimport type { KeyboardEvent, ReactNode } from \"react\";\n\nimport { useIsomorphicLayoutEffect } from \"../../internals/dom/ssr\";\nimport { useSoundCue } from \"../../sound/use-sound\";\nimport { cn } from \"../../utils\";\n\nexport interface AppleCardData {\n\t/** Category label shown above the title */\n\tcategory: string;\n\t/** Main card title */\n\ttitle: string;\n\t/** URL of the card background image */\n\tsrc: string;\n\t/** Short description shown in the expanded view */\n\tdescription?: string;\n\t/** Rich content shown in the expanded view (takes precedence over description) */\n\tcontent?: ReactNode;\n}\n\n/** Shared transition duration — must stay in sync with the inline transition below */\nexport const TRANSITION_MS = 400;\n\nexport interface AppleCardProps {\n\tcard: AppleCardData;\n\tindex: number;\n\texpandedIndex: number;\n\treducedMotion: boolean;\n\tonExpand: (index: number) => void;\n\tonCollapse: () => void;\n\tclassName?: string;\n\t/**\n\t * Plays the matching open/close cue through the sound controller. Off by\n\t * default; only audible once the user has enabled sound.\n\t */\n\tsound?: boolean;\n}\n\ninterface Rect {\n\ttop: number;\n\tleft: number;\n\twidth: number;\n\theight: number;\n}\n\nexport function AppleCard({\n\tcard,\n\tindex,\n\texpandedIndex,\n\treducedMotion,\n\tonExpand,\n\tonCollapse,\n\tclassName = \"\",\n\tsound = false,\n}: AppleCardProps) {\n\tconst cardEl = useRef<HTMLDivElement | null>(null);\n\tconst dialogEl = useRef<HTMLDivElement | null>(null);\n\tconst closeBtn = useRef<HTMLButtonElement | null>(null);\n\tconst previousFocus = useRef<HTMLElement | null>(null);\n\n\tconst [rect, setRect] = useState<Rect | null>(null);\n\tconst [overlayVisible, setOverlayVisible] = useState(false);\n\tconst [fullyExpanded, setFullyExpanded] = useState(false);\n\n\t// Collapse-in-progress latch. Not state: nothing renders off it — it only\n\t// dedupes handleCollapse calls (Escape + backdrop click) during the exit\n\t// window, and gates the close cue on the overlay actually being open\n\t// rather than on the entrance animation having finished.\n\tconst closing = useRef(false);\n\n\t// Read at expand time so the animation branch is decided once per expand,\n\t// exactly like the source's imperative handler.\n\tconst reducedMotionRef = useRef(reducedMotion);\n\treducedMotionRef.current = reducedMotion;\n\n\tconst playCue = useSoundCue(sound);\n\n\tfunction handleExpand() {\n\t\tif (expandedIndex !== -1) return;\n\t\tplayCue(\"open\");\n\t\tpreviousFocus.current = document.activeElement as HTMLElement;\n\t\tconst r = cardEl.current!.getBoundingClientRect();\n\t\tsetRect({ top: r.top, left: r.left, width: r.width, height: r.height });\n\t\tsetOverlayVisible(true);\n\t\tonExpand(index);\n\t}\n\n\t// Once the overlay is in the DOM, focus lands in the layout phase — before\n\t// the user's first painted frame, where the source's `await tick()` puts\n\t// it. The reduced-motion branch has no entrance leg, so its still frame is\n\t// committed here too.\n\tuseIsomorphicLayoutEffect(() => {\n\t\tif (!overlayVisible) return;\n\t\tcloseBtn.current?.focus();\n\t\tif (reducedMotionRef.current) {\n\t\t\tsetFullyExpanded(true);\n\t\t}\n\t}, [overlayVisible]);\n\n\t// Flip to the fully expanded geometry (double rAF so the initial card-rect\n\t// frame paints) — a painted first frame is the point, so this one stays\n\t// passive.\n\tuseEffect(() => {\n\t\tif (!overlayVisible || reducedMotionRef.current) return;\n\t\tlet raf2 = 0;\n\t\tconst raf1 = requestAnimationFrame(() => {\n\t\t\traf2 = requestAnimationFrame(() => {\n\t\t\t\tsetFullyExpanded(true);\n\t\t\t});\n\t\t});\n\t\treturn () => {\n\t\t\tcancelAnimationFrame(raf1);\n\t\t\tcancelAnimationFrame(raf2);\n\t\t};\n\t}, [overlayVisible]);\n\n\tfunction handleCollapse() {\n\t\tif (!overlayVisible || closing.current) return;\n\t\tclosing.current = true;\n\t\t// Gated on the overlay being open, not on `fullyExpanded` — a dismissal\n\t\t// during the two entrance frames (Escape right after Enter) must still\n\t\t// pair the `open` cue with a `close`.\n\t\tplayCue(\"close\");\n\t\tsetFullyExpanded(false);\n\t\tconst delay = reducedMotion ? 0 : TRANSITION_MS;\n\t\tsetTimeout(() => {\n\t\t\tsetOverlayVisible(false);\n\t\t\tclosing.current = false;\n\t\t\tonCollapse();\n\t\t\tsetRect(null);\n\t\t\tpreviousFocus.current?.focus();\n\t\t\tpreviousFocus.current = null;\n\t\t}, delay);\n\t}\n\n\tfunction handleCardKeydown(e: KeyboardEvent<HTMLDivElement>) {\n\t\tif (e.key === \"Enter\" || e.key === \" \") {\n\t\t\te.preventDefault();\n\t\t\thandleExpand();\n\t\t}\n\t}\n\n\tfunction handleOverlayKeydown(e: KeyboardEvent<HTMLDivElement>) {\n\t\tif (e.key === \"Escape\") {\n\t\t\thandleCollapse();\n\t\t\treturn;\n\t\t}\n\t\t// Simple focus trap: cycle focus within the dialog on Tab\n\t\tif (e.key === \"Tab\" && dialogEl.current) {\n\t\t\tconst focusable = Array.from(\n\t\t\t\tdialogEl.current.querySelectorAll<HTMLElement>(\n\t\t\t\t\t'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex=\"-1\"])'\n\t\t\t\t)\n\t\t\t);\n\t\t\tif (focusable.length === 0) return;\n\t\t\tconst first = focusable[0]!;\n\t\t\tconst last = focusable[focusable.length - 1]!;\n\t\t\tif (e.shiftKey && document.activeElement === first) {\n\t\t\t\te.preventDefault();\n\t\t\t\tlast.focus();\n\t\t\t} else if (!e.shiftKey && document.activeElement === last) {\n\t\t\t\te.preventDefault();\n\t\t\t\tfirst.focus();\n\t\t\t}\n\t\t}\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{/* Collapsed card in the carousel */}\n\t\t\t<div\n\t\t\t\tref={cardEl}\n\t\t\t\tclassName={cn(\n\t\t\t\t\t\"relative h-80 w-56 shrink-0 cursor-pointer snap-start overflow-hidden rounded-3xl md:h-96 md:w-72\",\n\t\t\t\t\tclassName\n\t\t\t\t)}\n\t\t\t\trole=\"button\"\n\t\t\t\ttabIndex={0}\n\t\t\t\taria-label={`Open ${card.title}`}\n\t\t\t\tonClick={handleExpand}\n\t\t\t\tonKeyDown={handleCardKeydown}\n\t\t\t>\n\t\t\t\t<img\n\t\t\t\t\tsrc={card.src}\n\t\t\t\t\talt={card.title}\n\t\t\t\t\tclassName=\"absolute inset-0 h-full w-full object-cover motion-safe:duration-500 hover:scale-105 motion-safe:transition-transform\"\n\t\t\t\t\tdraggable={false}\n\t\t\t\t/>\n\t\t\t\t<div className=\"absolute inset-0 bg-gradient-to-t from-black/60 via-black/10 to-transparent\"></div>\n\t\t\t\t<div className=\"absolute bottom-0 left-0 p-5\">\n\t\t\t\t\t<p className=\"mb-1 text-xs font-semibold tracking-widest text-white/70 uppercase\">\n\t\t\t\t\t\t{card.category}\n\t\t\t\t\t</p>\n\t\t\t\t\t<h3 className=\"text-base font-semibold text-white md:text-lg\">{card.title}</h3>\n\t\t\t\t</div>\n\t\t\t</div>\n\n\t\t\t{/* Expanded overlay */}\n\t\t\t{overlayVisible && rect !== null && (\n\t\t\t\t<>\n\t\t\t\t\t<div\n\t\t\t\t\t\tclassName=\"fixed inset-0 z-40 bg-black/80\"\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\topacity: fullyExpanded ? 1 : 0,\n\t\t\t\t\t\t\ttransition: `opacity ${reducedMotion ? 0 : TRANSITION_MS}ms ease`,\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonClick={handleCollapse}\n\t\t\t\t\t></div>\n\n\t\t\t\t\t<div\n\t\t\t\t\t\tref={dialogEl}\n\t\t\t\t\t\trole=\"dialog\"\n\t\t\t\t\t\taria-modal=\"true\"\n\t\t\t\t\t\taria-label={card.title}\n\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\tclassName=\"fixed z-50 overflow-y-auto bg-white dark:bg-neutral-900\"\n\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\ttop: fullyExpanded ? \"0px\" : `${rect.top}px`,\n\t\t\t\t\t\t\tleft: fullyExpanded ? \"0px\" : `${rect.left}px`,\n\t\t\t\t\t\t\twidth: fullyExpanded ? \"100vw\" : `${rect.width}px`,\n\t\t\t\t\t\t\theight: fullyExpanded ? \"100vh\" : `${rect.height}px`,\n\t\t\t\t\t\t\tborderRadius: fullyExpanded ? \"0px\" : \"1.5rem\",\n\t\t\t\t\t\t\ttransition: reducedMotion\n\t\t\t\t\t\t\t\t? \"none\"\n\t\t\t\t\t\t\t\t: `top ${TRANSITION_MS}ms cubic-bezier(0.32,0.72,0,1), left ${TRANSITION_MS}ms cubic-bezier(0.32,0.72,0,1), width ${TRANSITION_MS}ms cubic-bezier(0.32,0.72,0,1), height ${TRANSITION_MS}ms cubic-bezier(0.32,0.72,0,1), border-radius ${TRANSITION_MS}ms cubic-bezier(0.32,0.72,0,1)`,\n\t\t\t\t\t\t}}\n\t\t\t\t\t\tonKeyDown={handleOverlayKeydown}\n\t\t\t\t\t>\n\t\t\t\t\t\t{/* Close button */}\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\tref={closeBtn}\n\t\t\t\t\t\t\tclassName=\"absolute top-4 right-4 z-10 flex h-10 w-10 items-center justify-center rounded-full bg-black/20 backdrop-blur-sm transition-colors hover:bg-black/30\"\n\t\t\t\t\t\t\taria-label=\"Close\"\n\t\t\t\t\t\t\tonClick={handleCollapse}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<svg\n\t\t\t\t\t\t\t\txmlns=\"http://www.w3.org/2000/svg\"\n\t\t\t\t\t\t\t\twidth=\"18\"\n\t\t\t\t\t\t\t\theight=\"18\"\n\t\t\t\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\t\t\t\tfill=\"none\"\n\t\t\t\t\t\t\t\tstroke=\"white\"\n\t\t\t\t\t\t\t\tstrokeWidth=\"2.5\"\n\t\t\t\t\t\t\t\tstrokeLinecap=\"round\"\n\t\t\t\t\t\t\t\tstrokeLinejoin=\"round\"\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<path d=\"M18 6 6 18\" />\n\t\t\t\t\t\t\t\t<path d=\"m6 6 12 12\" />\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t</button>\n\n\t\t\t\t\t\t{/* Hero image */}\n\t\t\t\t\t\t<div className=\"relative h-72 w-full shrink-0 md:h-96\">\n\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\tsrc={card.src}\n\t\t\t\t\t\t\t\talt={card.title}\n\t\t\t\t\t\t\t\tclassName=\"h-full w-full object-cover\"\n\t\t\t\t\t\t\t\tdraggable={false}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t<div className=\"absolute inset-0 bg-gradient-to-t from-black/60 via-black/10 to-transparent\"></div>\n\t\t\t\t\t\t\t<div className=\"absolute bottom-0 left-0 p-6 md:p-8\">\n\t\t\t\t\t\t\t\t<p className=\"mb-2 text-xs font-semibold tracking-widest text-white/70 uppercase\">\n\t\t\t\t\t\t\t\t\t{card.category}\n\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t\t<h2 className=\"text-2xl font-bold text-white md:text-3xl\">{card.title}</h2>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\n\t\t\t\t\t\t{/* Content area */}\n\t\t\t\t\t\t<div className=\"p-6 md:p-8\">\n\t\t\t\t\t\t\t{card.content ? (\n\t\t\t\t\t\t\t\tcard.content\n\t\t\t\t\t\t\t) : card.description ? (\n\t\t\t\t\t\t\t\t<p className=\"leading-relaxed text-gray-600 dark:text-neutral-400\">\n\t\t\t\t\t\t\t\t\t{card.description}\n\t\t\t\t\t\t\t\t</p>\n\t\t\t\t\t\t\t) : null}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t</>\n\t\t\t)}\n\t\t</>\n\t);\n}\n","type":"registry:ui","target":"@ui/fancy/components/apple-card-carousel/AppleCard.tsx"},{"path":"react/src/components/apple-card-carousel/AppleCardCarousel.tsx","content":"\"use client\";\n\nimport { useState } from \"react\";\n\nimport { useReducedMotion } from \"../../internals/motion/media-query\";\nimport { cn } from \"../../utils\";\nimport { AppleCard } from \"./AppleCard\";\nimport type { AppleCardData } from \"./AppleCard\";\n\nexport type { AppleCardData };\n\nexport interface AppleCardCarouselProps {\n\t/** Cards to display in the carousel */\n\tcards: AppleCardData[];\n\t/** Additional CSS classes */\n\tclassName?: string;\n\t/**\n\t * Plays the matching open/close cue through the sound controller. Off by\n\t * default; only audible once the user has enabled sound.\n\t */\n\tsound?: boolean;\n}\n\nexport function AppleCardCarousel({\n\tcards,\n\tclassName = \"\",\n\tsound = false,\n}: AppleCardCarouselProps) {\n\tconst [expandedIndex, setExpandedIndex] = useState(-1);\n\tconst reducedMotion = useReducedMotion();\n\n\treturn (\n\t\t<div className={cn(\"relative w-full\", className)}>\n\t\t\t<div className=\"flex snap-x snap-mandatory gap-4 overflow-x-auto px-4 pb-4 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden\">\n\t\t\t\t{cards.map((card, i) => (\n\t\t\t\t\t<AppleCard\n\t\t\t\t\t\tkey={i}\n\t\t\t\t\t\tcard={card}\n\t\t\t\t\t\tindex={i}\n\t\t\t\t\t\texpandedIndex={expandedIndex}\n\t\t\t\t\t\treducedMotion={reducedMotion}\n\t\t\t\t\t\tonExpand={(idx) => setExpandedIndex(idx)}\n\t\t\t\t\t\tonCollapse={() => setExpandedIndex(-1)}\n\t\t\t\t\t\tsound={sound}\n\t\t\t\t\t/>\n\t\t\t\t))}\n\t\t\t</div>\n\t\t</div>\n\t);\n}\n","type":"registry:ui","target":"@ui/fancy/components/apple-card-carousel/AppleCardCarousel.tsx"},{"path":"react/src/components/apple-card-carousel/index.ts","content":"\"use client\";\n\nexport { AppleCardCarousel } from \"./AppleCardCarousel\";\nexport type { AppleCardCarouselProps, AppleCardData } from \"./AppleCardCarousel\";\nexport { AppleCard } from \"./AppleCard\";\nexport type { AppleCardProps } from \"./AppleCard\";\n","type":"registry:ui","target":"@ui/fancy/components/apple-card-carousel/index.ts"}],"meta":{"license":"MIT","package":"fancy-ui-react","version":"0.7.0","source":"https://fancy-ui.rama.app/docs/components/apple-card-carousel?framework=react"}}