{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "expand-card-grid",
  "title": "Expand Card Grid",
  "description": "A 2x2 grid of image cards that expand to fill the frame on click, revealing title/description/CTA, with keyboard arrow navigation between cards and swipe-to-close on touch.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/expand-card-grid/expand-card-grid.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface ExpandCardGridItem {\n  src?: string;\n  title: string;\n  description?: string;\n  buttonText?: string;\n  buttonHref?: string;\n}\n\nexport interface ExpandCardGridProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  items?: ExpandCardGridItem[];\n  transitionDuration?: number;\n  gap?: number;\n  cardRadius?: number;\n  overlayRadius?: number;\n  cardColor?: string;\n  titleSize?: number;\n  descriptionSize?: number;\n  accentColor?: string;\n  showButton?: boolean;\n  buttonTextColor?: string;\n  buttonBorderColor?: string;\n  closeIconColor?: string;\n  showIndex?: boolean;\n  indexColor?: string;\n}\n\nconst DEFAULT_ITEMS: ExpandCardGridItem[] = [\n  { src: \"/demo/105.webp\", title: \"Section One\", buttonText: \"Explore Now\" },\n  { src: \"/demo/102.webp\", title: \"Section Two\", buttonText: \"Explore Now\" },\n  { src: \"/demo/109.webp\", title: \"Section Three\", buttonText: \"Explore Now\" },\n  { src: \"/demo/111.webp\", title: \"Section Four\", buttonText: \"Explore Now\" },\n];\n\nconst EASING = \"cubic-bezier(0.4, 0, 0.2, 1)\";\nconst TONE_OFFSETS = [0, 0.16, -0.12, 0.26, -0.18, 0.08];\n\nexport function ExpandCardGrid({\n  items = DEFAULT_ITEMS,\n  transitionDuration = 0.6,\n  gap = 0,\n  cardRadius = 0,\n  overlayRadius = 0,\n  cardColor = \"#212121\",\n  titleSize = 32,\n  descriptionSize = 14,\n  accentColor = \"#ffffff\",\n  showButton = true,\n  buttonTextColor = \"rgba(255,255,255,0.55)\",\n  buttonBorderColor = \"rgba(255,255,255,0.35)\",\n  closeIconColor = \"#ffffff\",\n  showIndex = false,\n  indexColor = \"rgba(255,255,255,0.5)\",\n  className,\n  ...props\n}: ExpandCardGridProps) {\n  const [expandedIndex, setExpandedIndex] = React.useState<number | null>(null);\n  const [hoveredIndex, setHoveredIndex] = React.useState<number | null>(null);\n  const [focusedIndex, setFocusedIndex] = React.useState<number | null>(null);\n  const containerRef = React.useRef<HTMLDivElement>(null);\n  const sectionRefs = React.useRef<(HTMLDivElement | null)[]>([]);\n  const touchStartRef = React.useRef<{ x: number; y: number } | null>(null);\n  const [isMobile, setIsMobile] = React.useState(false);\n\n  React.useEffect(() => {\n    const el = containerRef.current;\n    if (!el) return;\n    const ro = new ResizeObserver(([entry]) => setIsMobile(entry.contentRect.width <= 700));\n    ro.observe(el);\n    return () => ro.disconnect();\n  }, []);\n\n  const resolvedItems = items.length > 0 ? items : DEFAULT_ITEMS;\n  const duration = transitionDuration;\n\n  const openSection = React.useCallback((index: number) => setExpandedIndex(index), []);\n  const closeSection = React.useCallback(() => setExpandedIndex(null), []);\n\n  const navigate = React.useCallback(\n    (currentIndex: number, direction: 1 | -1) => {\n      const total = resolvedItems.length;\n      openSection((currentIndex + direction + total) % total);\n    },\n    [resolvedItems.length, openSection],\n  );\n\n  React.useEffect(() => {\n    if (expandedIndex !== null) sectionRefs.current[expandedIndex]?.focus();\n  }, [expandedIndex]);\n\n  // Reset expansion state if the item count shrinks below the open index\n  React.useEffect(() => {\n    if (expandedIndex !== null && expandedIndex >= resolvedItems.length) {\n      setExpandedIndex(null);\n    }\n  }, [resolvedItems.length, expandedIndex]);\n\n  const hasExpanded = expandedIndex !== null;\n\n  return (\n    <div\n      ref={containerRef}\n      className={cn(\"relative w-full h-full overflow-hidden grid bg-black\", className)}\n      style={{ gridTemplateColumns: isMobile ? \"1fr\" : \"1fr 1fr\", gridAutoRows: \"1fr\", gap }}\n      {...props}\n    >\n      {resolvedItems.map((item, index) => {\n        const isExpanded = expandedIndex === index;\n        const isHidden = hasExpanded && !isExpanded;\n        const textDelay = isExpanded ? duration : 0;\n        const toneOffset = TONE_OFFSETS[index % TONE_OFFSETS.length];\n\n        return (\n          <div\n            key={index}\n            ref={(el) => {\n              sectionRefs.current[index] = el;\n            }}\n            role=\"button\"\n            tabIndex={isHidden ? -1 : 0}\n            aria-hidden={isHidden}\n            aria-pressed={isExpanded}\n            aria-label={isExpanded ? `${item.title}, collapse` : `${item.title}, expand`}\n            onClick={() => {\n              if (!isExpanded) openSection(index);\n            }}\n            onKeyDown={(event) => {\n              if (event.key === \"Enter\" || event.key === \" \") {\n                event.preventDefault();\n                if (!isExpanded) openSection(index);\n                return;\n              }\n              if (!isExpanded) return;\n              if (event.key === \"Escape\") {\n                event.preventDefault();\n                closeSection();\n              } else if (event.key === \"ArrowRight\" || event.key === \"ArrowDown\") {\n                event.preventDefault();\n                navigate(index, 1);\n              } else if (event.key === \"ArrowLeft\" || event.key === \"ArrowUp\") {\n                event.preventDefault();\n                navigate(index, -1);\n              }\n            }}\n            onMouseEnter={() => setHoveredIndex(index)}\n            onMouseLeave={() => setHoveredIndex(null)}\n            onFocus={() => setFocusedIndex(index)}\n            onBlur={() => setFocusedIndex(null)}\n            onTouchStart={(event) => {\n              if (!isExpanded) return;\n              const touch = event.touches[0];\n              touchStartRef.current = { x: touch.clientX, y: touch.clientY };\n            }}\n            onTouchEnd={(event) => {\n              if (!isExpanded || !touchStartRef.current) return;\n              const touch = event.changedTouches[0];\n              const dx = touch.clientX - touchStartRef.current.x;\n              const dy = touch.clientY - touchStartRef.current.y;\n              touchStartRef.current = null;\n\n              const SWIPE_THRESHOLD = 50;\n              if (Math.abs(dx) < SWIPE_THRESHOLD && Math.abs(dy) < SWIPE_THRESHOLD) return;\n\n              if (Math.abs(dx) > Math.abs(dy)) {\n                navigate(index, dx < 0 ? 1 : -1);\n              } else if (dy > 0) {\n                closeSection();\n              } else {\n                navigate(index, 1);\n              }\n            }}\n            className=\"w-full h-full overflow-hidden outline-none\"\n            style={{\n              position: isExpanded ? \"absolute\" : \"relative\",\n              inset: isExpanded ? 0 : undefined,\n              zIndex: isExpanded ? 100 : 0,\n              cursor: isExpanded ? \"auto\" : \"pointer\",\n              touchAction: isExpanded ? \"none\" : \"auto\",\n              background: cardColor,\n              borderRadius: cardRadius,\n              transform: isHidden ? \"scale3d(0, 0, 0)\" : \"scale3d(1, 1, 1)\",\n              opacity: isHidden ? 0 : 1,\n              willChange: hasExpanded ? \"transform, opacity, border-radius\" : \"auto\",\n              transitionProperty: \"transform, opacity, border-radius\",\n              transitionDuration: `${duration}s`,\n              transitionTimingFunction: EASING,\n              boxShadow: focusedIndex === index ? \"inset 0 0 0 3px rgba(255,255,255,0.7)\" : \"none\",\n            }}\n          >\n            {item.src && (\n              <img\n                src={item.src}\n                alt=\"\"\n                className=\"pointer-events-none absolute top-0 left-0 block h-full w-full object-cover\"\n                style={{\n                  transform: !isExpanded && hoveredIndex === index ? \"scale(1.08)\" : \"scale(1)\",\n                  transition: `transform 0.5s ${EASING}`,\n                  willChange: hoveredIndex === index ? \"transform\" : \"auto\",\n                }}\n              />\n            )}\n\n            <div\n              className=\"pointer-events-none absolute inset-0\"\n              style={{ borderRadius: overlayRadius, background: `linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.25) 55%, rgba(0,0,0,0.05) 100%), ${toneOffset >= 0 ? `rgba(0,0,0,${toneOffset})` : `rgba(255,255,255,${-toneOffset})`}` }}\n            />\n\n            {showIndex && (\n              <div className=\"pointer-events-none absolute top-4 left-4 text-[10px] tracking-[0.2em]\" style={{ fontFamily: \"'Helvetica Neue', Arial, sans-serif\", color: indexColor }}>\n                {String(index + 1).padStart(2, \"0\")}\n              </div>\n            )}\n\n            <div aria-hidden={!isExpanded} className=\"absolute right-0 bottom-0 left-0 px-6.5 py-7\">\n              <div className=\"mb-2.5 overflow-hidden\">\n                <h3\n                  className=\"m-0 leading-[1.15] font-medium tracking-[-0.02em] text-white\"\n                  style={{\n                    fontFamily: \"'Georgia', serif\",\n                    fontSize: titleSize,\n                    opacity: isExpanded ? 1 : 0,\n                    transform: isExpanded ? \"translateY(0px)\" : \"translateY(20px)\",\n                    transition: isExpanded ? `opacity 0.4s ${textDelay}s cubic-bezier(0.16,1,0.3,1), transform 0.4s ${textDelay}s cubic-bezier(0.16,1,0.3,1)` : \"opacity 0.12s 0s ease, transform 0.12s 0s ease\",\n                  }}\n                >\n                  {item.title}\n                </h3>\n              </div>\n\n              <div\n                className=\"mb-2.5 h-px origin-left\"\n                style={{\n                  background: accentColor,\n                  opacity: isExpanded ? 0.25 : 0,\n                  transform: isExpanded ? \"scaleX(1)\" : \"scaleX(0)\",\n                  transition: isExpanded ? `opacity 0.1s ${textDelay + 0.08}s ease, transform 0.55s ${textDelay + 0.1}s cubic-bezier(0.4,0,0.2,1)` : \"opacity 0.12s 0s ease, transform 0.12s 0s ease\",\n                }}\n              />\n\n              {item.description && (\n                <div className=\"overflow-hidden\">\n                  <p\n                    className=\"m-0 leading-[1.6] text-white/65\"\n                    style={{\n                      fontFamily: \"'Helvetica Neue', Arial, sans-serif\",\n                      fontSize: descriptionSize,\n                      opacity: isExpanded ? 1 : 0,\n                      transform: isExpanded ? \"translateY(0px)\" : \"translateY(14px)\",\n                      transition: isExpanded ? `opacity 0.4s ${textDelay + 0.1}s cubic-bezier(0.16,1,0.3,1), transform 0.4s ${textDelay + 0.1}s cubic-bezier(0.16,1,0.3,1)` : \"opacity 0.12s 0s ease, transform 0.12s 0s ease\",\n                      display: \"-webkit-box\",\n                      WebkitLineClamp: 4,\n                      WebkitBoxOrient: \"vertical\",\n                      overflow: \"hidden\",\n                    }}\n                  >\n                    {item.description}\n                  </p>\n                </div>\n              )}\n\n              {showButton && item.buttonText && (\n                <div className=\"mt-3.5 inline-block overflow-hidden\">\n                  <a\n                    href={item.buttonHref || undefined}\n                    target={item.buttonHref ? \"_blank\" : undefined}\n                    rel={item.buttonHref ? \"noopener noreferrer\" : undefined}\n                    onClick={(event) => event.stopPropagation()}\n                    aria-hidden={!isExpanded || !item.buttonHref}\n                    tabIndex={isExpanded && item.buttonHref ? 0 : -1}\n                    className=\"inline-flex items-center justify-center rounded-full bg-white/8 px-4.5 py-2 no-underline backdrop-blur-[8px]\"\n                    style={{\n                      border: `1px solid ${buttonBorderColor}`,\n                      cursor: item.buttonHref ? \"pointer\" : \"default\",\n                      pointerEvents: isExpanded && item.buttonHref ? \"auto\" : \"none\",\n                      opacity: isExpanded ? 1 : 0,\n                      transition: isExpanded ? `opacity 0.4s ${textDelay + 0.2}s ease` : \"opacity 0.12s 0s ease\",\n                    }}\n                  >\n                    <span className=\"text-[10px] tracking-[0.18em] whitespace-nowrap uppercase\" style={{ fontFamily: \"'Helvetica Neue', Arial, sans-serif\", color: buttonTextColor }}>\n                      {item.buttonText}\n                    </span>\n                  </a>\n                </div>\n              )}\n            </div>\n\n            <button\n              type=\"button\"\n              aria-label={`Close ${item.title}`}\n              aria-hidden={!isExpanded}\n              tabIndex={isExpanded ? 0 : -1}\n              onClick={(event) => {\n                event.stopPropagation();\n                closeSection();\n              }}\n              className=\"absolute top-0 right-0 flex h-12 w-12 items-center justify-center border-none bg-transparent text-[28px] leading-none\"\n              style={{\n                color: closeIconColor,\n                opacity: isExpanded ? 1 : 0,\n                pointerEvents: isExpanded ? \"auto\" : \"none\",\n                cursor: \"pointer\",\n                transitionProperty: \"opacity\",\n                transitionDuration: isExpanded ? \"0.2s\" : \"0.1s\",\n                transitionTimingFunction: \"linear\",\n                transitionDelay: isExpanded ? `${duration}s` : \"0s\",\n                willChange: \"opacity\",\n              }}\n            >\n              &times;\n            </button>\n          </div>\n        );\n      })}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}