import { type ComponentProps, type ReactElement, type ReactNode, type RefObject } from 'react'; import { type FileRejection, type FileStatus } from '../core/file-uploader.js'; /** * Unstyled Carbon `FileUploader` / `FileUploaderDropContainer` / `FileUploaderItem`, the behaviour without a single * class (core/file-uploader): a `Trigger` that opens the file dialog of a hidden `Input`, a `DropZone` that takes * dragged files (not folders), and the chosen files as `Item`s in a `List`. `accept` / `maxFileSize` / `maxFiles` / * `maxTotalSize` mark refused files invalid (they stay listed with your `describeRejection` text and aren't * submitted); without `multiple` a pick replaces the list. Items start in `status`; update `files` as uploads * progress. In a form, `FormValue` submits every valid file under `name`, and `required` blocks the submit until * there is one (`requiredText` is the validity message; the browser's bubble never shows, the trigger gets focus). * An uncontrolled list empties with its form. * * Removing a file with focus in the list moves focus to the next row's `Remove` button, else the previous one's, * else the trigger. A row's `Retry` that goes with focus (the upload restarts) leaves it on the row's `Remove` * button, else the row itself. An `Item` works on its own too (files already on the server). * * State shows as data attributes to style on: `data-disabled` on `Group`, `DropZone` and `Trigger`; `data-drag-over` * on `DropZone` and `Trigger`; `data-file-item`, `data-removable`, `data-status` and `data-invalid` on `Item`; * `data-file-remove` on `Remove` and `data-file-retry` on `Retry`. * * ```tsx * ({ errorSubject: 'Not a PDF' })}> * * * Add files * * * * {…one Item per file of useFileUploaderContext().files…} * * ``` */ export type { FileStatus } from '../core/file-uploader.js'; /** One file in the list. */ export interface FileItem { uuid: string; name: string; file: File; /** Refused by `accept` / `maxFileSize` / `maxFiles` / `maxTotalSize` (Carbon `invalidFileType`), or a failed upload. */ invalid?: boolean; status?: FileStatus; errorSubject?: string; errorBody?: string; /** Upload progress 0–100 while `status` is uploading. */ progress?: number; /** An invalid row (a failed upload) that can be retried (`onRetry`); refused files aren't retryable. */ retryable?: boolean; } export interface FileChange { addedFiles: FileItem[]; removedFiles: FileItem[]; currentFiles: FileItem[]; action: 'add' | 'remove' | 'clear'; } /** Why a file was refused (core `checkFile`), never null here. */ export type Rejection = NonNullable; export interface RootProps { /** Comma-separated extensions / MIME types, e.g. ".pdf,.jpg,image/png". */ accept?: string; multiple?: boolean; /** Bytes; larger files are added as invalid (0 = no limit). */ maxFileSize?: number; /** Most valid files in the list; the ones past it are added as invalid (0 = no limit). */ maxFiles?: number; /** Bytes the valid files may add up to; a file that would go over is added as invalid (0 = no limit). */ maxTotalSize?: number; /** The error text of a refused file. */ describeRejection?: (rejection: Rejection) => Pick; /** Submitted name of `FormValue`. */ name?: string; disabled?: boolean; /** Status new items start in (Carbon `filenameStatus`). */ status?: FileStatus; /** At least one valid file before the form submits. */ required?: boolean; /** The validity message while `required` and there is no valid file; defaults to the English translation's. */ requiredText?: string; /** The list (controlled); replace it to update statuses or errors. */ files?: FileItem[]; defaultFiles?: FileItem[]; /** Right after the user picked or dropped files (refused ones included). */ onAdd?: (addedFiles: FileItem[]) => void; onChange?: (change: FileChange) => void; onDelete?: (deleted: { deletedFile: FileItem; remainingFiles: FileItem[]; }) => void; /** The user retried a failed upload (a `retryable` invalid file): start it again and update `files`. */ onRetry?: (retriedFile: FileItem) => void; children?: ReactNode; } interface FileUploaderContextValue { files: FileItem[]; /** The names of the files of the last pick or drop ([] after a form reset). */ picked: string[]; disabled: boolean; multiple: boolean; accept: string; name: string | undefined; /** Files are dragged over the drop zone. */ dragOver: boolean; titleId: string; inputId: string; picker: RefObject; submitted: RefObject; trigger: RefObject; list: RefObject; /** Adds picked or dropped files (checked against the limits). */ add: (files: File[]) => void; /** Removes a file (focus moves on if it was in the list). */ remove: (uuid: string) => void; /** Asks for a failed upload to be started again (`onRetry`). */ retry: (uuid: string) => void; /** Opens the file dialog. */ browse: () => void; setDragOver: (over: boolean) => void; } /** The state of the enclosing `FileUploader.Root` (files, picked, dragOver …). */ export declare function useFileUploaderContext(part?: string): FileUploaderContextValue; /** Holds the list, the limits and the focus rules; renders only its children. */ export declare function Root({ accept, multiple, maxFileSize, maxFiles, maxTotalSize, describeRejection, name, disabled, status, required, requiredText, files: filesProp, defaultFiles, onAdd, onChange, onDelete, onRetry, children, }: Readonly): import("react").JSX.Element; /** The group of trigger and files (`role="group"`): name it with `aria-labelledby` (the `Title`'s id) or `aria-label`. */ export declare function Group(props: Readonly, 'role'>>): import("react").JSX.Element; /** The title (its id is the context's `titleId`, for `Group`'s `aria-labelledby`). */ export declare function Title(props: Readonly, 'id'>>): import("react").JSX.Element; /** Plain files dragged out of the system (no folders) and dropped on it are added; the keyboard uses the `Trigger` inside. */ export declare function DropZone(props: Readonly>): import("react").JSX.Element; export type TriggerRenderProps = ComponentProps<'button'> & { 'data-drag-over'?: string; 'data-disabled'?: string; }; export interface TriggerProps extends Omit, 'type'> { /** Enter / Space open the dialog on keydown (Carbon `FileUploaderDropContainer`'s button). */ openOnKeyDown?: boolean; /** Render your own button with these props, e.g. a styled one. */ render?: (props: TriggerRenderProps) => ReactElement; } /** The button that opens the file dialog (off while disabled); focus comes back to it when the list empties under it. */ export declare function Trigger({ openOnKeyDown, render, ref, ...rest }: Readonly): import("react").JSX.Element; /** The (visually hidden) label of the file `Input`. */ export declare function Label(props: Readonly, 'htmlFor'>>): import("react").JSX.Element; /** The `` the trigger clicks (hide it; out of the Tab order): a pick adds the files; `required` invalidity focuses the trigger. */ export declare function Input({ ref, ...props }: Readonly, 'type' | 'id' | 'multiple' | 'accept' | 'disabled'>>): import("react").JSX.Element; /** With a `name`: the hidden file input that submits every valid file. Renders nothing otherwise. */ export declare function FormValue({ ref }: Readonly, 'ref'>>): import("react").JSX.Element | null; /** The list of `Item`s (focus moves within it as rows go). */ export declare function List({ ref, ...rest }: Readonly>): import("react").JSX.Element; export interface ItemProps extends Omit, 'onRetry'> { name: string; /** Identifies the file in `onDelete` / `onRetry`; defaults to `name`. */ uuid?: string; status?: FileStatus; invalid?: boolean; /** On an invalid row: `Retry` shows (a failed upload). */ retryable?: boolean; disabled?: boolean; /** Upload progress 0–100 while uploading (`percent` of the context; `Remove` then cancels the upload). */ progress?: number; onDelete?: (uuid: string) => void; onRetry?: (uuid: string) => void; } interface ItemContextValue { uuid: string; name: string; status: FileStatus; invalid: boolean; retryable: boolean; disabled: boolean; /** The upload percentage while uploading with a `progress`. */ percent: number | undefined; /** "Uploaded: name" is due (the upload just finished). */ finished: boolean; row: RefObject; retryButton: RefObject; removeButton: RefObject; /** The retry button got or lost focus (kept when it is removed with focus: a removed button may not blur). */ retryFocus: (focused: boolean) => void; remove: () => void; retry: () => void; } /** The state of the enclosing `FileUploader.Item` (status, percent, finished …). */ export declare function useItemContext(part?: string): ItemContextValue; /** One file (a `
`): `edit` can be removed, `uploading` with a `progress` too (a cancel), `complete` not. */ export declare function Item({ name, uuid, status, invalid, retryable, disabled: ownDisabled, progress, onDelete, onRetry, children, ...rest }: Readonly): import("react").JSX.Element; /** The row inside the item: focus lands on it when its last button goes with focus (`aria-disabled` while disabled). */ export declare function ItemRow({ ref, ...rest }: Readonly>): import("react").JSX.Element; /** Removes the file (`onDelete`); with a `progress`, cancels its upload. Name it with the file's name. Not on a `complete` row or one uploading without a `progress` (as ``). */ export declare function Remove({ ref, ...props }: Readonly, 'type' | 'disabled'>>): import("react").JSX.Element | null; /** Starts a failed upload again (`onRetry`): only on an invalid `retryable` row. Name it with the file's name. */ export declare function Retry({ ref, ...props }: Readonly, 'type' | 'disabled'>>): import("react").JSX.Element | null; /** A polite live region (`role="status"`): its children ("Uploaded: name") once an upload finished. */ export declare function ItemStatus({ children, ...rest }: Readonly, 'role'>>): import("react").JSX.Element;