{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fold-report",
  "title": "Fold Report",
  "description": "An accordion whose rows unfold like folded paper, top to bottom, and fold back up from the end.",
  "dependencies": [
    "animejs"
  ],
  "registryDependencies": [
    "https://spotcheckui.com/r/spotcheck-base.json",
    "https://spotcheckui.com/r/use-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/spotcheck/components/spotcheck/fold-report.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { animate, stagger, utils } from \"animejs\"\n\nimport { cn } from \"@/lib/utils\"\nimport { useReducedMotion } from \"@/registry/spotcheck/hooks/use-reduced-motion\"\n\nconst OPEN_MS = 520\nconst CLOSE_MS = 420\nconst CLOSE_DELAY_MS = 120\nconst ROW_OPEN_MS = 720\nconst ROW_CLOSE_MS = 260\nconst ROW_OPEN_STAGGER_MS = 75\nconst ROW_CLOSE_STAGGER_MS = 30\nconst OPEN_FROM_DEGREES = -100\nconst CLOSE_TO_DEGREES = 80\n\ntype FoldContextValue = {\n  open: string | null\n  toggle: (value: string) => void\n}\n\nconst FoldContext = React.createContext<FoldContextValue | null>(null)\n\ntype FoldReportProps = Omit<React.ComponentProps<\"div\">, \"defaultValue\"> & {\n  /** The section open at the start. */\n  defaultOpen?: string\n  /** The open section, when you control it. Use `null` for none. */\n  open?: string | null\n  /** Runs when a section opens or closes. */\n  onOpenChange?: (open: string | null) => void\n}\n\nexport function FoldReport({ defaultOpen, open, onOpenChange, className, children, ...props }: FoldReportProps) {\n  const [internal, setInternal] = React.useState<string | null>(defaultOpen ?? null)\n  const current = open !== undefined ? open : internal\n\n  const context = React.useMemo(\n    () => ({\n      open: current,\n      toggle: (value: string) => {\n        const next = current === value ? null : value\n        setInternal(next)\n        onOpenChange?.(next)\n      },\n    }),\n    [current, onOpenChange],\n  )\n\n  return (\n    <FoldContext.Provider value={context}>\n      <div className={cn(\"flex min-w-0 flex-col font-(family-name:--f-body)\", className)} {...props}>\n        {children}\n      </div>\n    </FoldContext.Provider>\n  )\n}\n\ntype FoldSectionProps = Omit<React.ComponentProps<\"div\">, \"title\"> & {\n  /** Identifies the section. */\n  value: string\n  title: React.ReactNode\n  /** A short note at the end of the header, such as a count. */\n  meta?: React.ReactNode\n}\n\nexport function FoldSection({ value, title, meta, className, children, ...props }: FoldSectionProps) {\n  const context = React.useContext(FoldContext)\n  if (!context) throw new Error(\"FoldSection must be inside FoldReport\")\n  const expanded = context.open === value\n\n  const reduced = useReducedMotion()\n  const baseId = React.useId()\n  const body = React.useRef<HTMLDivElement>(null)\n  const inner = React.useRef<HTMLDivElement>(null)\n  const painted = React.useRef(expanded)\n  const [startsHidden] = React.useState(!expanded)\n\n  React.useLayoutEffect(() => {\n    const panel = body.current\n    if (!panel || !inner.current || painted.current === expanded) return\n    painted.current = expanded\n    const rows = inner.current.querySelectorAll<HTMLElement>(\"[data-fold-row]\")\n\n    utils.remove(panel)\n    utils.remove(rows)\n\n    const finish = () => {\n      panel.style.height = \"\"\n      rows.forEach((row) => {\n        row.style.transform = \"\"\n        row.style.opacity = \"\"\n      })\n    }\n\n    if (reduced) {\n      finish()\n      panel.hidden = !expanded\n      return\n    }\n\n    if (expanded) {\n      // A close that gets interrupted reopens from where it had reached.\n      const from = panel.hidden ? 0 : panel.offsetHeight\n      panel.hidden = false\n      // Rows wait out their stagger, so they start hidden rather than flashing into place.\n      rows.forEach((row) => {\n        row.style.opacity = \"0\"\n      })\n      animate(panel, {\n        height: [from, inner.current.offsetHeight],\n        duration: OPEN_MS,\n        ease: \"outQuart\",\n        onComplete: () => {\n          panel.style.height = \"\"\n        },\n      })\n      animate(rows, {\n        rotateX: [OPEN_FROM_DEGREES, 0],\n        opacity: [0, 1],\n        duration: ROW_OPEN_MS,\n        delay: stagger(ROW_OPEN_STAGGER_MS),\n        ease: \"outBack(1.2)\",\n        onComplete: finish,\n      })\n      return\n    }\n\n    animate(rows, {\n      rotateX: [0, CLOSE_TO_DEGREES],\n      opacity: [1, 0],\n      duration: ROW_CLOSE_MS,\n      delay: stagger(ROW_CLOSE_STAGGER_MS, { from: \"last\" }),\n      ease: \"inQuad\",\n    })\n    animate(panel, {\n      height: [panel.offsetHeight, 0],\n      duration: CLOSE_MS,\n      delay: CLOSE_DELAY_MS,\n      ease: \"inOutQuart\",\n      onComplete: () => {\n        finish()\n        panel.hidden = true\n      },\n    })\n  }, [expanded, reduced])\n\n  return (\n    <div data-open={expanded || undefined} className={cn(\"group/fold\", className)} {...props}>\n      <h3>\n        <button\n          type=\"button\"\n          id={`${baseId}-header`}\n          aria-expanded={expanded}\n          aria-controls={`${baseId}-panel`}\n          className=\"spotcheck-focus group-data-open/fold:border-ink grid w-full cursor-pointer grid-cols-[minmax(0,1fr)_auto_1.4rem] items-end gap-2.5 border-b border-[color-mix(in_srgb,var(--ink)_30%,transparent)] pt-3 pb-1.5 text-left\"\n          onClick={() => context.toggle(value)}\n        >\n          <span className=\"spotcheck-heading text-[21px] leading-none\">{title}</span>\n          {meta !== undefined && <span className=\"spotcheck-label\">{meta}</span>}\n          <span\n            aria-hidden\n            className=\"group-data-open/fold:text-accent-ink col-start-3 text-center font-(family-name:--f-mono) text-xl leading-none transition-transform duration-300 group-data-open/fold:rotate-45 motion-reduce:transition-none\"\n          >\n            +\n          </span>\n        </button>\n      </h3>\n      <div\n        ref={body}\n        id={`${baseId}-panel`}\n        role=\"region\"\n        aria-labelledby={`${baseId}-header`}\n        hidden={startsHidden}\n        className=\"overflow-hidden\"\n      >\n        <div ref={inner} className=\"pt-0.5 pb-2.5 perspective-[700px]\">\n          {children}\n        </div>\n      </div>\n    </div>\n  )\n}\n\ntype FoldRowProps = React.ComponentProps<\"div\"> & {\n  /** The short note on the left, such as a time. */\n  label?: React.ReactNode\n}\n\nexport function FoldRow({ label, className, children, ...props }: FoldRowProps) {\n  return (\n    <div\n      data-fold-row\n      className={cn(\n        \"bg-paper grid origin-top grid-cols-[4.6rem_minmax(0,1fr)] gap-2.5 border-b border-dashed border-[color-mix(in_srgb,var(--ink)_25%,transparent)] pt-2 pb-[3px] text-sm\",\n        className,\n      )}\n      {...props}\n    >\n      <span className=\"text-mute font-(family-name:--f-mono) text-[11.5px] tabular-nums\">{label}</span>\n      <span className=\"min-w-0\">{children}</span>\n    </div>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "depth"
  ],
  "type": "registry:component"
}