2023-03-17 22:26:15 +00:00
|
|
|
import React from "react";
|
2023-04-27 15:10:41 +00:00
|
|
|
import classnames from "classnames";
|
2023-03-06 15:03:48 +00:00
|
|
|
|
|
|
|
|
import Button from "components/buttons/Button";
|
|
|
|
|
import Icon from "components/Icon";
|
|
|
|
|
import { IconNames } from "components/icons";
|
2023-10-10 22:00:45 +00:00
|
|
|
import Card from "components/Card";
|
2023-03-06 15:03:48 +00:00
|
|
|
|
|
|
|
|
const baseClass = "file-uploader";
|
|
|
|
|
|
|
|
|
|
interface IFileUploaderProps {
|
|
|
|
|
icon: IconNames;
|
|
|
|
|
message: string;
|
2023-10-10 22:00:45 +00:00
|
|
|
additionalInfo?: string;
|
2023-03-06 15:03:48 +00:00
|
|
|
isLoading?: boolean;
|
2023-10-10 22:00:45 +00:00
|
|
|
/** A comma seperated string of one or more file types accepted to upload.
|
|
|
|
|
* This is the same as the html accept attribute.
|
|
|
|
|
* https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept
|
|
|
|
|
*/
|
2023-04-27 15:10:41 +00:00
|
|
|
accept?: string;
|
|
|
|
|
className?: string;
|
2023-03-06 15:03:48 +00:00
|
|
|
onFileUpload: (files: FileList | null) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FileUploader = ({
|
|
|
|
|
icon,
|
|
|
|
|
message,
|
2023-10-10 22:00:45 +00:00
|
|
|
additionalInfo,
|
2023-03-06 15:03:48 +00:00
|
|
|
isLoading = false,
|
2023-04-27 15:10:41 +00:00
|
|
|
accept,
|
|
|
|
|
className,
|
2023-03-06 15:03:48 +00:00
|
|
|
onFileUpload,
|
|
|
|
|
}: IFileUploaderProps) => {
|
2023-04-27 15:10:41 +00:00
|
|
|
const classes = classnames(baseClass, className);
|
|
|
|
|
|
2023-03-06 15:03:48 +00:00
|
|
|
return (
|
2023-10-10 22:00:45 +00:00
|
|
|
<Card color="gray" className={classes}>
|
2023-03-06 15:03:48 +00:00
|
|
|
<Icon name={icon} />
|
2023-10-10 22:00:45 +00:00
|
|
|
<p className={`${baseClass}__message`}>{message}</p>
|
|
|
|
|
<p className={`${baseClass}__additional-info`}>{additionalInfo}</p>
|
|
|
|
|
<Button
|
|
|
|
|
className={`${baseClass}__upload-button`}
|
|
|
|
|
variant="brand"
|
|
|
|
|
isLoading={isLoading}
|
|
|
|
|
>
|
2023-03-17 22:26:15 +00:00
|
|
|
<label htmlFor="upload-profile">Upload</label>
|
2023-03-06 15:03:48 +00:00
|
|
|
</Button>
|
|
|
|
|
<input
|
2023-04-27 15:10:41 +00:00
|
|
|
accept={accept}
|
2023-03-06 15:03:48 +00:00
|
|
|
id="upload-profile"
|
|
|
|
|
type="file"
|
2023-03-20 19:30:13 +00:00
|
|
|
onChange={(e) => {
|
|
|
|
|
onFileUpload(e.target.files);
|
|
|
|
|
e.target.value = "";
|
|
|
|
|
}}
|
2023-03-06 15:03:48 +00:00
|
|
|
/>
|
2023-10-10 22:00:45 +00:00
|
|
|
</Card>
|
2023-03-06 15:03:48 +00:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default FileUploader;
|