{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-image-accordion",
  "title": "Image accordion",
  "description": "A row of image panels where the hovered or focused one widens to show its caption.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "components/core/image-accordion.tsx",
      "content": "'use client';\nimport { useState, type MouseEvent, type PointerEvent } from 'react';\nimport { cn } from '@/lib/utils';\n\nexport type ImageAccordionItem = {\n  id: string;\n  src: string;\n  alt: string;\n  title: string;\n  description?: string;\n  href?: string;\n};\n\nexport type ImageAccordionOrientation = 'horizontal' | 'vertical';\n\nexport type ImageAccordionProps = {\n  items: ImageAccordionItem[];\n  defaultValue?: string;\n  value?: string;\n  onValueChange?: (value: string) => void;\n  orientation?: ImageAccordionOrientation;\n  className?: string;\n};\n\nconst ORIENTATION_CLASS: Record<ImageAccordionOrientation, string> = {\n  horizontal: 'h-[28rem] flex-col sm:h-80 sm:flex-row',\n  vertical: 'h-[28rem] flex-col',\n};\n\nconst IMAGE_CLASS: Record<ImageAccordionOrientation, string> = {\n  horizontal:\n    'top-1/2 left-0 h-auto min-h-full w-full -translate-y-1/2 sm:top-0 sm:left-1/2 sm:h-full sm:min-h-0 sm:w-auto sm:min-w-full sm:-translate-x-1/2 sm:translate-y-0',\n  vertical: 'top-1/2 left-0 h-auto min-h-full w-full -translate-y-1/2',\n};\n\nconst ITEM_CLASS =\n  'min-h-0 min-w-0 basis-0 grow transition-[flex-grow] duration-500 ease-(--ease-out-strong) data-[active=true]:grow-[4]';\n\nconst PANEL_CLASS =\n  'group/panel bg-foreground/[0.04] focus-visible:ring-ring focus-visible:ring-offset-background relative block size-full cursor-pointer overflow-hidden rounded-xl text-left outline-none focus-visible:ring-2 focus-visible:ring-offset-2';\n\nconst CAPTION_CLASS =\n  'pointer-events-none absolute bottom-3 left-3 flex w-56 flex-col gap-0.5 rounded-lg bg-card/90 px-3 py-2 text-card-foreground opacity-0 shadow-[0_1px_2px_rgb(0_0_0/0.08)] transition-[opacity,translate] duration-100 ease-(--ease-out-strong) translate-y-1 group-data-[active=true]/panel:translate-y-0 group-data-[active=true]/panel:opacity-100 group-data-[active=true]/panel:delay-150 group-data-[active=true]/panel:duration-200';\n\nfunction firstIdOf(items: ImageAccordionItem[]) {\n  const first = items[0];\n  if (!first) {\n    return '';\n  }\n  return first.id;\n}\n\nfunction selectedIdOf(\n  controlledValue: string | undefined,\n  internalValue: string\n) {\n  if (controlledValue === undefined) {\n    return internalValue;\n  }\n  return controlledValue;\n}\n\ntype PanelContentProps = {\n  item: ImageAccordionItem;\n  orientation: ImageAccordionOrientation;\n};\n\nfunction PanelContent({ item, orientation }: PanelContentProps) {\n  return (\n    <>\n      {/* eslint-disable-next-line @next/next/no-img-element -- registry items land in any React app, where next/image may not exist */}\n      <img\n        src={item.src}\n        alt={item.alt}\n        draggable={false}\n        decoding='async'\n        className={cn(\n          'absolute max-w-none object-cover',\n          IMAGE_CLASS[orientation]\n        )}\n      />\n      <span className={CAPTION_CLASS}>\n        <span className='truncate text-sm font-medium'>{item.title}</span>\n        {item.description && (\n          <span className='text-muted-foreground line-clamp-2 text-xs'>\n            {item.description}\n          </span>\n        )}\n      </span>\n    </>\n  );\n}\n\nfunction ImageAccordion({\n  items,\n  defaultValue,\n  value: controlledValue,\n  onValueChange,\n  orientation = 'horizontal',\n  className,\n}: ImageAccordionProps) {\n  const [internalValue, setInternalValue] = useState(\n    defaultValue ?? firstIdOf(items)\n  );\n  const activeId = selectedIdOf(controlledValue, internalValue);\n\n  const activate = (id: string) => {\n    if (id === activeId) {\n      return;\n    }\n    setInternalValue(id);\n    onValueChange?.(id);\n  };\n\n  const activateOnPress = (\n    item: ImageAccordionItem,\n    event: MouseEvent<HTMLElement>\n  ) => {\n    const isLink = item.href !== undefined;\n    const isClosed = item.id !== activeId;\n    const isClosedLink = isLink && isClosed;\n    if (isClosedLink) {\n      event.preventDefault();\n    }\n    activate(item.id);\n  };\n\n  const activateOnHover = (id: string, event: PointerEvent<HTMLElement>) => {\n    const isMouse = event.pointerType === 'mouse';\n    if (isMouse) {\n      activate(id);\n    }\n  };\n\n  return (\n    <ul className={cn('flex gap-2', ORIENTATION_CLASS[orientation], className)}>\n      {items.map((item) => {\n        const isActive = item.id === activeId;\n        const sharedProps = {\n          'data-active': isActive,\n          className: PANEL_CLASS,\n          onFocus: () => activate(item.id),\n          onClick: (event: MouseEvent<HTMLElement>) =>\n            activateOnPress(item, event),\n          onPointerEnter: (event: PointerEvent<HTMLElement>) =>\n            activateOnHover(item.id, event),\n        };\n\n        return (\n          <li key={item.id} data-active={isActive} className={ITEM_CLASS}>\n            {item.href && (\n              <a href={item.href} {...sharedProps}>\n                <PanelContent item={item} orientation={orientation} />\n              </a>\n            )}\n            {!item.href && (\n              <button type='button' aria-expanded={isActive} {...sharedProps}>\n                <PanelContent item={item} orientation={orientation} />\n              </button>\n            )}\n          </li>\n        );\n      })}\n    </ul>\n  );\n}\n\nexport { ImageAccordion };\n",
      "type": "registry:component",
      "target": "components/core/image-accordion.tsx"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:component"
}