import type { ButtonKind } from '../button/button.js'; import { UiElement } from '../shared/element.js'; import { type FileStatus } from '../../core/file-uploader.js'; import type { FileUploaderSize } from './file-uploader-shared.js'; import '../button/button.js'; import '../progress-bar/progress-bar.js'; export * from './file-uploader-item.js'; export type { FileUploaderSize } from './file-uploader-shared.js'; export type { FileStatus } from '../../core/file-uploader.js'; /** One file in a ``'s `files` list. */ export interface FileItem { uuid: string; name: string; file: File; /** Rejected by `accept` / `max-file-size` / `max-files` / `max-total-size` (Carbon `invalidFileType`), or a failed upload. */ invalid?: boolean; status?: FileStatus; errorSubject?: string; errorBody?: string; /** Upload progress 0–100 while `status` is uploading: a bar under the row and the percentage instead of the spinner. */ progress?: number; /** An invalid row (a failed upload) shows a retry button (`ui-retry`); refused files aren't retryable. */ retryable?: boolean; } export interface FileChangeDetail { addedFiles: FileItem[]; removedFiles: FileItem[]; currentFiles: FileItem[]; action: 'add' | 'remove' | 'clear'; } /** * Carbon `FileUploader` / `FileUploaderDropContainer`: a title, a description and either an * "Add file" button (default) or a dashed drop zone (`drop`) that opens the file dialog; the * chosen files are listed as ``s. `accept` (extensions or MIME types) * and `max-file-size` mark rejected files invalid with `invalid-type-text` / `too-large-text`. * Items start in `status` (edit / uploading / complete); update `files` yourself as uploads * progress. Form-associated: every valid file is submitted under `name`. * * Beyond Carbon: `max-files` and `max-total-size` (bytes) add the files past them as invalid rows * too (`too-many-text` / `total-too-large-text`); a file's `progress` shows a bar and the * percentage while it uploads; a failed upload you mark `invalid` + `retryable` gets a retry * button (`ui-retry`); `show-size` shows each file's size. * * State on the host for styling: `data-drag-over` while files are dragged over the drop zone. * * @cssstate drag-over - While files are dragged over the drop zone (also `[data-drag-over]`) * @slot - Extra ``s (e.g. files already on the server) * @fires ui-add - detail: { addedFiles } right after the user picks files (invalid ones included) * @fires ui-change - detail: { addedFiles, removedFiles, currentFiles, action } * @fires change - Native-style, alongside `ui-change` * @fires ui-delete - detail: { deletedFile, remainingFiles } * @fires ui-retry - detail: { retriedFile } when the user retries a failed upload * @csspart title - Label title * @csspart description - Label description * @csspart trigger - The button or drop zone * @csspart drop-icon - The drop zone's upload icon (hidden unless a design shows it) * @csspart items - The file list * @cssprop --ui-field-radius - Corner radius of the drop zone (the field setting); `--ui-file-drop-radius` overrides it (Kanok: 12px) * @cssprop --ui-file-uploader-max-width - Widest the drop zone and the file rows get (default Carbon's 320px; Kanok: none) * @cssprop --ui-file-drop-direction - The drop zone's layout: `flex-direction` (default row), `--ui-file-drop-align` / `-justify` / `-text-align` / `-gap` (default flex-start, space-between, start, 0; Kanok: a centred column, 12px apart) * @cssprop --ui-file-drop-height - `block-size` of the drop zone (default Carbon's 96px; Kanok: auto), `--ui-file-drop-min-height` (Kanok: 136px), `--ui-file-drop-padding` (default 16px; Kanok: 24px) * @cssprop --ui-file-drop-background - Fill of the drop zone (default transparent; Kanok: the fields' fill); `--ui-file-drop-hover-background` while hovered or dragged over (Kanok: `--ui-highlight`) * @cssprop --ui-file-drop-hover-border-color - Its dashed line while hovered or dragged over (default unchanged; Kanok: `--ui-primary`); `--ui-file-drop-hover-outline` the outline then (default `--ui-focus`; Kanok: transparent), `--ui-file-drop-hover-decoration` the text (default underline; Kanok: none) * @cssprop --ui-file-drop-icon-display - The upload icon (default none; Kanok: grid, a 40px circle: `--ui-file-drop-icon-background` its fill, `--ui-file-drop-icon-color` the icon) */ export declare class UiFileUploader extends UiElement { static hostStates: readonly string[]; /** `el.focus()` lands on the control inside. */ static readonly shadowRootOptions: ShadowRootInit; static readonly formAssociated = true; static readonly styles: import("lit").CSSResult[]; labelTitle: string; private readonly localize; labelDescription: string; /** Button text; replaced by the file name / "N files" after a pick unless `keep-label`. */ buttonLabel: string; buttonKind: ButtonKind; /** Button and item sizes. */ size: FileUploaderSize; /** Render the dashed drop zone instead of the button (Carbon `FileUploaderDropContainer`). */ drop: boolean; dropLabel: string; /** Comma-separated extensions / MIME types, e.g. ".pdf,.jpg,image/png". */ accept: string; multiple: boolean; /** Bytes; larger files are added as invalid. */ 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; /** Show each file's size in its row ("1.2 MB", in the page language). */ showSize: boolean; name: string; disabled: boolean; /** Status new items start in (Carbon `filenameStatus`). */ status: FileStatus; iconLabel: string; keepLabel: boolean; /** At least one valid file must be chosen before the form submits. */ required: boolean; /** Validation message for `required`; defaults to the translation. */ requiredText: string; invalidTypeText: string; tooLargeText: string; tooManyText: string; totalTooLargeText: string; invalidBodyText: string; /** The current list; replace it (new array) to update statuses or errors. */ files: FileItem[]; private dragOver; private pickedLabel; /** Disabled, reset defaults, validation on submit and the name given from outside (shared by the form fields). */ private readonly formControl; private readonly input; /** Message from `setCustomValidity()`; '' = none. */ private customValidityMessage; /** Like `.setCustomValidity()`: a non-empty message makes the field invalid until cleared with ''. */ setCustomValidity(message: string): void; private readonly ids; get form(): HTMLFormElement | null; get validity(): ValidityState; get validationMessage(): string; checkValidity(): boolean; reportValidity(): boolean; /** Focus the trigger when the form reports this field first. */ connectedCallback(): void; disconnectedCallback(): void; formResetCallback(): void; formDisabledCallback(disabled: boolean): void; private get isDisabled(); protected updated(changed: Map): void; private syncFormValue; /** Open the file dialog. */ browse(): void; /** A picked file as a list item, invalid with its error when refused. */ private toItem; /** Add files as if the user picked them. */ addFiles(files: File[]): void; removeFile(uuid: string): void; clearFiles(): void; private emitChange; private onInputChange; private onDragOver; private onDragLeave; private onDrop; private onTriggerKeydown; private onItemDelete; /** Focus would fall to `` with the removed row: move it to the next remove button, else the previous, else the trigger. */ private focusAfterRemoval; /** A listed file's retry: re-sent with the whole item (slotted items' events pass through as they are). */ private onItemRetry; private renderedItems; private renderTrigger; render(): import("lit-html").TemplateResult<1>; } export interface FileAddDetail { addedFiles: FileItem[]; } export interface FileDeleteDetail { deletedFile: FileItem; remainingFiles: FileItem[]; } export interface FileRetryDetail { retriedFile: FileItem; } export interface UiFileUploaderEventMap extends HTMLElementEventMap { 'ui-add': CustomEvent; 'ui-delete': CustomEvent; 'ui-change': CustomEvent; 'ui-retry': CustomEvent; } /** Typed listeners for UiFileUploader's events (declaration merging with the class). */ export interface UiFileUploader { addEventListener(type: K, listener: (this: UiFileUploader, event: UiFileUploaderEventMap[K]) => unknown, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: UiFileUploader, event: UiFileUploaderEventMap[K]) => unknown, options?: boolean | EventListenerOptions): void; removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } declare global { interface HTMLElementTagNameMap { 'ui-file-uploader': UiFileUploader; } }