{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "contact-sheet",
  "title": "Contact Sheet",
  "description": "A grid of photo thumbnails that opens into a full-screen lightbox. It zooms out of the thumbnail you press, swipes, drags and pages with the arrow keys, has a thumbnail strip, and closes back into the photo you ended on. Built on ui-sdk's Dialog and Carousel, so the focus trap, scroll lock and ARIA are done.",
  "dependencies": [
    "@ui-sdk/react@0.1.0-beta.20",
    "@ui-sdk/core@0.1.0-beta.20",
    "lucide-react"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "registry/new-york/blocks/contact-sheet/contact-sheet.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  Carousel,\n  CarouselContent,\n  CarouselIndicator,\n  CarouselIndicatorGroup,\n  CarouselItem,\n  CarouselNext,\n  CarouselPrevious,\n  CarouselViewport,\n  createCarouselController,\n} from \"@ui-sdk/react/carousel\"\nimport {\n  createDialogController,\n  Dialog,\n  DialogBackdrop,\n  DialogClose,\n  DialogContent,\n  DialogTitle,\n  DialogTrigger,\n} from \"@ui-sdk/react/dialog\"\nimport { ChevronLeftIcon, ChevronRightIcon, XIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport type ContactSheetPhoto = {\n  src: string\n  alt: string\n  /** A smaller file for the grid and the strip. Falls back to `src`. */\n  thumb?: string\n  caption?: React.ReactNode\n}\n\ntype ContactSheetProps = Omit<React.ComponentProps<\"div\">, \"children\"> & {\n  photos: ContactSheetPhoto[]\n  /** Names the grid, the lightbox and its carousel. */\n  label?: string\n  /** A fixed column count. Without it the grid fits as many 9rem columns as there's room for. */\n  columns?: number\n  /** Next on the last photo goes round to the first. */\n  loop?: boolean\n  /** Small frame numbers under each thumbnail, like a darkroom contact sheet. */\n  frameNumbers?: boolean\n  /** Called with the photo's index when the lightbox opens or pages, and `null` when it closes. */\n  onIndexChange?: (index: number | null) => void\n}\n\n/** Centre of an element as a CSS transform origin, in viewport px. */\nfunction originOf(el: Element | null | undefined) {\n  if (!el) return \"50% 50%\"\n  const r = el.getBoundingClientRect()\n  return `${Math.round(r.left + r.width / 2)}px ${Math.round(r.top + r.height / 2)}px`\n}\n\n/** Scrolls only the strip, unlike scrollIntoView, which can also move the page behind the dialog. */\nfunction centerInStrip(strip: HTMLElement | null, index: number) {\n  const item = strip?.querySelectorAll<HTMLElement>(\"[data-slot=carousel-indicator]\")[index]\n  if (!strip || !item) return\n  strip.scrollLeft = item.offsetLeft - (strip.clientWidth - item.offsetWidth) / 2\n}\n\nfunction ContactSheet({\n  photos,\n  label = \"Photos\",\n  columns,\n  loop = false,\n  frameNumbers = true,\n  onIndexChange,\n  className,\n  style,\n  ...props\n}: ContactSheetProps) {\n  const [dialog] = React.useState(() => createDialogController())\n  const [carousel] = React.useState(() => createCarouselController())\n  const [page, setPage] = React.useState(1)\n  const [origin, setOrigin] = React.useState(\"50% 50%\")\n  const thumbs = React.useRef<(HTMLButtonElement | null)[]>([])\n  const strip = React.useRef<HTMLDivElement>(null)\n  const viewport = React.useRef<HTMLDivElement>(null)\n\n  const show = (next: number) => {\n    setPage(next)\n    onIndexChange?.(next - 1)\n    centerInStrip(strip.current, next - 1)\n  }\n\n  if (photos.length === 0) return null\n\n  return (\n    <div\n      data-slot=\"contact-sheet\"\n      className={cn(\"w-full\", className)}\n      style={{ ...style, ...(columns ? { \"--contact-sheet-columns\": columns } : null) } as React.CSSProperties}\n      {...props}\n    >\n      <ul\n        aria-label={label}\n        className={cn(\n          \"grid gap-3\",\n          columns\n            ? \"grid-cols-[repeat(var(--contact-sheet-columns),minmax(0,1fr))]\"\n            : \"grid-cols-[repeat(auto-fill,minmax(min(9rem,100%),1fr))]\"\n        )}\n      >\n        {photos.map((photo, index) => (\n          <li key={photo.src} className=\"flex min-w-0 flex-col gap-1.5\">\n            <DialogTrigger\n              controller={dialog}\n              ref={(el: HTMLButtonElement | null) => {\n                thumbs.current[index] = el\n              }}\n              onClick={(event: React.MouseEvent<HTMLButtonElement>) => {\n                setOrigin(originOf(event.currentTarget))\n                setPage(index + 1)\n                onIndexChange?.(index)\n              }}\n              className={cn(\n                \"group/thumb relative block aspect-[4/3] w-full cursor-zoom-in overflow-hidden rounded-xl bg-muted\",\n                \"ring-1 ring-foreground/10 outline-none ring-inset\",\n                \"transition-transform duration-150 ease-out active:scale-[0.97]\",\n                \"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\"\n              )}\n            >\n              {/* eslint-disable-next-line @next/next/no-img-element */}\n              <img\n                src={photo.thumb ?? photo.src}\n                alt={photo.alt}\n                loading=\"lazy\"\n                decoding=\"async\"\n                draggable={false}\n                className={cn(\n                  \"size-full object-cover transition-[filter] duration-200 ease-out\",\n                  \"[@media(hover:hover)_and_(pointer:fine)]:group-hover/thumb:brightness-110\"\n                )}\n              />\n            </DialogTrigger>\n            {frameNumbers && (\n              <span aria-hidden className=\"font-mono text-[10px] leading-none tracking-wider text-muted-foreground tabular-nums\">\n                {String(index + 1).padStart(2, \"0\")}\n              </span>\n            )}\n          </li>\n        ))}\n      </ul>\n\n      <Dialog\n        controller={dialog}\n        onOpenChange={(open: boolean) => {\n          if (open) return\n          // Shrink back into the photo the viewer ended on, which is also where focus returns.\n          setOrigin(originOf(thumbs.current[page - 1]))\n          onIndexChange?.(null)\n        }}\n      >\n        <DialogBackdrop\n          className={cn(\n            \"fixed inset-0 bg-black/90 backdrop-blur-sm\",\n            \"transition-opacity duration-200 ease-out\",\n            \"data-starting-style:opacity-0 data-ending-style:opacity-0 data-ending-style:duration-150\"\n          )}\n        />\n        <DialogContent\n          initialFocus={() => viewport.current}\n          finalFocus={() => thumbs.current[page - 1]}\n          style={{ transformOrigin: origin }}\n          className={cn(\n            \"fixed inset-0 m-0 size-full max-h-none max-w-none bg-transparent p-0 text-white outline-none\",\n            \"transition-[opacity,scale] duration-[240ms] ease-[cubic-bezier(0.23,1,0.32,1)]\",\n            \"data-starting-style:scale-[0.92] data-starting-style:opacity-0\",\n            \"data-ending-style:scale-[0.92] data-ending-style:opacity-0 data-ending-style:duration-150\",\n            \"motion-reduce:data-starting-style:scale-100 motion-reduce:data-ending-style:scale-100\"\n          )}\n          onKeyDown={(event: React.KeyboardEvent) => {\n            // The viewport and the strip page with arrows themselves; this covers the buttons around them.\n            const target = event.target as HTMLElement\n            if (target.closest(\"[data-slot=carousel-viewport], [data-slot=carousel-indicator-group]\")) return\n            if (event.key === \"ArrowRight\") carousel.next()\n            else if (event.key === \"ArrowLeft\") carousel.previous()\n          }}\n        >\n          <Carousel\n            aria-label={label}\n            controller={carousel}\n            loop={loop}\n            page={page}\n            onPageChange={show}\n            className=\"grid size-full grid-cols-[minmax(0,1fr)] grid-rows-[auto_minmax(0,1fr)_auto]\"\n          >\n            <header className=\"flex items-center justify-between gap-4 px-4 pt-4 sm:px-6\">\n              <DialogTitle className=\"min-w-0 truncate text-sm font-medium text-white/90\">{label}</DialogTitle>\n              <div className=\"flex items-center gap-3\">\n                <span aria-hidden className=\"font-mono text-xs text-white/60 tabular-nums\">\n                  {page} / {photos.length}\n                </span>\n                <DialogClose\n                  aria-label=\"Close\"\n                  className={cn(\n                    \"grid size-9 place-items-center rounded-full bg-white/10 text-white\",\n                    \"transition-[background-color,scale] duration-150 ease-out active:scale-[0.94]\",\n                    \"[@media(hover:hover)_and_(pointer:fine)]:hover:bg-white/20\",\n                    \"outline-none focus-visible:ring-2 focus-visible:ring-white/80\"\n                  )}\n                >\n                  <XIcon aria-hidden className=\"size-4\" />\n                </DialogClose>\n              </div>\n            </header>\n\n            <div className=\"relative min-h-0\">\n              <CarouselViewport\n                ref={viewport}\n                className=\"size-full [scrollbar-width:none] outline-none focus-visible:ring-1 focus-visible:ring-white/40 focus-visible:ring-inset\"\n              >\n                <CarouselContent className=\"h-full\">\n                  {photos.map((photo, index) => (\n                    <CarouselItem key={photo.src} aria-label={photo.alt} className=\"h-full basis-full overflow-clip\">\n                      <figure className=\"flex size-full flex-col items-center justify-center gap-3 px-4 py-4 sm:px-20\">\n                        {/* eslint-disable-next-line @next/next/no-img-element */}\n                        <img\n                          src={photo.src}\n                          alt={photo.alt}\n                          loading={Math.abs(index + 1 - page) <= 1 ? \"eager\" : \"lazy\"}\n                          decoding=\"async\"\n                          draggable={false}\n                          className=\"min-h-0 max-w-full flex-1 rounded-lg object-contain select-none\"\n                        />\n                        {photo.caption && (\n                          <figcaption className=\"max-w-prose text-center text-sm text-pretty text-white/75\">\n                            {photo.caption}\n                          </figcaption>\n                        )}\n                      </figure>\n                    </CarouselItem>\n                  ))}\n                </CarouselContent>\n              </CarouselViewport>\n              <CarouselPrevious aria-label=\"Previous photo\" className={stepClass(\"left-3 sm:left-5\")}>\n                <ChevronLeftIcon aria-hidden className=\"size-5\" />\n              </CarouselPrevious>\n              <CarouselNext aria-label=\"Next photo\" className={stepClass(\"right-3 sm:right-5\")}>\n                <ChevronRightIcon aria-hidden className=\"size-5\" />\n              </CarouselNext>\n            </div>\n\n            <CarouselIndicatorGroup\n              ref={(el: HTMLDivElement | null) => {\n                strip.current = el\n                // Mounts as the lightbox opens: start with the current frame in view.\n                centerInStrip(el, page - 1)\n              }}\n              aria-label=\"Choose a photo\"\n              className=\"relative flex gap-2 overflow-x-auto px-4 pt-3 pb-4 [scrollbar-width:none] sm:justify-center-safe sm:px-6\"\n            >\n              {photos.map((photo, index) => (\n                <CarouselIndicator\n                  key={photo.src}\n                  page={index + 1}\n                  aria-label={photo.alt}\n                  className={cn(\n                    \"relative h-12 w-16 shrink-0 overflow-hidden rounded-md opacity-45\",\n                    \"transition-[opacity,scale] duration-150 ease-out active:scale-[0.95]\",\n                    \"data-selected:opacity-100 data-selected:ring-2 data-selected:ring-white\",\n                    \"[@media(hover:hover)_and_(pointer:fine)]:hover:opacity-80\",\n                    \"outline-none focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-white/80\"\n                  )}\n                >\n                  {/* eslint-disable-next-line @next/next/no-img-element */}\n                  <img\n                    src={photo.thumb ?? photo.src}\n                    alt=\"\"\n                    loading=\"lazy\"\n                    decoding=\"async\"\n                    draggable={false}\n                    className=\"size-full object-cover\"\n                  />\n                </CarouselIndicator>\n              ))}\n            </CarouselIndicatorGroup>\n          </Carousel>\n        </DialogContent>\n      </Dialog>\n    </div>\n  )\n}\n\nfunction stepClass(side: string) {\n  return cn(\n    \"absolute top-1/2 hidden size-11 -translate-y-1/2 place-items-center rounded-full bg-white/10 text-white backdrop-blur-md sm:grid\",\n    \"transition-[background-color,opacity,scale] duration-150 ease-out active:scale-[0.94]\",\n    \"[@media(hover:hover)_and_(pointer:fine)]:hover:bg-white/20\",\n    // At the ends they stay focusable (aria-disabled), so dim rather than hide them.\n    \"data-disabled:cursor-default data-disabled:opacity-30\",\n    \"outline-none focus-visible:ring-2 focus-visible:ring-white/80\",\n    side\n  )\n}\n\nexport { ContactSheet }\n",
      "type": "registry:component"
    }
  ],
  "meta": {
    "look": "modern",
    "addedAt": "2026-11-30"
  },
  "docs": "Add `@layer ui-sdk;` at the top of your global stylesheet, above `@import \"tailwindcss\"`.",
  "type": "registry:component"
}