@tiller-ds/upload
Version:
Upload module of Tiller Design System
84 lines (83 loc) • 3.04 kB
TypeScript
import { BatchItem } from "@rpldy/shared";
declare type FileStatus = "added" | "uploading" | "cancelled" | "finished" | "error" | "aborted";
export declare type UseFileUpload<T extends File> = {
/**
* List of currently uploaded files. Dependent of the {@link uploadedFileIds} list-
*/
uploadedFiles: Array<T>;
/**
* List of the ids of uploaded files. Needs to be updated for the change in {@link uploadedFiles} to be visible
*/
uploadedFileIds: Array<string>;
/**
* Called internally when Uploady completes file upload. Should not be used in external API
* @param file file that was uploaded
*/
onUploadedFiles: (file: T) => void;
/**
* Should be called with updated list of current file ids in any case that list is changed
* @param fileId
*/
onUploadedFileIds: (fileId: string[] | null) => void;
/**
* Should be called in case of the action of deleting a specific file
*
* @param file
*/
onDeletedFiles: (file: T | T[]) => void;
/**
* Callback is called whenever there is update in the file list
*
* @param callback function to be called on file list change (upload or delete)
*/
onUpdateCallback: (callback: Callback) => void;
/**
* Used if you do not want to manage your ids manually. Call to add uploaded file to the file list.
*
* @param id id of the file to be added
*/
addUploadedFileId: (id: string) => void;
/**
* Used if you do not want to manage your ids manually. Call to remove uploaded file to the file list.
*
* @param id id of the file to be removed
*/
removeUploadedFileIds: (id: string | string[]) => void;
};
export declare type File = {
/**
* Unique identificator of the file
*/
id: string;
/**
* Current name of the file
*/
name: string;
/**
* Original file name at the time of the upload
*/
originalFileName?: string;
/**
* Status of the file upload
*/
status: FileStatus;
/**
* History of versions of the file
*/
versions?: Array<Omit<File, "status">>;
};
/**
* Default mapper for backend response, maps to {@link File} type
* @param item item that was uploaded
* @param originalFileName original file name in the time of the upload
*/
export declare function defaultUploadResponseMapper(item: BatchItem, originalFileName: string): File;
declare type Callback = (added?: string | string[], deleted?: string | string[]) => void;
/**
* Hook that works with uploady and tracks the current file list. Can be used with manual or with automatic tracking of
* the uploaded files
* @param files initial uploaded files
* @param autoTrack should the hook automatically track uploaded files, default is false
*/
export default function useFileUpload<T extends File>(files?: Array<Omit<T, "status">>, autoTrack?: boolean): UseFileUpload<T>;
export {};