{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "file-browser",
  "type": "registry:component",
  "title": "File browser",
  "description": "A compact file collection with selection, metadata, previews and real download links.",
  "categories": [
    "tables-&-lists"
  ],
  "dependencies": [
    "@tabler/icons-react"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "src/registry/overtrue/file-browser.tsx",
      "type": "registry:component",
      "target": "components/overtrue/file-browser.tsx",
      "content": "\"use client\";\n\nimport { useId, type ReactNode } from \"react\";\nimport {\n  IconFile,\n  IconFolder,\n  IconPhoto,\n  IconDownload,\n} from \"@tabler/icons-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface BrowserFile {\n  id: string;\n  name: string;\n  kind?: \"file\" | \"folder\" | \"image\";\n  size?: string;\n  updated?: string;\n  owner?: string;\n  downloadUrl?: string;\n  preview?: string;\n  metadata?: ReactNode;\n}\n\n/** Presentational file records. Applications own selection, permissions and downloads. */\nexport function FileBrowser({\n  files,\n  selectedIds,\n  onSelectionChange,\n  onOpen,\n  empty = \"No files in this collection.\",\n  className,\n}: {\n  files: readonly BrowserFile[];\n  selectedIds?: readonly string[];\n  onSelectionChange?: (ids: string[]) => void;\n  onOpen?: (file: BrowserFile) => void;\n  empty?: string;\n  className?: string;\n}) {\n  const id = useId();\n  const selection = new Set(selectedIds ?? []);\n  const selectable = Boolean(onSelectionChange);\n  const selectedVisible = files.filter((file) => selection.has(file.id)).length;\n  const toggle = (ids: string[], checked: boolean) => {\n    const next = new Set(selection);\n    ids.forEach((id) => (checked ? next.add(id) : next.delete(id)));\n    onSelectionChange?.([...next]);\n  };\n  return (\n    <div\n      data-slot=\"file-browser\"\n      className={cn(\n        \"@container min-w-0 overflow-hidden rounded-xl border border-border bg-card text-card-foreground\",\n        className,\n      )}\n    >\n      <div className=\"flex items-center gap-3 border-b border-border bg-muted/35 px-4 py-3 text-xs text-muted-foreground\">\n        {selectable && (\n          <input\n            type=\"checkbox\"\n            aria-label=\"Select all files\"\n            checked={files.length > 0 && selectedVisible === files.length}\n            ref={(node) => {\n              if (node)\n                node.indeterminate =\n                  selectedVisible > 0 && selectedVisible < files.length;\n            }}\n            disabled={!files.length}\n            onChange={(event) =>\n              toggle(\n                files.map((file) => file.id),\n                event.target.checked,\n              )\n            }\n            className=\"size-4 shrink-0 accent-primary\"\n          />\n        )}\n        <span className=\"flex-1\">\n          {selectedVisible ? `${selectedVisible} selected` : \"Name\"}\n        </span>\n        <span className=\"hidden w-32 @xl:block\">Last updated</span>\n        <span className=\"hidden w-20 text-right @xl:block\">Size</span>\n        <span className=\"w-7\" aria-hidden=\"true\" />\n      </div>\n      <ul\n        aria-label=\"Files\"\n        className=\"m-0 list-none divide-y divide-border p-0\"\n      >\n        {files.map((file, index) => {\n          const Icon =\n            file.kind === \"folder\"\n              ? IconFolder\n              : file.kind === \"image\"\n                ? IconPhoto\n                : IconFile;\n          return (\n            <li\n              key={file.id}\n              data-slot=\"file-browser-item\"\n              data-selected={selection.has(file.id)}\n              className=\"flex items-center gap-3 px-4 py-3.5 transition-colors hover:bg-muted/30 data-[selected=true]:bg-primary/5\"\n            >\n              {selectable && (\n                <input\n                  id={`${id}-${index}`}\n                  type=\"checkbox\"\n                  aria-label={`Select ${file.name}`}\n                  checked={selection.has(file.id)}\n                  onChange={(event) => toggle([file.id], event.target.checked)}\n                  className=\"size-4 shrink-0 accent-primary\"\n                />\n              )}\n              <span className=\"flex size-9 shrink-0 items-center justify-center overflow-hidden rounded-lg border border-border bg-muted/50 text-muted-foreground\">\n                {file.preview ? (\n                  <img\n                    src={file.preview}\n                    alt=\"\"\n                    className=\"size-full object-cover\"\n                  />\n                ) : (\n                  <Icon size={19} stroke={1.5} aria-hidden=\"true\" />\n                )}\n              </span>\n              <div className=\"min-w-0 flex-1\">\n                {onOpen ? (\n                  <button\n                    type=\"button\"\n                    onClick={() => onOpen(file)}\n                    className=\"block max-w-full rounded-sm text-left text-sm font-medium [overflow-wrap:anywhere] hover:text-primary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring\"\n                  >\n                    {file.name}\n                  </button>\n                ) : (\n                  <p className=\"m-0 text-sm font-medium [overflow-wrap:anywhere]\">\n                    {file.name}\n                  </p>\n                )}\n                <p className=\"m-0 mt-1 flex flex-wrap gap-x-2 text-xs text-muted-foreground\">\n                  {file.owner && <span>{file.owner}</span>}\n                  <span className=\"@xl:hidden\">\n                    {[file.size, file.updated].filter(Boolean).join(\" · \")}\n                  </span>\n                  {file.metadata}\n                </p>\n              </div>\n              <span className=\"hidden w-32 shrink-0 text-xs text-muted-foreground @xl:block\">\n                {file.updated ?? \"—\"}\n              </span>\n              <span className=\"hidden w-20 shrink-0 text-right text-xs tabular-nums text-muted-foreground @xl:block\">\n                {file.size ?? \"—\"}\n              </span>\n              {file.downloadUrl ? (\n                <a\n                  href={file.downloadUrl}\n                  download={file.name}\n                  aria-label={`Download ${file.name}`}\n                  className=\"flex size-7 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring\"\n                >\n                  <IconDownload size={16} aria-hidden=\"true\" />\n                </a>\n              ) : (\n                <span className=\"w-7 shrink-0\" />\n              )}\n            </li>\n          );\n        })}\n      </ul>\n      {!files.length && (\n        <p className=\"m-0 px-5 py-10 text-center text-sm text-muted-foreground\">\n          {empty}\n        </p>\n      )}\n    </div>\n  );\n}\n"
    }
  ],
  "docs": "Documentation: https://ui.overtrue.xyz/components/file-browser. Requires an initialized shadcn/ui project with Tailwind CSS v4."
}
