|
| 1 | +import { OverridableProps } from "@unlimited-react-components/kernel"; |
| 2 | +import { Localization } from "../../../../localization/localization"; |
| 3 | +import { FileItemContainerProps } from "../../../file-item/components/FileItemContainer/FileItemContainerProps"; |
| 4 | +import { FileDuiResponse } from "../utils/dropzone-ui.upload.utils"; |
| 5 | +import { CustomValidateFileResponse, FileValidated } from "../utils/validation.utils"; |
| 6 | +export interface DropzoneProps extends OverridableProps { |
| 7 | + /** |
| 8 | + * This event is triggered when files are dropped or selected. |
| 9 | + * Returns as first parameter the list of FileValidate files dropped or selected. |
| 10 | + */ |
| 11 | + onDrop?: (filesDropped: FileValidated[]) => void; |
| 12 | + /** |
| 13 | + * server Url or endpoint to upload the files |
| 14 | + */ |
| 15 | + url?: string; |
| 16 | + /** |
| 17 | + * upload method, can be POST | PUT | PATCH |
| 18 | + */ |
| 19 | + method?: "POST" | "PUT" | "PATCH"; |
| 20 | + /** |
| 21 | + * Extra configuration for uploading |
| 22 | + * e.g. headers or bearer token |
| 23 | + * default: |
| 24 | + * config = { |
| 25 | + * headers: { |
| 26 | + * "content-type": "multipart/form-data", |
| 27 | + * }, |
| 28 | + * } |
| 29 | + * |
| 30 | + */ |
| 31 | + config?: Object; |
| 32 | + /** |
| 33 | + * If true, onDrop event will return the list of files, but also |
| 34 | + * will upload the files if url was set, and also config |
| 35 | + */ |
| 36 | + uploadOnDrop?: boolean; |
| 37 | + /** |
| 38 | + * Max number of files to be accepted. |
| 39 | + */ |
| 40 | + maxFiles?: number; |
| 41 | + /** |
| 42 | + * max file size allowed in bytes |
| 43 | + */ |
| 44 | + maxFileSize?: number; |
| 45 | + /** |
| 46 | + * If true, the dropzone component itself will be clickable |
| 47 | + */ |
| 48 | + clickable?: boolean; |
| 49 | + /** |
| 50 | + * Extra featur to perform on click |
| 51 | + * Only if clickable was set to true |
| 52 | + */ |
| 53 | + onClick?: Function; |
| 54 | + /** |
| 55 | + * The default implementation of accept |
| 56 | + * checks the file's mime type or extension |
| 57 | + * against this list. This is a comma |
| 58 | + * separated list of mime types or file extensions. |
| 59 | + * Eg.: image/*,application/pdf,.psd |
| 60 | + */ |
| 61 | + accept?: string; |
| 62 | + /** |
| 63 | + * If true, files that does not match accept |
| 64 | + * criteria will be ignored |
| 65 | + */ |
| 66 | + removeOnDrop?: boolean; |
| 67 | + /** |
| 68 | + * If present, delete all butoon will be visible |
| 69 | + * and will trigger this function onClick |
| 70 | + */ |
| 71 | + onReset?: Function; |
| 72 | + /** |
| 73 | + * if true, will show a ripple everytime |
| 74 | + * the user drops files os selects files |
| 75 | + */ |
| 76 | + disableRipple?: boolean; |
| 77 | + /** |
| 78 | + * The background color for dropzone, |
| 79 | + * by default is linear-gradient(to bottom, aliceblue,#b7a8a8) |
| 80 | + */ |
| 81 | + backgroundColor?: string; |
| 82 | + /** |
| 83 | + * custom validator |
| 84 | + * must be a function that recieves as first parameter a File Object |
| 85 | + * and must return a boolean value |
| 86 | + */ |
| 87 | + validator?: (f: File) => CustomValidateFileResponse; |
| 88 | + /** |
| 89 | + * The current number of valid files |
| 90 | + */ |
| 91 | + /** |
| 92 | + * If present will make change view visible |
| 93 | + * and also return the selected view mode |
| 94 | + */ |
| 95 | + onChangeView?: Function; |
| 96 | + /** |
| 97 | + * The current view |
| 98 | + */ |
| 99 | + view?: FileItemContainerProps["view"]; |
| 100 | + /** |
| 101 | + * The max height of the container |
| 102 | + * in string format |
| 103 | + * by default "500px" |
| 104 | + * |
| 105 | + * examples: |
| 106 | + * "50vh" |
| 107 | + * "20%" |
| 108 | + * "40em" |
| 109 | + * "1rem" |
| 110 | + */ |
| 111 | + maxHeight?: string; |
| 112 | + /** |
| 113 | + * The max height of the container |
| 114 | + * in string format |
| 115 | + * by default "500px" |
| 116 | + * |
| 117 | + * examples: |
| 118 | + * "50vh" |
| 119 | + * "20%" |
| 120 | + * "40em" |
| 121 | + * "1rem" |
| 122 | + */ |
| 123 | + minHeight?: string; |
| 124 | + /** |
| 125 | + * if true, shows the dropzone footer |
| 126 | + */ |
| 127 | + footer?: boolean; |
| 128 | + /** |
| 129 | + * if true, shows the dropzone footer |
| 130 | + */ |
| 131 | + header?: boolean; |
| 132 | + /** |
| 133 | + * Just like any other input component |
| 134 | + * the value prop is the current value |
| 135 | + */ |
| 136 | + value?: FileValidated[]; |
| 137 | + /** |
| 138 | + * This event is triggered when upload process starts |
| 139 | + * also returns the list of files that will be uploaded, |
| 140 | + * Unlike Onchange, onUploadStart will only return a list of files thta are candidates to be uploaded, |
| 141 | + * in case they are valid or upload status is "error" |
| 142 | + */ |
| 143 | + onUploadStart?: (files: FileValidated[]) => void; |
| 144 | + /** |
| 145 | + * This event returns as first aparameter the list of responses for each file following the structure: |
| 146 | + * responses = [ |
| 147 | + * {id: <the file id>, serverResponse: the server response} |
| 148 | + * ] |
| 149 | + */ |
| 150 | + onUploadFinish?: (responses: FileDuiResponse[]) => void; |
| 151 | + /** |
| 152 | + * A message to show in the footer when the uploading process happens |
| 153 | + */ |
| 154 | + uploadingMessage?: string; |
| 155 | + /** |
| 156 | + * Probably one of the most important methods. |
| 157 | + * Onchange returns as first parameter the list of validated files, |
| 158 | + * following the structure: |
| 159 | + * file = |
| 160 | + * { |
| 161 | + * file: File; |
| 162 | + * valid: boolean; |
| 163 | + * id: number | string | undefined; |
| 164 | + * errors?: string[]; |
| 165 | + * uploadMessage?: string; |
| 166 | + * uploadStatus?: undefined | "uploading", success, error; |
| 167 | + * } |
| 168 | + * |
| 169 | + * This event is also triggered when upload starts and when upload |
| 170 | + * finishes for each file in order to update the props on very FIleItem |
| 171 | + */ |
| 172 | + onChange?: (files: FileValidated[]) => void; |
| 173 | + /** |
| 174 | + * This event is triggered when "clean button is clicked" |
| 175 | + * Retuns as first parameter the list of files without not valid files |
| 176 | + */ |
| 177 | + onClean?: (files: FileValidated[]) => void; |
| 178 | + /** |
| 179 | + * The behaviuor on drop files |
| 180 | + */ |
| 181 | + behaviour?: "add" | "replace"; |
| 182 | + /** |
| 183 | + * Label to place when no files selected |
| 184 | + */ |
| 185 | + label?: string; |
| 186 | + /** |
| 187 | + * Use this prop only in development mode |
| 188 | + * This will make dropzone to simulate a server upload |
| 189 | + */ |
| 190 | + fakeUploading?: boolean; |
| 191 | + /** |
| 192 | + * language to be used |
| 193 | + * for now |
| 194 | + * only English, French , Portuguese and Spanish are supported |
| 195 | + */ |
| 196 | + localization?: Localization; |
| 197 | +} |
| 198 | +export declare const DropzonePropsDefault: DropzoneProps; |
0 commit comments