{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "contact-sheet",
  "title": "Contact sheet",
  "description": "A photographer's contact sheet: every frame at once on a strip of film, marked with a grease pencil. Circle the keepers, cross out the rest. For reviewing generated images, design variants and screenshots.",
  "dependencies": [
    "cn"
  ],
  "registryDependencies": [
    "https://bevel-ui.vercel.app/r/bevel.json"
  ],
  "files": [
    {
      "path": "registry/bevel/ui/contact-sheet.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { cn } from \"cn\"\n\ntype Mark = \"pick\" | \"reject\"\n\ntype ContactSheetContextValue = {\n  ids: string[]\n  register: (id: string) => () => void\n  marks: Record<string, Mark>\n  setMark: (id: string, mark: Mark | null) => void\n  focused: string | undefined\n  setFocused: (id: string) => void\n  move: (from: string, key: string) => void\n}\n\nconst ContactSheetContext = React.createContext<ContactSheetContextValue | null>(null)\n\nfunction useContactSheet() {\n  const context = React.useContext(ContactSheetContext)\n  if (!context) throw new Error(\"ContactSheet parts must be inside <ContactSheet>\")\n  return context\n}\n\ntype ContactSheetProps = Omit<React.ComponentProps<\"div\">, \"defaultValue\"> & {\n  /** Marks by frame id. Unmarked frames are left out. */\n  value?: Record<string, Mark>\n  defaultValue?: Record<string, Mark>\n  onValueChange?: (value: Record<string, Mark>) => void\n  /** Frames per row. Arrow keys move by row with it. */\n  columns?: number\n}\n\n/**\n * A contact sheet: every frame at once, marked with a grease pencil.\n * Circle the keepers, cross out the rest. Arrow keys move between frames;\n * P picks, X rejects, Backspace clears, Enter cycles. Give it an aria-label.\n */\nfunction ContactSheet({\n  className,\n  value,\n  defaultValue = {},\n  onValueChange,\n  columns = 4,\n  style,\n  children,\n  ...props\n}: ContactSheetProps) {\n  const [ids, setIds] = React.useState<string[]>([])\n  const [uncontrolled, setUncontrolled] = React.useState(defaultValue)\n  const [focused, setFocused] = React.useState<string>()\n  const marks = value ?? uncontrolled\n  const frames = React.useRef<HTMLDivElement>(null)\n\n  const register = React.useCallback((id: string) => {\n    setIds((all) => (all.includes(id) ? all : [...all, id]))\n    return () => setIds((all) => all.filter((x) => x !== id))\n  }, [])\n  const setMark = React.useCallback(\n    (id: string, mark: Mark | null) => {\n      const next = { ...marks }\n      if (mark) next[id] = mark\n      else delete next[id]\n      setUncontrolled(next)\n      onValueChange?.(next)\n    },\n    [marks, onValueChange]\n  )\n  const move = React.useCallback(\n    (from: string, key: string) => {\n      const i = ids.indexOf(from)\n      const steps: Record<string, number> = { ArrowRight: 1, ArrowLeft: -1, ArrowDown: columns, ArrowUp: -columns }\n      const to = key === \"Home\" ? 0 : key === \"End\" ? ids.length - 1 : i + (steps[key] ?? 0)\n      const id = ids[to]\n      if (to < 0 || !id) return\n      setFocused(id)\n      frames.current?.querySelector<HTMLElement>(`[data-frame-id=\"${CSS.escape(id)}\"]`)?.focus()\n    },\n    [ids, columns]\n  )\n\n  const context = React.useMemo(\n    () => ({ ids, register, marks, setMark, focused: focused ?? ids[0], setFocused, move }),\n    [ids, register, marks, setMark, focused, move]\n  )\n  const picked = Object.values(marks).filter((m) => m === \"pick\").length\n  return (\n    <ContactSheetContext value={context}>\n      <div\n        role=\"group\"\n        data-slot=\"contact-sheet\"\n        className={cn(\"bevel-paper flex w-full flex-col gap-2 rounded-(--bevel-radius-xs) p-3\", className)}\n        style={{ \"--contact-sheet-columns\": columns, ...style } as React.CSSProperties}\n        {...props}\n      >\n        <div\n          ref={frames}\n          className=\"grid grid-cols-[repeat(var(--contact-sheet-columns),minmax(0,1fr))] gap-y-2 bg-(--contact-sheet-film) px-1 py-4 shadow-(--bevel-depth-sheet)\"\n        >\n          {children}\n        </div>\n        <p role=\"status\" className=\"text-xs text-(--bevel-paper-muted)\">\n          {picked} picked of {ids.length}\n        </p>\n      </div>\n    </ContactSheetContext>\n  )\n}\n\ntype ContactSheetFrameProps = Omit<React.ComponentProps<\"button\">, \"id\"> & {\n  id: string\n  /** What's in the frame, for its name: “Dunes at dusk”. */\n  label: string\n}\n\n/** One frame. Its picture is the children. */\nfunction ContactSheetFrame({ className, id, label, children, onKeyDown, onFocus, ...props }: ContactSheetFrameProps) {\n  const { ids, register, marks, setMark, focused, setFocused, move } = useContactSheet()\n  React.useEffect(() => register(id), [id, register])\n  const mark = marks[id]\n  const number = ids.indexOf(id) + 1\n  const cycle: Record<string, Mark | null> = { none: \"pick\", pick: \"reject\", reject: null }\n  return (\n    <button\n      type=\"button\"\n      data-slot=\"contact-sheet-frame\"\n      data-frame-id={id}\n      data-mark={mark}\n      tabIndex={focused === id ? 0 : -1}\n      aria-keyshortcuts=\"P X Backspace\"\n      onFocus={(event) => {\n        onFocus?.(event)\n        setFocused(id)\n      }}\n      onClick={() => setMark(id, cycle[mark ?? \"none\"]!)}\n      onKeyDown={(event) => {\n        onKeyDown?.(event)\n        const key = event.key.toLowerCase()\n        if (key === \"p\") setMark(id, mark === \"pick\" ? null : \"pick\")\n        else if (key === \"x\") setMark(id, mark === \"reject\" ? null : \"reject\")\n        else if (event.key === \"Backspace\" || event.key === \"Delete\") setMark(id, null)\n        else if ([\"ArrowRight\", \"ArrowLeft\", \"ArrowUp\", \"ArrowDown\", \"Home\", \"End\"].includes(event.key)) move(id, event.key)\n        else return\n        event.preventDefault()\n      }}\n      className={cn(\n        \"group/frame relative flex flex-col gap-1 px-1 text-left outline-none\",\n        \"focus-visible:ring-2 focus-visible:ring-(--contact-sheet-sprocket)\",\n        className\n      )}\n      {...props}\n    >\n      {/* Sprocket holes above and below, as on 35mm film. */}\n      <span aria-hidden className=\"absolute inset-x-1 -top-3 flex justify-around\">\n        {Array.from({ length: 4 }, (_, i) => (\n          <span key={i} className=\"h-1.5 w-1 rounded-(--bevel-radius-xs) bg-(--contact-sheet-sprocket) opacity-80\" />\n        ))}\n      </span>\n      <span className=\"relative block aspect-[3/2] overflow-hidden bg-(--bevel-shade-strong) transition-opacity duration-(--bevel-duration-small) group-data-[mark=reject]/frame:opacity-45 motion-reduce:transition-none\">\n        {children}\n      </span>\n      {/* The edge-printed frame number starts the name: “3. Dusk, low sun, picked”. */}\n      <span aria-hidden className=\"font-mono text-(length:--bevel-fine) text-(--contact-sheet-edge-print)\">\n        {number}\n      </span>\n      <span className=\"sr-only\">\n        {`${number}. ${label}${mark === \"pick\" ? \", picked\" : mark === \"reject\" ? \", rejected\" : \"\"}`}\n      </span>\n      {/* Grease pencil: a loose circle to keep, a cross to drop. */}\n      <svg\n        aria-hidden\n        viewBox=\"0 0 100 70\"\n        preserveAspectRatio=\"none\"\n        className=\"pointer-events-none absolute inset-x-0 -top-1 aspect-[3/2] w-full overflow-visible\"\n      >\n        <path\n          d=\"M14 38 C10 14 40 4 62 7 C88 10 96 30 88 50 C80 66 40 70 22 60 C10 53 8 40 18 30\"\n          fill=\"none\"\n          stroke=\"var(--contact-sheet-pick)\"\n          strokeWidth=\"4\"\n          strokeLinecap=\"round\"\n          className=\"origin-center scale-90 opacity-0 transition-[opacity,scale] duration-(--bevel-duration-small) ease-(--bevel-ease-out) group-data-[mark=pick]/frame:scale-100 group-data-[mark=pick]/frame:opacity-100 motion-reduce:transition-none\"\n        />\n        <path\n          d=\"M18 12 L84 60 M82 10 L20 62\"\n          fill=\"none\"\n          stroke=\"var(--contact-sheet-reject)\"\n          strokeWidth=\"4\"\n          strokeLinecap=\"round\"\n          className=\"origin-center scale-90 opacity-0 transition-[opacity,scale] duration-(--bevel-duration-small) ease-(--bevel-ease-out) group-data-[mark=reject]/frame:scale-100 group-data-[mark=reject]/frame:opacity-90 motion-reduce:transition-none\"\n        />\n      </svg>\n    </button>\n  )\n}\n\nexport { ContactSheet, ContactSheetFrame }\nexport type { ContactSheetProps, ContactSheetFrameProps }\n",
      "type": "registry:ui"
    }
  ],
  "css": {
    ":root": {
      "--contact-sheet-film": "oklch(0.17 0.01 60)",
      "--contact-sheet-edge-print": "oklch(0.72 0.12 70)",
      "--contact-sheet-sprocket": "oklch(0.93 0.01 90)",
      "--contact-sheet-pick": "oklch(0.6 0.22 27)",
      "--contact-sheet-reject": "oklch(0.96 0.01 90)",
      "--contact-sheet-columns": "4"
    },
    "[data-slot=\"contact-sheet-frame\"]": {
      "--bevel-ink": "var(--contact-sheet-pick)"
    }
  },
  "categories": [
    "records"
  ],
  "type": "registry:ui"
}