{
  "name": "file-upload",
  "type": "registry:ui",
  "framework": "react",
  "title": "File Upload",
  "description": "A drop zone that also opens a file picker from the keyboard.",
  "files": [
    {
      "path": "ui/file-upload.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/*\n * The drop zone a modal asks for a file with. Two ways in, because a drop is\n * not available to everyone: dragging files onto it, and a `browse` control\n * that opens the same picker from the keyboard.\n *\n * The file input stays in the DOM rather than being replaced by a button —\n * it is the accessible name, the keyboard path and the picker all at once.\n */\nexport interface FileUploadProps extends Omit<\n  React.HTMLAttributes<HTMLDivElement>,\n  \"onDrop\" | \"onChange\"\n> {\n  /** Accepted types, passed straight to the input. */\n  accept?: string\n  /** Whether more than one file can be chosen at a time. */\n  multiple?: boolean\n  disabled?: boolean\n  /** The line under the prompt: how many, how large. */\n  hint?: React.ReactNode\n  /** The text before the browse control. */\n  prompt?: string\n  /** The browse control, which opens the file picker. */\n  browseLabel?: string\n  /** Called with whatever was dropped or picked. */\n  onFiles?: (files: readonly File[]) => void\n}\n\nconst FileUpload = React.forwardRef<HTMLDivElement, FileUploadProps>(\n  (\n    {\n      className,\n      accept,\n      multiple = false,\n      disabled = false,\n      hint,\n      prompt = \"Drop files here or\",\n      browseLabel = \"browse\",\n      onFiles,\n      ...props\n    },\n    ref\n  ) => {\n    const inputRef = React.useRef<HTMLInputElement>(null)\n    const [dragging, setDragging] = React.useState(false)\n\n    function accept_(list: FileList | null) {\n      if (list === null || list.length === 0) return\n      onFiles?.(Array.from(list))\n    }\n\n    return (\n      <div\n        ref={ref}\n        data-dragging={dragging || undefined}\n        data-disabled={disabled || undefined}\n        onDragOver={(event) => {\n          if (disabled) return\n          event.preventDefault()\n          setDragging(true)\n        }}\n        onDragLeave={() => setDragging(false)}\n        onDrop={(event) => {\n          if (disabled) return\n          event.preventDefault()\n          setDragging(false)\n          accept_(event.dataTransfer.files)\n        }}\n        className={cn(\n          \"flex flex-col items-center justify-center gap-1 rounded-[var(--newt-radius-md)] border border-dashed border-newt-border bg-newt-bg-base px-4 py-6 text-center\",\n          \"transition-colors duration-fast ease-newt\",\n          \"data-[dragging]:border-newt-brand data-[dragging]:bg-newt-bg-surface\",\n          \"focus-within:border-newt-brand\",\n          disabled && \"cursor-not-allowed opacity-50\",\n          className\n        )}\n        {...props}\n      >\n        <svg\n          viewBox=\"0 0 24 24\"\n          aria-hidden=\"true\"\n          className=\"h-6 w-6 text-newt-text-muted\"\n        >\n          <path\n            fill=\"currentColor\"\n            d=\"M12 3a1 1 0 0 1 .7.3l4 4a1 1 0 1 1-1.4 1.4L13 6.42V15a1 1 0 1 1-2 0V6.41L8.71 8.71a1 1 0 0 1-1.42-1.42l4-4A1 1 0 0 1 12 3ZM5 15a1 1 0 0 1 1 1v2a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1v-2a1 1 0 1 1 2 0v2a3 3 0 0 1-3 3H7a3 3 0 0 1-3-3v-2a1 1 0 0 1 1-1Z\"\n          />\n        </svg>\n\n        <p className=\"text-sm text-newt-text-secondary\">\n          {prompt}{\" \"}\n          {/*\n           * The label is the control: clicking the word opens the picker, and\n           * the input keeps the focus ring and the keyboard behaviour it was\n           * born with.\n           */}\n          <label className=\"cursor-pointer text-newt-text-link underline-offset-2 hover:underline\">\n            {browseLabel}\n            <input\n              ref={inputRef}\n              type=\"file\"\n              accept={accept}\n              multiple={multiple}\n              disabled={disabled}\n              className=\"sr-only\"\n              onChange={(event) => accept_(event.target.files)}\n            />\n          </label>\n        </p>\n\n        {hint === undefined ? null : (\n          <p className=\"text-xs text-newt-text-muted\">{hint}</p>\n        )}\n      </div>\n    )\n  }\n)\nFileUpload.displayName = \"FileUpload\"\n\nexport { FileUpload }\n",
      "type": "registry:ui"
    }
  ]
}