{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "files-03",
  "description": "Storage used against the plan, split by kind of file, with the largest files and the space deleting them would free.",
  "registryDependencies": [
    "card",
    "button",
    "https://www.dashboardblocks.com/r/radix/block-state.json",
    "https://www.dashboardblocks.com/r/radix/files.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/progress-bar.json",
    "https://www.dashboardblocks.com/r/radix/usage-meter.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/files/files-03.tsx",
      "content": "'use client'\n\nimport {\n  BlockReady,\n  BlockStateProvider,\n  BlockStateRows,\n  type BlockStateProps,\n  getBlockState,\n} from '@/registry/components/dashboardblocks/block-state'\nimport {\n  type FileAction,\n  FileActionsMenu,\n  FileKindIcon,\n  type FileKind,\n  fileKindConfig,\n  formatFileSize,\n} from '@/registry/components/dashboardblocks/files'\nimport { SegmentedProgressBar } from '@/registry/components/dashboardblocks/progress-bar'\nimport {\n  UsageMeterLimit,\n  UsageMeterValue,\n  UsageStatusLabel,\n  getUsageStatus,\n} from '@/registry/components/dashboardblocks/usage-meter'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatPercent } from '@/registry/lib/dashboardblocks/format'\nimport { startTransition, useId, useMemo, useRef, useState } from 'react'\n\nimport { buttonVariants } from '@/components/ui/button'\nimport { Card, CardContent } from '@/components/ui/card'\n\nimport { cn } from '@/lib/utils'\n\ninterface StorageFile {\n  href: string\n  id: string\n  kind: FileKind\n  location: string\n  name: string\n  /** In bytes. */\n  size: number\n}\n\ninterface StorageKind {\n  kind: FileKind\n  /** Defaults to the kind's label. */\n  label?: string\n  /** In bytes, including `largestFiles` of this kind. */\n  size: number\n}\n\ninterface Files3Props extends BlockStateProps {\n  /** Storage used by kind, largest first. Leave out, or pass none, to show the empty state. */\n  breakdown?: StorageKind[]\n  /** The biggest files, largest first, to free up space. */\n  largestFiles?: StorageFile[]\n  /** In bytes. */\n  limit: number\n  onDelete?: (file: StorageFile) => Promise<void>\n  plan: string\n  title: string\n  upgradeHint: string\n  upgradeHref: string\n}\n\nconst GB = 1024 ** 3\nconst MB = 1024 ** 2\n\nconst exampleProps: Files3Props = {\n  breakdown: [\n    { kind: 'video', label: 'Videos', size: 38.2 * GB },\n    { kind: 'image', label: 'Images', size: 21.7 * GB },\n    { kind: 'document', label: 'Documents', size: 11.4 * GB },\n    { kind: 'archive', label: 'Archives', size: 7.9 * GB },\n    { kind: 'other', label: 'Other', size: 3.4 * GB },\n  ],\n  largestFiles: [\n    {\n      href: '#',\n      id: 'keynote-recording',\n      kind: 'video',\n      location: 'Events / Summit 2026',\n      name: 'Summit keynote full recording.mov',\n      size: 6.2 * GB,\n    },\n    {\n      href: '#',\n      id: 'photo-archive',\n      kind: 'archive',\n      location: 'Brand / Photography',\n      name: 'Product shoot RAW archive.zip',\n      size: 3.8 * GB,\n    },\n    {\n      href: '#',\n      id: 'teaser-master',\n      kind: 'video',\n      location: 'Campaigns / Fall launch',\n      name: 'Launch teaser 4K master.mp4',\n      size: 2.1 * GB,\n    },\n    {\n      href: '#',\n      id: 'print-catalog',\n      kind: 'pdf',\n      location: 'Sales / Print',\n      name: 'Spring catalog print-ready.pdf',\n      size: 846 * MB,\n    },\n  ],\n  limit: 100 * GB,\n  plan: 'Team plan',\n  title: 'Storage',\n  upgradeHint: 'Need more room? Business has 1 TB per workspace.',\n  upgradeHref: '#',\n}\n\nasync function deleteFile() {\n  await new Promise((resolve) => setTimeout(resolve, 400))\n}\n\nconst noKinds: StorageKind[] = []\nconst noFiles: StorageFile[] = []\n\nconst KIND_COLORS = [\n  'var(--color-chart-2)',\n  'var(--color-chart-3)',\n  'var(--color-chart-4)',\n  'var(--color-chart-5)',\n  'var(--color-chart-1)',\n]\n\nfunction getKindColors(breakdown: StorageKind[]) {\n  let next = 0\n  return breakdown.map((item) =>\n    item.kind === 'other'\n      ? 'var(--color-muted-foreground)'\n      : KIND_COLORS[next++ % KIND_COLORS.length],\n  )\n}\n\nfunction breakdownKind(kind: FileKind, shown: FileKind[]): FileKind {\n  if (shown.includes(kind)) return kind\n  const family: Partial<Record<FileKind, FileKind>> = {\n    pdf: 'document',\n    presentation: 'document',\n    spreadsheet: 'document',\n  }\n  const parent = family[kind]\n  return parent && shown.includes(parent) ? parent : 'other'\n}\n\nconst Files3 = (props: Files3Props) => {\n  const {\n    breakdown: storedBreakdown = noKinds,\n    largestFiles = noFiles,\n    limit,\n    onDelete = deleteFile,\n    plan,\n    errorMessage,\n    status,\n    title,\n    upgradeHint,\n    upgradeHref,\n  } = props\n  const headingId = useId()\n  const [deleted, setDeleted] = useState<ReadonlySet<string>>(() => new Set())\n  const [message, setMessage] = useState('')\n  const deleting = useRef(new Set<string>())\n  const state = getBlockState(status, storedBreakdown)\n\n  const files = useMemo(\n    () => largestFiles.filter((file) => !deleted.has(file.id)),\n    [deleted, largestFiles],\n  )\n  const breakdown = useMemo(() => {\n    const kinds = storedBreakdown.map((item) => item.kind)\n    const freed = new Map<FileKind, number>()\n    for (const file of largestFiles) {\n      if (!deleted.has(file.id)) continue\n      const kind = breakdownKind(file.kind, kinds)\n      freed.set(kind, (freed.get(kind) ?? 0) + file.size)\n    }\n    return storedBreakdown.map((item) => ({\n      ...item,\n      size: Math.max(0, item.size - (freed.get(item.kind) ?? 0)),\n    }))\n  }, [deleted, largestFiles, storedBreakdown])\n\n  const used = breakdown.reduce((sum, item) => sum + item.size, 0)\n  const free = Math.max(0, limit - used)\n  const kindColors = getKindColors(breakdown)\n  const usage = getUsageStatus(used, limit)\n  const largest = breakdown.reduce<StorageKind | undefined>(\n    (top, item) => (top && top.size >= item.size ? top : item),\n    undefined,\n  )\n  const labelOf = (item: StorageKind) => item.label ?? fileKindConfig[item.kind].label\n  const reclaimable = files.reduce((sum, file) => sum + file.size, 0)\n\n  async function remove(file: StorageFile) {\n    if (deleting.current.has(file.id)) return\n    deleting.current.add(file.id)\n    setMessage(`Deleting ${file.name}…`)\n    try {\n      await onDelete(file)\n    } finally {\n      deleting.current.delete(file.id)\n    }\n    startTransition(() => {\n      setDeleted((current) => new Set([...current, file.id]))\n      setMessage(`Deleted ${file.name}, freeing ${formatFileSize(file.size)}`)\n    })\n  }\n\n  const actionsFor = (file: StorageFile): FileAction[] => [\n    {\n      icon: (\n        <IconPlaceholder\n          lucide='DownloadIcon'\n          tabler='IconDownload'\n          hugeicons='Download01Icon'\n          phosphor='DownloadIcon'\n          remixicon='RiDownloadLine'\n        />\n      ),\n      label: 'Download',\n      onSelect: () => setMessage(`Downloading ${file.name}`),\n    },\n    {\n      icon: (\n        <IconPlaceholder\n          lucide='Trash2Icon'\n          tabler='IconTrash'\n          hugeicons='Delete02Icon'\n          phosphor='TrashIcon'\n          remixicon='RiDeleteBinLine'\n        />\n      ),\n      label: 'Delete',\n      onSelect: () => void remove(file),\n      variant: 'destructive',\n    },\n  ]\n\n  return (\n    <BlockStateProvider errorMessage={errorMessage} state={state}>\n      <Card>\n        <CardContent>\n          <section className='@container flex flex-col gap-4'>\n            <header className='flex items-start justify-between gap-3'>\n              <div className='flex min-w-0 flex-col gap-0.5'>\n                <h2 className='font-semibold tracking-tight'>{title}</h2>\n                <BlockReady className='text-sm'>\n                  <p className='text-muted-foreground text-sm'>\n                    {largest ? (\n                      <>\n                        {labelOf(largest)} use the most space, and{' '}\n                        <span className='tabular-nums'>{formatFileSize(free)}</span> of\n                        the {plan} is free.\n                      </>\n                    ) : (\n                      `Nothing stored on the ${plan} yet.`\n                    )}\n                  </p>\n                </BlockReady>\n              </div>\n              <UsageStatusLabel className='mt-0.5' status={usage} />\n            </header>\n            <div className='flex flex-col gap-3 border-t pt-4'>\n              <div className='flex flex-wrap items-baseline gap-x-2'>\n                <UsageMeterValue>{formatFileSize(used)}</UsageMeterValue>\n                <UsageMeterLimit>of {formatFileSize(limit)}</UsageMeterLimit>\n              </div>\n              <div aria-hidden>\n                <SegmentedProgressBar\n                  className='h-2.5 gap-0.5'\n                  segments={breakdown.map((item, index) => ({\n                    color: kindColors[index],\n                    label: item.kind,\n                    value: item.size,\n                  }))}\n                  total={Math.max(limit, used)}\n                />\n              </div>\n              {state === 'loading' && <BlockStateRows rows={4} />}\n              {!state && (\n                <ul className='grid gap-x-6 text-sm @sm:grid-cols-2'>\n                  {breakdown.map((item, index) => (\n                    <li\n                      key={item.kind}\n                      className='flex min-w-0 items-center gap-2 border-b py-2'\n                    >\n                      <span\n                        aria-hidden\n                        className='size-2.5 shrink-0 rounded-[3px]'\n                        style={{ backgroundColor: kindColors[index] }}\n                      />\n                      <span className='text-muted-foreground truncate'>\n                        {labelOf(item)}\n                      </span>\n                      <span className='ml-auto font-medium tabular-nums'>\n                        {formatFileSize(item.size)}\n                      </span>\n                      <span className='text-muted-foreground w-9 text-right text-xs tabular-nums'>\n                        {formatPercent(limit > 0 ? item.size / limit : 0, {\n                          maximumFractionDigits: 0,\n                        })}\n                      </span>\n                    </li>\n                  ))}\n                </ul>\n              )}\n            </div>\n            {(state === undefined || state === 'loading') && (\n              <section aria-labelledby={headingId} className='flex flex-col gap-1'>\n                <div className='flex flex-col gap-0.5'>\n                  <h3 id={headingId} className='text-sm font-medium'>\n                    Largest files\n                  </h3>\n                  {!state && files.length > 0 && (\n                    <p className='text-muted-foreground text-sm'>\n                      Deleting these{' '}\n                      {files.length === 1 ? 'file' : `${files.length} files`} would free{' '}\n                      <span className='tabular-nums'>{formatFileSize(reclaimable)}</span>.\n                    </p>\n                  )}\n                </div>\n                {state === 'loading' ? (\n                  <BlockStateRows className='mt-1 border-t' rows={4} />\n                ) : files.length > 0 ? (\n                  <ul className='mt-1 flex flex-col border-t'>\n                    {files.map((file) => (\n                      <li\n                        key={file.id}\n                        className='flex items-center gap-3 border-b py-2.5'\n                      >\n                        <FileKindIcon kind={file.kind} size='sm' />\n                        <div className='flex min-w-0 flex-1 flex-col'>\n                          <a\n                            href={file.href}\n                            className='truncate text-sm font-medium underline-offset-4 outline-none hover:underline focus-visible:underline'\n                          >\n                            {file.name}\n                          </a>\n                          <span className='text-muted-foreground truncate text-sm'>\n                            {file.location}\n                          </span>\n                        </div>\n                        <span className='text-sm tabular-nums'>\n                          {formatFileSize(file.size)}\n                        </span>\n                        <FileActionsMenu\n                          actions={actionsFor(file)}\n                          label={`Actions for ${file.name}`}\n                          className='-mr-2'\n                        />\n                      </li>\n                    ))}\n                  </ul>\n                ) : (\n                  <p className='text-muted-foreground border-t py-2.5 text-sm'>\n                    No large files left to review.\n                  </p>\n                )}\n              </section>\n            )}\n            <footer className='flex flex-wrap items-center justify-between gap-3'>\n              <p\n                aria-live='polite'\n                className='text-muted-foreground min-w-48 flex-1 text-sm'\n              >\n                {message || upgradeHint}\n              </p>\n              <a href={upgradeHref} className={cn(buttonVariants({ size: 'sm' }))}>\n                Upgrade storage\n              </a>\n            </footer>\n          </section>\n        </CardContent>\n      </Card>\n    </BlockStateProvider>\n  )\n}\n\nexport {\n  Files3,\n  exampleProps as files3ExampleProps,\n  type Files3Props,\n  type StorageFile,\n  type StorageKind,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/files/files-03.tsx"
    }
  ],
  "meta": {
    "shows": "Storage used against the plan, split by kind of file, with the largest files and the space deleting them would free.",
    "size": "half",
    "usedWith": [
      "files-02",
      "usage-meter-01"
    ],
    "component": "Files3",
    "props": "{ breakdown?: { kind: \"archive\" | \"audio\" | \"code\" | \"document\" | \"folder\" | \"image\" | \"other\" | \"pdf\" | \"presentation\" | \"spreadsheet\" | \"video\"; label?: string; size: number }[]; largestFiles?: { href: string; id: string; kind: \"archive\" | \"audio\" | \"code\" | \"document\" | \"folder\" | \"image\" | \"other\" | \"pdf\" | \"presentation\" | \"spreadsheet\" | \"video\"; location: string; name: string; size: number }[]; limit: number; onDelete?: (file: { href: string; id: string; kind: \"archive\" | \"audio\" | \"code\" | \"document\" | \"folder\" | \"image\" | \"other\" | \"pdf\" | \"presentation\" | \"spreadsheet\" | \"video\"; location: string; name: string; size: number }) => Promise<void>; plan: string; title: string; upgradeHint: string; upgradeHref: string; errorMessage?: string; status?: \"loading\" | \"error\" }"
  },
  "type": "registry:component"
}
