{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "document-folder-stack",
  "title": "Document Folder Stack",
  "description": "A tabbed folder that opens when you point at it: the front flap hinges forward in 3D and the documents inside rise and fan out one after another, each with a file-type tag, title and meta line; click a document to lift it to the front.",
  "dependencies": [
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/document-folder-stack/document-folder-stack.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 type FolderDocType = \"pdf\" | \"doc\" | \"xls\" | \"img\" | \"txt\";\n\nexport interface FolderDocument {\n  id: string;\n  title: string;\n  type?: FolderDocType;\n  /** Small mono line, e.g. a date or size. */\n  meta?: string;\n}\n\nexport type DocumentFolderTheme = \"dark\" | \"light\";\n\nexport interface DocumentFolderStackProps extends Omit<React.ComponentPropsWithoutRef<\"div\">, \"children\"> {\n  label?: string;\n  /** Shown under the label, e.g. \"Updated 2d ago\". Defaults to the document count. */\n  caption?: string;\n  documents?: FolderDocument[];\n  /** Folder colour. */\n  color?: string;\n  /** Controlled open state; otherwise it opens on hover, keyboard focus or tap. */\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  onDocumentClick?: (doc: FolderDocument) => void;\n  theme?: DocumentFolderTheme;\n}\n\nconst DOCS: FolderDocument[] = [\n  { id: \"msa\", title: \"Master services agreement\", type: \"pdf\", meta: \"12 pages · Oct 2\" },\n  { id: \"sow\", title: \"Statement of work — Q4\", type: \"doc\", meta: \"6 pages · Oct 18\" },\n  { id: \"rates\", title: \"Rate card 2026\", type: \"xls\", meta: \"2 sheets · Nov 1\" },\n];\n\nconst TYPE_STYLE: Record<FolderDocType, { label: string; color: string }> = {\n  pdf: { label: \"PDF\", color: \"#e5484d\" },\n  doc: { label: \"DOC\", color: \"#3e7bfa\" },\n  xls: { label: \"XLS\", color: \"#2f9e64\" },\n  img: { label: \"IMG\", color: \"#d97706\" },\n  txt: { label: \"TXT\", color: \"#71717a\" },\n};\n\n/** Lines of fake text with varied lengths, stable per document. */\nfunction lines(seed: string, count: number) {\n  let h = 0;\n  for (const c of seed) h = (h * 31 + c.charCodeAt(0)) >>> 0;\n  return Array.from({ length: count }, (_, i) => 55 + ((h >> (i * 3)) % 40));\n}\n\nexport function DocumentFolderStack({\n  label = \"Contracts\",\n  caption,\n  documents = DOCS,\n  color = \"#d9c7a7\",\n  open: openProp,\n  defaultOpen = false,\n  onOpenChange,\n  onDocumentClick,\n  theme = \"dark\",\n  className,\n  style,\n  ...props\n}: DocumentFolderStackProps) {\n  const light = theme === \"light\";\n  const [hoverOpen, setHoverOpen] = React.useState(false);\n  const [focusOpen, setFocusOpen] = React.useState(false);\n  const [tapOpen, setTapOpen] = React.useState(defaultOpen);\n  const [active, setActive] = React.useState<string | null>(null);\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const open = openProp ?? (hoverOpen || focusOpen || tapOpen);\n  const docs = documents.slice(0, 4);\n  const n = docs.length;\n\n  const prevOpen = React.useRef(open);\n  React.useEffect(() => {\n    if (prevOpen.current !== open) onOpenChange?.(open);\n    prevOpen.current = open;\n  }, [open, onOpenChange]);\n\n  // A tap outside closes a folder opened by touch.\n  React.useEffect(() => {\n    if (!tapOpen) return;\n    const close = (event: PointerEvent) => {\n      if (!rootRef.current?.contains(event.target as Node)) {\n        setTapOpen(false);\n        setActive(null);\n      }\n    };\n    document.addEventListener(\"pointerdown\", close);\n    return () => document.removeEventListener(\"pointerdown\", close);\n  }, [tapOpen]);\n\n  const ease = \"cubic-bezier(.2,.8,.2,1)\";\n  const paper = light ? \"#ffffff\" : \"#f4f3ef\";\n\n  return (\n    <div\n      ref={rootRef}\n      className={cn(\"group/folder relative w-[240px] select-none\", className)}\n      // An open folder draws above its neighbours, so its fanned papers can overlap them.\n      style={{ zIndex: open ? 20 : 1, ...style }}\n      onPointerEnter={(event) => event.pointerType === \"mouse\" && setHoverOpen(true)}\n      onPointerLeave={() => {\n        setHoverOpen(false);\n        setActive(null);\n      }}\n      onFocus={(event) => (event.target as HTMLElement).matches(\":focus-visible\") && setFocusOpen(true)}\n      onBlur={(event) => {\n        if (!event.currentTarget.contains(event.relatedTarget)) {\n          setFocusOpen(false);\n          setActive(null);\n        }\n      }}\n      {...props}\n    >\n      <div className=\"relative h-[200px] [perspective:900px]\">\n        {/* Back panel with its tab. */}\n        <div aria-hidden=\"true\" className=\"absolute inset-x-0 bottom-0 h-[176px]\">\n          <div className=\"absolute top-[-14px] left-0 h-[22px] w-[96px] rounded-t-[10px]\" style={{ background: color, filter: \"brightness(.86)\" }} />\n          <div className=\"absolute inset-0 rounded-[14px] rounded-tl-none\" style={{ background: color, filter: \"brightness(.86)\" }} />\n        </div>\n\n        {/* Documents: tucked inside at rest, rising and fanning out when the folder opens. */}\n        {docs.map((doc, i) => {\n          const t = n === 1 ? 0 : i / (n - 1) - 0.5; // -0.5 … 0.5\n          const isActive = active === doc.id;\n          const type = TYPE_STYLE[doc.type ?? \"txt\"];\n          const rest = `translate(${t * 10}px, ${-i * 4}px) rotate(${t * 3}deg)`;\n          const fanned = `translate(${t * 156}px, ${-98 - (0.5 - Math.abs(t)) * 28}px) rotate(${t * 15}deg)`;\n          const lifted = `translate(${t * 60}px, -132px) rotate(${t * 4}deg) scale(1.08)`;\n          return (\n            <button\n              key={doc.id}\n              type=\"button\"\n              tabIndex={open ? 0 : -1}\n              aria-hidden={!open}\n              aria-label={`${doc.title}${doc.meta ? `, ${doc.meta}` : \"\"}`}\n              onClick={() => {\n                setActive(isActive ? null : doc.id);\n                onDocumentClick?.(doc);\n              }}\n              className=\"absolute bottom-[18px] left-1/2 -ml-[86px] h-[150px] w-[172px] origin-bottom cursor-pointer rounded-[8px] p-3 text-left outline-none focus-visible:ring-2 focus-visible:ring-offset-2 motion-reduce:transition-none\"\n              style={{\n                background: paper,\n                color: \"#1b1b1f\",\n                zIndex: isActive ? 30 : 10 + i,\n                boxShadow: \"0 1px 0 rgba(0,0,0,.04), 0 10px 22px -12px rgba(0,0,0,.45)\",\n                transform: !open ? rest : isActive ? lifted : fanned,\n                transition: `transform 520ms ${ease} ${open ? i * 55 : (n - 1 - i) * 30}ms`,\n                [\"--tw-ring-color\" as string]: light ? \"#141414\" : \"#f4f4f2\",\n                [\"--tw-ring-offset-color\" as string]: light ? \"#f1f1ef\" : \"#0a0a0a\",\n              }}\n            >\n              <span className=\"flex items-center justify-between\">\n                <span className=\"rounded-[4px] px-1.5 py-0.5 font-mono text-[8.5px] font-semibold tracking-wide text-white\" style={{ background: type.color }}>\n                  {type.label}\n                </span>\n                <span aria-hidden=\"true\" className=\"size-1.5 rounded-full bg-black/15\" />\n              </span>\n              <span className=\"mt-2 line-clamp-2 block text-[11.5px] leading-snug font-semibold\">{doc.title}</span>\n              <span aria-hidden=\"true\" className=\"mt-2 block space-y-1.5\">\n                {lines(doc.id, 4).map((w, j) => (\n                  <span key={j} className=\"block h-[3px] rounded-full bg-black/10\" style={{ width: `${w}%` }} />\n                ))}\n              </span>\n              {doc.meta && <span className=\"absolute bottom-2.5 left-3 font-mono text-[8.5px] text-black/45\">{doc.meta}</span>}\n            </button>\n          );\n        })}\n\n        {/* Front panel: hinges forward at its bottom edge when the folder opens. */}\n        <button\n          type=\"button\"\n          aria-expanded={open}\n          aria-label={`${label} folder, ${n} document${n === 1 ? \"\" : \"s\"}`}\n          onPointerDown={(event) => {\n            if (event.pointerType !== \"mouse\") setTapOpen((o) => !o);\n          }}\n          onKeyDown={(event) => {\n            if (event.key === \"Enter\" || event.key === \" \") {\n              event.preventDefault();\n              setTapOpen((o) => !o);\n              setFocusOpen(false);\n            }\n          }}\n          className=\"absolute inset-x-0 bottom-0 z-20 h-[150px] origin-bottom cursor-pointer rounded-[14px] outline-none focus-visible:ring-2 focus-visible:ring-offset-2 motion-reduce:transition-none\"\n          style={{\n            background: `linear-gradient(180deg, ${color}, color-mix(in srgb, ${color} 88%, #000))`,\n            boxShadow: \"inset 0 1px 0 rgba(255,255,255,.45), 0 18px 30px -18px rgba(0,0,0,.55)\",\n            transform: open ? \"rotateX(-48deg)\" : \"rotateX(0deg)\",\n            transition: `transform 520ms ${ease}`,\n            [\"--tw-ring-color\" as string]: light ? \"#141414\" : \"#f4f4f2\",\n            [\"--tw-ring-offset-color\" as string]: light ? \"#f1f1ef\" : \"#0a0a0a\",\n          }}\n        >\n          <span aria-hidden=\"true\" className=\"absolute top-4 left-4 h-[3px] w-10 rounded-full bg-black/15\" />\n          <span aria-hidden=\"true\" className=\"absolute right-4 bottom-4 rounded-full bg-black/12 px-2 py-0.5 font-mono text-[10px] font-semibold text-black/55\">\n            {String(n).padStart(2, \"0\")}\n          </span>\n        </button>\n      </div>\n\n      <div className=\"mt-4 px-1\">\n        <p className=\"text-[15px] font-medium\" style={{ color: light ? \"#141414\" : \"#f4f4f2\" }}>\n          {label}\n        </p>\n        <p className=\"mt-0.5 font-mono text-[10.5px]\" style={{ color: light ? \"#6b6b6b\" : \"#8f8f8f\" }}>\n          {caption ?? `${n} document${n === 1 ? \"\" : \"s\"}`}\n        </p>\n      </div>\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}