83 lines
2.0 KiB
JavaScript
Raw Normal View History

/**
*
* PluginInputFile
*
*/
import React from 'react';
import PropTypes from 'prop-types';
2018-02-16 14:17:24 +01:00
import { FormattedMessage } from 'react-intl';
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 */
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);
}
render() {
const {
name,
onChange,
showLoader,
} = this.props;
const { isDraging } = this.state;
2018-02-16 14:17:24 +01:00
const link = (
<FormattedMessage id="upload.PluginInputFile.link">
{(message) => <span className={styles.underline}>{message}</span>}
2018-02-16 14:17:24 +01:00
</FormattedMessage>
);
return (
<label
className={cn(styles.pluginInputFile, isDraging && styles.pluginInputFileHover, showLoader && styles.pluginInputFileHover)}
onDragEnter={this.handleDragEnter}
onDragOver={(e) => {
e.preventDefault();
e.stopPropagation();
}}
onDrop={this.handleDrop}
>
2018-02-16 14:17:24 +01:00
<p className={styles.textWrapper}>
{!showLoader && <FormattedMessage id="upload.PluginInputFile.text" values={{ link }} /> }
{showLoader && <FormattedMessage id="upload.PluginInputFile.loading" />}
2018-02-16 14:17:24 +01:00
</p>
<div
onDragLeave={this.handleDragLeave}
className={cn(isDraging && styles.isDraging)}
/>
<input
2018-02-16 14:17:24 +01:00
multiple
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,
showLoader: PropTypes.bool.isRequired,
};
export default PluginInputFile;