saleor-dashboard/src/components/FileUpload/FileUpload.tsx

62 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-06-19 14:40:52 +00:00
import Button from "@material-ui/core/Button";
2019-10-30 14:34:24 +00:00
import { makeStyles } from "@material-ui/core/styles";
2019-06-19 14:40:52 +00:00
import TextField from "@material-ui/core/TextField";
2019-08-09 10:26:22 +00:00
import React from "react";
import { FormattedMessage } from "react-intl";
2019-06-19 14:40:52 +00:00
2019-12-03 15:28:40 +00:00
const useStyles = makeStyles(
{
fileUploadField: {
display: "none"
},
root: {
display: "flex"
},
textField: {
flex: 1
}
2019-06-19 14:40:52 +00:00
},
2019-12-03 15:28:40 +00:00
{ name: "FileUpload" }
);
2019-06-19 14:40:52 +00:00
2019-10-30 14:34:24 +00:00
interface FileUploadProps {
2019-06-19 14:40:52 +00:00
disabled?: boolean;
name?: string;
value?: any;
onChange?(event: React.ChangeEvent<any>);
}
2019-10-30 14:34:24 +00:00
const FileUpload: React.FC<FileUploadProps> = props => {
const { disabled, name, value, onChange } = props;
const classes = useStyles(props);
return (
2019-06-19 14:40:52 +00:00
<div className={classes.root}>
<input
disabled={disabled}
name={name}
onChange={onChange}
ref={ref => (this.upload = ref)}
className={classes.fileUploadField}
type="file"
value={value}
/>
<TextField
className={classes.textField}
disabled={disabled}
onChange={undefined}
value={value}
/>
<Button disabled={disabled} onClick={() => this.upload.click()}>
<FormattedMessage
defaultMessage="Upload"
description="upload file, button"
/>
2019-06-19 14:40:52 +00:00
</Button>
</div>
2019-10-30 14:34:24 +00:00
);
};
2019-06-19 14:40:52 +00:00
FileUpload.displayName = "FileUpload";
export default FileUpload;