import { SvelteComponentTyped } from "svelte"; import type { SvelteHTMLElements } from "svelte/elements"; type $RestProps = SvelteHTMLElements["div"]; type $Props = { /** * Specify the file uploader status. * Applied to every file row unless overridden by `fileStatus`. * @default "uploading" */ status?: "uploading" | "edit" | "complete"; /** * Override the global `status` for an individual file. * Receives `(file, index)` and returns `"uploading" | "edit" | "complete"`. * When omitted, every row uses `status`. */ fileStatus?: undefined | ((file: File, index: number) => "uploading" | "edit" | "complete"); /** * Mark an individual file as invalid. * Receives `(file, index)` and returns a boolean. */ fileInvalid?: undefined | ((file: File, index: number) => boolean); /** * Per-file error subject when the row is invalid. * Receives `(file, index)` and returns the subject text. * The error is announced with `role="alert"` when the row becomes * invalid, and describes the row's remove button. */ fileErrorSubject?: undefined | ((file: File, index: number) => string); /** * Per-file error body when the row is invalid. * Receives `(file, index)` and returns the body text. */ fileErrorBody?: undefined | ((file: File, index: number) => string); /** * Show each file's size under its name. * - `false` (default): show the name only * - `true` or `"decimal"`: format `file.size` with decimal units (1000 bytes = 1 kB) * - `"binary"`: format `file.size` with binary units (1024 bytes = 1 KiB) * - A function receiving `(file, index)` that returns the text (e.g., a localized size) * @default false */ fileSize?: boolean | "decimal" | "binary" | ((file: File, index: number) => string); /** * Set to `true` for the selected files to fill the container instead of * stopping at 20rem. * @default false */ fullWidth?: boolean; /** * Set to `true` to disable the file uploader. * Also disables each file row's remove button. * @default false */ disabled?: boolean; /** * Specify the accepted file types. * @default [] */ accept?: ReadonlyArray; /** * Specify the minimum file size in bytes. * Smaller files are filtered out and reported via the `rejected` event * with `reason: 'size'`. Use `1` to reject empty files. */ minFileSize?: number | undefined; /** * Specify the maximum file size in bytes. * Files exceeding this limit will be filtered out. * The limit is a raw byte count: use `5 * 1000 * 1000` for 5 MB * (decimal) or `5 * 1024 * 1024` for 5 MiB (binary). * @example * ```svelte * * * ``` */ maxFileSize?: number | undefined; /** * Obtain a reference to the uploaded files. * @default [] */ files?: ReadonlyArray; /** * Open the device camera instead of the file picker on mobile. * `"user"` requests the front camera and `"environment"` the rear camera. * Desktop browsers ignore it and open the file picker. */ capture?: "user" | "environment" | undefined; /** * Set to `true` to select a folder instead of individual files. * Every file inside the folder and its subfolders is added, and each row * shows the file's path relative to the selected folder. Browsers do not * apply `accept` to folder contents. * @default false */ directory?: boolean; /** * Set to `true` to allow multiple files * @default false */ multiple?: boolean; /** * Set to `true` to reject files that match an already-selected file * (by name, size, and lastModified). Rejected duplicates are reported * via the `rejected` event with `reason: 'duplicate'`. * @default false */ preventDuplicate?: boolean; /** * Control how newly added files are ordered in the list. * - `"append"` (default): new files appear at the end * - `"prepend"`: new files appear at the beginning * - A custom function receiving (existingFiles, newFiles) that returns the merged array * @default "append" */ orderFiles?: "append" | "prepend" | ((existing: ReadonlyArray, added: ReadonlyArray) => ReadonlyArray); /** * Specify the label title. * Alternatively, use the named slot "labelTitle". * @example * ```svelte * * Custom Label * * ``` * @default "" */ labelTitle?: string; /** * Specify the label description. * Alternatively, use the named slot "labelDescription". * @example * ```svelte * * Custom description text * * ``` * @default "" */ labelDescription?: string; /** * Specify the kind of file uploader button. * @default "primary" */ kind?: import("../Button/Button.svelte").ButtonProps["kind"]; /** * Specify the size of the file uploader button. * At `"xs"`, the file rows are extra small too. * Inherits the height of the parent `Form` size when unset, * otherwise defaults to `"small"`. * Accepts the same Carbon v11 aliases as `Button`. */ size?: import("../Button/Button.svelte").ButtonProps["size"] | undefined; /** * Specify the button label * @default "" */ buttonLabel?: string; /** * Accessible label for file row status icons (spinner, remove control, checkmark). * Forwarded to `Filename`. Use a string, or a function with context `{ file, fileName, status, invalid }` * where `file` is the row's `File` (only set from `FileUploader`, not from `FileUploaderItem`). * When omitted or the resolved value is blank after trim, `Filename` uses built-in defaults. */ iconDescription?: string | undefined | ((ctx: { file?: File; fileName: string; status: "uploading" | "edit" | "complete"; invalid: boolean }) => string | undefined); /** * Specify a name attribute for the file button uploader input * @default "" */ name?: string; /** * Specify the id of a form element outside the component to associate * the file input with. */ form?: string | undefined; /** * Set an id for the top-level element. * The file input id derives from it as `{id}-input`, and the label * description id as `{id}-description`. * @default uniqueId() */ id?: string; /** * Obtain a reference to the input HTML element. * @default null */ ref?: null | HTMLInputElement; [key: `data-${string}`]: unknown; }; export type FileUploaderProps = Omit<$RestProps, keyof $Props> & $Props; export default class FileUploader extends SvelteComponentTyped< FileUploaderProps, { add: CustomEvent>; change: CustomEvent>; clear: CustomEvent; click: WindowEventMap["click"]; keydown: WindowEventMap["keydown"]; mouseenter: WindowEventMap["mouseenter"]; mouseleave: WindowEventMap["mouseleave"]; mouseover: WindowEventMap["mouseover"]; rejected: CustomEvent>; remove: CustomEvent>; }, { labelDescription: Record; labelTitle: Record; } > { /** * Programmatically clear the uploaded files. * @example * ```svelte * * * ``` */ clearFiles: () => void; }