UNPKG

@holokit/core

Version:
108 lines (107 loc) 3.59 kB
import * as React from 'react'; import { Component } from 'react'; interface UploadAreaProps { /** * The type of files allowed to be selected for upload */ acceptFileType: FILETYPE; /** * The button text/CTA displayed to user to confirm upload; if no text is provided, CTA will read as "Upload File" */ actionText?: string; /** * Set to `true` if there is a problem with the file the user supplied; this will display the button to "Select new (file type)" */ fileNotCompatible?: boolean; /** * The instructional copy for the user */ infoText?: string; /** * Set to `true` to render in a loading state while upload is in progress */ isUploading?: boolean; /** * A callback function that will run when a file is dropped into the UploadArea */ onDrop?: () => void; /** * A callback function that will run when the file data in the component is updated */ onFileChange?: (arg: object) => void; /** * A callback function that will run when the user drops an incompatible file */ onFileTypeError?: (arg: string) => void; /** * A callback function that will run when the user drops multiple files in the UploadArea */ onMultipleFiles?: (arg: number) => void; /** * A callback function that will run when the user clicks to remove an uploaded file */ onRemoveFile?: () => void; /** * A callback function that will run when the user clicks to replace a selected file */ onReplace?: () => void; /** * A callback function that will run when the user clicks to select a file (initial state) */ onSelectFile?: () => void; /** * A callback function that will run when the user clicks to select a new file (when `fileNotCompatible` is true) */ onSelectNew?: () => void; /** * A callback function that will run when the upload is triggered */ onUpload: (arg: object) => void; /** * Will render as an error message (overrides any validation error rendered by the component) */ uploadError?: string; /** * Set this to `true` after the onUpload function has been called and the upload has been successful */ uploadSuccessful?: boolean; } export declare enum FILETYPE { CSV = "text/csv" } interface UploadAreaState { dragging: boolean; dragCounter: number; error: string; fileData: File | { name: string; size: number; }; showLoader: boolean; } /** * With this component, a user can drag and drop a file to upload. */ declare class UploadArea extends Component<UploadAreaProps, UploadAreaState> { static FILETYPE_TO_STRING_MAP: { "text/csv": string; }; private dropRef; fileInput: React.RefObject<HTMLInputElement>; constructor(props: UploadAreaProps); componentDidMount(): void; componentDidUpdate(prevProps: UploadAreaProps, prevState: UploadAreaState): void; componentWillUnmount(): void; handleDragEvent: (e: DragEvent) => void; static getFileSizeString: (size: number) => string; handleDrop: (e: DragEvent) => void; handleSubmit: (e: React.FormEvent<HTMLFormElement>) => void; handleFiles: () => void; handleRemoveFile: () => void; handleReplaceFile: (e: MouseEvent) => void; handleSelectFile: (e: MouseEvent) => void; handleSelectNew: (e: MouseEvent) => void; static handleFileButton: (e: KeyboardEvent | MouseEvent) => void; render(): React.JSX.Element; } export default UploadArea;