2019-06-19 14:40:52 +00:00
|
|
|
import Button from "@material-ui/core/Button";
|
|
|
|
import { createStyles, withStyles, WithStyles } from "@material-ui/core/styles";
|
|
|
|
import TextField from "@material-ui/core/TextField";
|
2019-08-09 10:26:22 +00:00
|
|
|
import React from "react";
|
2019-08-26 21:54:03 +00:00
|
|
|
import { FormattedMessage } from "react-intl";
|
2019-06-19 14:40:52 +00:00
|
|
|
|
|
|
|
const styles = createStyles({
|
|
|
|
fileUploadField: {
|
|
|
|
display: "none"
|
|
|
|
},
|
|
|
|
root: {
|
|
|
|
display: "flex"
|
|
|
|
},
|
|
|
|
textField: {
|
|
|
|
flex: 1
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
interface FileUploadProps extends WithStyles<typeof styles> {
|
|
|
|
disabled?: boolean;
|
|
|
|
name?: string;
|
|
|
|
value?: any;
|
|
|
|
onChange?(event: React.ChangeEvent<any>);
|
|
|
|
}
|
|
|
|
|
|
|
|
const FileUpload = withStyles(styles, { name: "FileUpload" })(
|
|
|
|
({ classes, disabled, name, value, onChange }: FileUploadProps) => (
|
|
|
|
<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()}>
|
2019-08-26 21:54:03 +00:00
|
|
|
<FormattedMessage
|
|
|
|
defaultMessage="Upload"
|
|
|
|
description="upload file, button"
|
|
|
|
/>
|
2019-06-19 14:40:52 +00:00
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
FileUpload.displayName = "FileUpload";
|
|
|
|
export default FileUpload;
|