({
onFilesDrop,
validation = {},
errorMessages = {},
disabled = false,
className,
state,
inputRef,
isCompactList,
ctaSize,
renderCta,
isCopyBold,
dragDropDescription = 'Drag & Drop your CV or',
ctaLabelDesktop = 'Upload CV',
ctaLabelMobile = 'Upload CV',
uploadIcon,
showRemove,
fullClick = false,
}: DragDropProps)
| 140 | 'relative flex flex-1 rounded-10 border border-dashed border-border-subtlest-secondary'; |
| 141 | |
| 142 | function DragDropComponent({ |
| 143 | onFilesDrop, |
| 144 | validation = {}, |
| 145 | errorMessages = {}, |
| 146 | disabled = false, |
| 147 | className, |
| 148 | state, |
| 149 | inputRef, |
| 150 | isCompactList, |
| 151 | ctaSize, |
| 152 | renderCta, |
| 153 | isCopyBold, |
| 154 | dragDropDescription = 'Drag & Drop your CV or', |
| 155 | ctaLabelDesktop = 'Upload CV', |
| 156 | ctaLabelMobile = 'Upload CV', |
| 157 | uploadIcon, |
| 158 | showRemove, |
| 159 | fullClick = false, |
| 160 | }: DragDropProps): ReactElement { |
| 161 | const [filenames, setFilenames] = useState<string[]>([]); |
| 162 | const isLaptop = useViewSize(ViewSize.Laptop); |
| 163 | const { displayToast } = useToastNotification(); |
| 164 | const isError = state === 'error'; |
| 165 | |
| 166 | const { validateFiles } = useFileValidation(validation, errorMessages); |
| 167 | |
| 168 | const handleFiles = (files: FileList | null) => { |
| 169 | if (!files || files.length === 0) { |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | const { validFiles, errors } = validateFiles(files); |
| 174 | |
| 175 | if (errors.length > 0) { |
| 176 | const first = errors[0]; |
| 177 | const fileName = first.file ? ` (${first.file.name})` : ''; |
| 178 | displayToast(`${first.message}${fileName}`); |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | setFilenames(validFiles.map((f) => f.name)); |
| 183 | onFilesDrop(validFiles, errors.length > 0 ? errors : undefined); |
| 184 | }; |
| 185 | |
| 186 | const { input, openFileInput } = useFileInput({ |
| 187 | inputRef, |
| 188 | onFiles: handleFiles, |
| 189 | accept: validation.acceptedTypes, |
| 190 | multiple: validation.multiple, |
| 191 | disabled, |
| 192 | }); |
| 193 | |
| 194 | const { |
| 195 | isDragOver, |
| 196 | isDragValid, |
| 197 | handleDragEnter, |
| 198 | handleDragOver, |
| 199 | handleDragLeave, |
nothing calls this directly
no test coverage detected