-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathFileUploadButton.tsx
48 lines (44 loc) · 1.26 KB
/
FileUploadButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import React, { PropsWithChildren } from 'react';
import { AttachmentIcon } from './icons';
import { UploadButton } from './UploadButton';
import { useTranslationContext } from '../../context';
export type FileUploadButtonProps = {
handleFiles: (files: FileList | File[]) => void;
accepts?: string | string[];
disabled?: boolean;
multiple?: boolean;
resetOnChange?: boolean;
};
/**
* @deprecated will be removed in the next major release
*/
export const FileUploadButton = ({
disabled = false,
multiple = false,
children = <AttachmentIcon />,
handleFiles,
accepts,
resetOnChange = true,
}: PropsWithChildren<FileUploadButtonProps>) => {
const { t } = useTranslationContext('FileUploadButton');
let className = 'rfu-file-upload-button';
if (disabled) {
className = `${className} rfu-file-upload-button--disabled`;
}
return (
<div className={className}>
<label>
<UploadButton
accept={Array.isArray(accepts) ? accepts.join(',') : accepts}
aria-label={t('aria/File input')}
className='rfu-file-input'
disabled={disabled}
multiple={multiple}
onFileChange={handleFiles}
resetOnChange={resetOnChange}
/>
{children}
</label>
</div>
);
};