{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "file-upload-11",
  "title": "File table uploader",
  "description": "Uploaded files in a table with their type, size and actions.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/table.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-file-upload.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/file-upload/file-upload-11.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\n\nimport {\n  type FileMetadata,\n  type FileWithPreview,\n  formatBytes,\n  useFileUpload,\n} from '@/registry/ndeko/hooks/use-file-upload';\nimport {\n  CircleAlertIcon,\n  DownloadIcon,\n  FileArchiveIcon,\n  FileIcon,\n  FileSpreadsheetIcon,\n  FileTextIcon,\n  HeadphonesIcon,\n  ImageIcon,\n  Trash2Icon,\n  UploadCloudIcon,\n  UploadIcon,\n  VideoIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  Table,\n  TableBody,\n  TableCell,\n  TableHead,\n  TableHeader,\n  TableRow,\n} from '@/registry/ndeko/ui/table';\n\nconst MAX_SIZE = 10 * 1024 * 1024;\nconst MAX_FILES = 10;\n\nconst INITIAL_FILES: FileMetadata[] = [\n  {\n    name: 'brand-guidelines.pdf',\n    size: 528737,\n    type: 'application/pdf',\n    url: '',\n    id: 'brand-guidelines',\n  },\n  {\n    name: 'q3-roadmap.zip',\n    size: 252873,\n    type: 'application/zip',\n    url: '',\n    id: 'q3-roadmap',\n  },\n  {\n    name: 'budget-2027.xlsx',\n    size: 352873,\n    type: 'application/xlsx',\n    url: '',\n    id: 'budget-2027',\n  },\n];\n\nconst DOCUMENT_EXTENSIONS = ['.pdf', '.doc', '.docx'];\nconst ARCHIVE_EXTENSIONS = ['.zip', '.rar'];\nconst SPREADSHEET_EXTENSIONS = ['.xls', '.xlsx'];\nconst FILE_ICON_CLASS = 'text-muted-foreground size-4';\n\nconst DROP_ZONE = [\n  'flex min-h-56 flex-col items-center justify-center rounded-xl p-4 data-files:hidden',\n  'group hairline-border border-dashed border-foreground/20',\n  'transition-[background-color,border-color,scale] duration-200 ease-(--ease-out-strong)',\n  'data-dragging:scale-[1.01] motion-reduce:data-dragging:scale-100',\n  'data-dragging:border-primary/50 data-dragging:bg-primary/[0.04]',\n  'has-[input:focus-visible]:ring-[3px] has-[input:focus-visible]:ring-ring/25',\n].join(' ');\n\nconst ICON_TILE =\n  'keycap-3d text-muted-foreground mb-3 flex size-10 items-center justify-center rounded-full transition-transform duration-200 ease-(--ease-out-strong) group-data-dragging:-translate-y-0.5 motion-reduce:group-data-dragging:translate-y-0';\n\nconst COUNT =\n  'keycap-3d inline-flex h-5 min-w-5 items-center justify-center rounded-[5px] px-1 text-[11px] font-medium tabular-nums text-muted-foreground';\n\nconst ROW_ACTION = 'text-muted-foreground hover:text-foreground';\n\nconst ENTER_TRANSITION: Transition = {\n  duration: 0.2,\n  ease: [0.23, 1, 0.32, 1],\n};\nconst EXIT_TRANSITION: Transition = {\n  duration: 0.15,\n  ease: [0.23, 1, 0.32, 1],\n};\n\nconst ROW_VARIANTS: Variants = {\n  hidden: { opacity: 0, transition: EXIT_TRANSITION },\n  shown: { opacity: 1, transition: ENTER_TRANSITION },\n};\n\nconst MotionTableRow = motion.create(TableRow);\n\nfunction presenceOf(isPresent: boolean) {\n  if (isPresent) {\n    return true;\n  }\n  return undefined;\n}\n\nfunction hasExtension(name: string, extensions: string[]) {\n  return extensions.some((extension) => name.endsWith(extension));\n}\n\nfunction isDocument(type: string, name: string) {\n  const isDocumentType = type.includes('pdf') || type.includes('word');\n  const hasDocumentExtension = hasExtension(name, DOCUMENT_EXTENSIONS);\n  return isDocumentType || hasDocumentExtension;\n}\n\nfunction isArchive(type: string, name: string) {\n  const isArchiveType = type.includes('zip') || type.includes('archive');\n  const hasArchiveExtension = hasExtension(name, ARCHIVE_EXTENSIONS);\n  return isArchiveType || hasArchiveExtension;\n}\n\nfunction isSpreadsheet(type: string, name: string) {\n  const isSpreadsheetType = type.includes('excel') || type.includes('xlsx');\n  const hasSpreadsheetExtension = hasExtension(name, SPREADSHEET_EXTENSIONS);\n  return isSpreadsheetType || hasSpreadsheetExtension;\n}\n\nfunction fileIconOf(file: File | FileMetadata) {\n  const type = file.type;\n  const name = file.name.toLowerCase();\n  if (isDocument(type, name)) {\n    return <FileTextIcon className={FILE_ICON_CLASS} />;\n  }\n  if (isArchive(type, name)) {\n    return <FileArchiveIcon className={FILE_ICON_CLASS} />;\n  }\n  if (isSpreadsheet(type, name)) {\n    return <FileSpreadsheetIcon className={FILE_ICON_CLASS} />;\n  }\n  if (type.startsWith('video/')) {\n    return <VideoIcon className={FILE_ICON_CLASS} />;\n  }\n  if (type.startsWith('audio/')) {\n    return <HeadphonesIcon className={FILE_ICON_CLASS} />;\n  }\n  if (type.startsWith('image/')) {\n    return <ImageIcon className={FILE_ICON_CLASS} />;\n  }\n  return <FileIcon className={FILE_ICON_CLASS} />;\n}\n\nfunction typeLabelOf(name: string) {\n  const parts = name.split('.');\n  const hasExtensionPart = parts.length > 1;\n  if (!hasExtensionPart) {\n    return 'Unknown';\n  }\n  const extension = parts[parts.length - 1];\n  return extension.toUpperCase();\n}\n\nfunction localUrlOf(file: FileWithPreview) {\n  const isLocalFile = file.file instanceof File;\n  if (!isLocalFile) {\n    return null;\n  }\n  return file.preview ?? null;\n}\n\nfunction DownloadAction({ file }: { file: FileWithPreview }) {\n  const url = localUrlOf(file);\n  if (!url) {\n    return null;\n  }\n  return (\n    <Button\n      size='icon'\n      variant='ghost'\n      className={ROW_ACTION}\n      aria-label={`Download ${file.file.name}`}\n      nativeButton={false}\n      render={<a href={url} download={file.file.name} />}\n    >\n      <DownloadIcon />\n    </Button>\n  );\n}\n\nexport default function FileUpload11() {\n  const [\n    { files, isDragging, errors },\n    {\n      handleDragEnter,\n      handleDragLeave,\n      handleDragOver,\n      handleDrop,\n      openFileDialog,\n      removeFile,\n      clearFiles,\n      getInputProps,\n    },\n  ] = useFileUpload({\n    multiple: true,\n    maxFiles: MAX_FILES,\n    maxSize: MAX_SIZE,\n    initialFiles: INITIAL_FILES,\n  });\n\n  const hasFiles = files.length > 0;\n  const firstError = errors[0];\n\n  return (\n    <div className='flex w-full flex-col gap-2'>\n      <div\n        onDragEnter={handleDragEnter}\n        onDragLeave={handleDragLeave}\n        onDragOver={handleDragOver}\n        onDrop={handleDrop}\n        data-dragging={presenceOf(isDragging)}\n        data-files={presenceOf(hasFiles)}\n        className={DROP_ZONE}\n      >\n        <input\n          {...getInputProps()}\n          className='sr-only'\n          aria-label='Upload files'\n        />\n        <div className='flex flex-col items-center justify-center text-center'>\n          <div className={ICON_TILE} aria-hidden='true'>\n            <FileIcon className='size-4' />\n          </div>\n          <p className='mb-1 text-[13px] font-medium'>Upload files</p>\n          <p className='text-muted-foreground text-xs tabular-nums'>\n            Max {MAX_FILES} files · Up to {formatBytes(MAX_SIZE)}\n          </p>\n          <Button variant='outline' className='mt-4' onClick={openFileDialog}>\n            <UploadIcon className='-ms-1 opacity-60' />\n            Select files\n          </Button>\n        </div>\n      </div>\n      {hasFiles && (\n        <>\n          <div className='flex items-center justify-between gap-2'>\n            <h3 className='flex items-center gap-2 text-[13px] font-medium'>\n              Files\n              <span className={COUNT}>{files.length}</span>\n            </h3>\n            <div className='flex gap-2'>\n              <Button variant='outline' size='sm' onClick={openFileDialog}>\n                <UploadCloudIcon className='-ms-0.5 size-3.5 opacity-60' />\n                Add files\n              </Button>\n              <Button variant='outline' size='sm' onClick={clearFiles}>\n                <Trash2Icon className='-ms-0.5 size-3.5 opacity-60' />\n                Remove all\n              </Button>\n            </div>\n          </div>\n          <div className='bg-card hairline-ring ring-border overflow-hidden rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)]'>\n            <Table>\n              <TableHeader>\n                <TableRow className='hover:bg-transparent'>\n                  <TableHead className='h-9'>Name</TableHead>\n                  <TableHead className='h-9'>Type</TableHead>\n                  <TableHead className='h-9 text-right'>Size</TableHead>\n                  <TableHead className='h-9 w-0 text-right'>\n                    <span className='sr-only'>Actions</span>\n                  </TableHead>\n                </TableRow>\n              </TableHeader>\n              <TableBody>\n                <AnimatePresence initial={false}>\n                  {files.map((file) => (\n                    <MotionTableRow\n                      key={file.id}\n                      variants={ROW_VARIANTS}\n                      initial='hidden'\n                      animate='shown'\n                      exit='hidden'\n                    >\n                      <TableCell className='max-w-48 py-2 font-medium'>\n                        <span className='flex items-center gap-2'>\n                          <span className='shrink-0' aria-hidden='true'>\n                            {fileIconOf(file.file)}\n                          </span>\n                          <span className='truncate'>{file.file.name}</span>\n                        </span>\n                      </TableCell>\n                      <TableCell className='text-muted-foreground py-2'>\n                        {typeLabelOf(file.file.name)}\n                      </TableCell>\n                      <TableCell className='text-muted-foreground py-2 text-right tabular-nums'>\n                        {formatBytes(file.file.size)}\n                      </TableCell>\n                      <TableCell className='py-2 text-right whitespace-nowrap'>\n                        <DownloadAction file={file} />\n                        <Button\n                          size='icon'\n                          variant='ghost'\n                          className={ROW_ACTION}\n                          aria-label={`Remove ${file.file.name}`}\n                          onClick={() => removeFile(file.id)}\n                        >\n                          <Trash2Icon />\n                        </Button>\n                      </TableCell>\n                    </MotionTableRow>\n                  ))}\n                </AnimatePresence>\n              </TableBody>\n            </Table>\n          </div>\n        </>\n      )}\n      {firstError && (\n        <p\n          role='alert'\n          className='text-destructive-ink flex items-center gap-1.5 text-xs'\n        >\n          <CircleAlertIcon className='size-3.5 shrink-0' />\n          <span>{firstError}</span>\n        </p>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "file-upload"
  ],
  "type": "registry:component"
}