{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "file",
  "type": "registry:component",
  "title": "File",
  "description": "File message part chip with mime icon, size, and download.",
  "files": [
    {
      "path": "registry/tonic/file/file.tsx",
      "content": "\"use client\"\n\nimport type { FC } from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport {\n  BracesIcon,\n  DownloadIcon,\n  FileIcon,\n  FileTextIcon,\n  ImageIcon,\n  MusicIcon,\n  VideoIcon,\n} from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\nconst fileVariants = cva(\n  \"inline-flex items-center gap-3 rounded-lg transition-colors\",\n  {\n    variants: {\n      variant: {\n        outline: \"border-border hover:bg-muted/50 border\",\n        ghost: \"hover:bg-muted/50\",\n        muted: \"bg-muted/50 hover:bg-muted/70\",\n      },\n      size: {\n        sm: \"px-2.5 py-1.5 text-xs\",\n        default: \"px-3 py-2 text-sm\",\n        lg: \"px-4 py-3 text-base\",\n      },\n    },\n    defaultVariants: {\n      variant: \"outline\",\n      size: \"default\",\n    },\n  }\n)\n\nfunction getMimeTypeIcon(mimeType: string): FC<{ className?: string }> {\n  const type = mimeType.toLowerCase()\n  if (type.startsWith(\"image/\")) return ImageIcon\n  if (type === \"application/pdf\") return FileTextIcon\n  if (type === \"application/json\") return BracesIcon\n  if (type.startsWith(\"text/\")) return FileTextIcon\n  if (type.startsWith(\"audio/\")) return MusicIcon\n  if (type.startsWith(\"video/\")) return VideoIcon\n  return FileIcon\n}\n\nexport function formatFileSize(bytes: number): string {\n  if (bytes < 1024) return `${bytes} B`\n  if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`\n  return `${(bytes / (1024 * 1024)).toFixed(1)} MB`\n}\n\nexport type FileRootProps = React.ComponentProps<\"div\"> &\n  VariantProps<typeof fileVariants>\n\nfunction FileRoot({\n  className,\n  variant,\n  size,\n  children,\n  ...props\n}: FileRootProps) {\n  return (\n    <div\n      data-slot=\"file-root\"\n      className={cn(fileVariants({ variant, size, className }))}\n      {...props}\n    >\n      {children}\n    </div>\n  )\n}\n\nfunction FileIconDisplay({\n  mimeType,\n  className,\n  children,\n  ...props\n}: React.ComponentProps<\"span\"> & { mimeType?: string }) {\n  const IconComponent = mimeType ? getMimeTypeIcon(mimeType) : FileIcon\n  return (\n    <span\n      data-slot=\"file-icon\"\n      className={cn(\"text-muted-foreground shrink-0\", className)}\n      {...props}\n    >\n      {children ?? <IconComponent className=\"size-5\" />}\n    </span>\n  )\n}\n\nfunction FileName({\n  className,\n  children,\n  ...props\n}: React.ComponentProps<\"span\">) {\n  return (\n    <span\n      data-slot=\"file-name\"\n      className={cn(\"min-w-0 flex-1 truncate font-medium\", className)}\n      {...props}\n    >\n      {children}\n    </span>\n  )\n}\n\nfunction FileSize({\n  bytes,\n  className,\n  ...props\n}: React.ComponentProps<\"span\"> & { bytes?: number }) {\n  if (bytes === undefined) return null\n  return (\n    <span\n      data-slot=\"file-size\"\n      className={cn(\"text-muted-foreground shrink-0 tabular-nums\", className)}\n      {...props}\n    >\n      {formatFileSize(bytes)}\n    </span>\n  )\n}\n\nfunction FileDownload({\n  href,\n  filename,\n  className,\n  ...props\n}: React.ComponentProps<\"a\"> & { filename?: string }) {\n  if (!href) return null\n  return (\n    <a\n      data-slot=\"file-download\"\n      href={href}\n      download={filename}\n      className={cn(\n        \"text-muted-foreground hover:text-foreground shrink-0\",\n        className\n      )}\n      aria-label={filename ? `Download ${filename}` : \"Download file\"}\n      {...props}\n    >\n      <DownloadIcon className=\"size-4\" />\n    </a>\n  )\n}\n\nexport function FilePart({\n  name,\n  mimeType,\n  bytes,\n  href,\n  variant,\n  size,\n  className,\n}: {\n  name: string\n  mimeType?: string\n  bytes?: number\n  href?: string\n  variant?: FileRootProps[\"variant\"]\n  size?: FileRootProps[\"size\"]\n  className?: string\n}) {\n  return (\n    <FileRoot variant={variant} size={size} className={className}>\n      <FileIconDisplay mimeType={mimeType} />\n      <div className=\"flex min-w-0 flex-1 flex-col\">\n        <FileName>{name}</FileName>\n        <FileSize bytes={bytes} className=\"text-xs\" />\n      </div>\n      <FileDownload href={href} filename={name} />\n    </FileRoot>\n  )\n}\n\nexport {\n  FileRoot,\n  FileIconDisplay as FileIcon,\n  FileName,\n  FileSize,\n  FileDownload,\n  fileVariants,\n}\n",
      "type": "registry:component"
    }
  ]
}