2018-02-15 18:26:05 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* PluginInputFile
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-02-16 14:17:24 +01:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2018-02-15 18:26:05 +01:00
|
|
|
import cn from 'classnames';
|
|
|
|
|
|
|
|
import styles from './styles.scss';
|
|
|
|
|
2018-02-22 12:08:11 +01:00
|
|
|
/* eslint-disable react/no-string-refs */
|
|
|
|
/* eslint-disable jsx-a11y/label-has-for */
|
2018-02-15 18:26:05 +01:00
|
|
|
class PluginInputFile extends React.PureComponent {
|
|
|
|
state = { isDraging: false };
|
|
|
|
|
|
|
|
handleDragEnter = () => this.setState({ isDraging: true });
|
|
|
|
|
|
|
|
handleDragLeave = () => this.setState({ isDraging: false });
|
|
|
|
|
|
|
|
handleDrop = (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.setState({ isDraging: false });
|
2018-02-16 14:17:24 +01:00
|
|
|
this.props.onDrop(e);
|
2018-02-15 18:26:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
name,
|
|
|
|
onChange,
|
2018-03-06 09:31:44 +01:00
|
|
|
showLoader,
|
2018-02-15 18:26:05 +01:00
|
|
|
} = this.props;
|
|
|
|
const { isDraging } = this.state;
|
2018-02-16 14:17:24 +01:00
|
|
|
const link = (
|
|
|
|
<FormattedMessage id="upload.PluginInputFile.link">
|
2018-02-26 11:39:50 +01:00
|
|
|
{(message) => <span className={styles.underline}>{message}</span>}
|
2018-02-16 14:17:24 +01:00
|
|
|
</FormattedMessage>
|
|
|
|
);
|
2018-02-15 18:26:05 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<label
|
2018-03-06 09:31:44 +01:00
|
|
|
className={cn(styles.pluginInputFile, isDraging && styles.pluginInputFileHover, showLoader && styles.pluginInputFileHover)}
|
2018-02-15 18:26:05 +01:00
|
|
|
onDragEnter={this.handleDragEnter}
|
|
|
|
onDragOver={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
onDrop={this.handleDrop}
|
|
|
|
>
|
2018-02-16 14:17:24 +01:00
|
|
|
<p className={styles.textWrapper}>
|
2018-03-06 09:31:44 +01:00
|
|
|
{!showLoader && <FormattedMessage id="upload.PluginInputFile.text" values={{ link }} /> }
|
|
|
|
{showLoader && <FormattedMessage id="upload.PluginInputFile.loading" />}
|
2018-02-16 14:17:24 +01:00
|
|
|
</p>
|
2018-02-15 18:26:05 +01:00
|
|
|
<div
|
|
|
|
onDragLeave={this.handleDragLeave}
|
|
|
|
className={cn(isDraging && styles.isDraging)}
|
|
|
|
/>
|
|
|
|
<input
|
2018-02-16 14:17:24 +01:00
|
|
|
multiple
|
2018-02-15 18:26:05 +01:00
|
|
|
name={name}
|
|
|
|
onChange={onChange}
|
|
|
|
type="file"
|
|
|
|
/>
|
|
|
|
</label>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PluginInputFile.defaultProps = {
|
|
|
|
onChange: () => {},
|
|
|
|
};
|
|
|
|
|
|
|
|
PluginInputFile.propTypes = {
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
onChange: PropTypes.func,
|
2018-02-22 12:08:11 +01:00
|
|
|
onDrop: PropTypes.func.isRequired,
|
2018-03-06 09:31:44 +01:00
|
|
|
showLoader: PropTypes.bool.isRequired,
|
2018-02-15 18:26:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default PluginInputFile;
|