MCPcopy Create free account
hub / github.com/dailydotdev/apps / UploadButton

Function UploadButton

packages/shared/src/components/buttons/UploadButton.tsx:13–54  ·  view source on GitHub ↗
({
  onFilesDrop,
  validation = {},
  errorMessages = {},
  disabled,
  ...buttonProps
}: UploadButtonProps)

Source from the content-addressed store, hash-verified

11 Pick<DragDropProps, 'onFilesDrop' | 'validation' | 'errorMessages'>;
12
13export const UploadButton = ({
14 onFilesDrop,
15 validation = {},
16 errorMessages = {},
17 disabled,
18 ...buttonProps
19}: UploadButtonProps): ReactElement => {
20 const { displayToast } = useToastNotification();
21
22 const { validateFiles } = useFileValidation(validation, errorMessages);
23
24 const handleFiles = (files: FileList | null) => {
25 if (!files || files.length === 0) {
26 return;
27 }
28
29 const { validFiles, errors } = validateFiles(files);
30
31 if (errors.length > 0) {
32 const first = errors[0];
33 const fileName = first.file ? ` (${first.file.name})` : '';
34 displayToast(`${first.message}${fileName}`);
35 return;
36 }
37
38 onFilesDrop(validFiles);
39 };
40
41 const { input, openFileInput } = useFileInput({
42 onFiles: handleFiles,
43 accept: validation.acceptedTypes,
44 multiple: validation.multiple,
45 disabled,
46 });
47
48 return (
49 <>
50 {input}
51 <Button onClick={openFileInput} disabled={disabled} {...buttonProps} />
52 </>
53 );
54};

Callers

nothing calls this directly

Calls 3

useToastNotificationFunction · 0.90
useFileValidationFunction · 0.90
useFileInputFunction · 0.90

Tested by

no test coverage detected