diff --git a/docs/components/Contributors/index.jsx b/docs/components/Contributors/index.jsx index a2a981f2a..711850b1d 100644 --- a/docs/components/Contributors/index.jsx +++ b/docs/components/Contributors/index.jsx @@ -7,25 +7,25 @@ import './styles.scss'; const plural = number => `${number} contribution${number > 1 ? 's' : ''}`; -class Contributors extends React.Component { - constructor() { - super(); - this.state = { contributors: [] }; - this.renderContributors = this.renderContributors.bind(this); +class Contributors extends React.PureComponent { + state = { + contributors: [], + }; + componentDidMount() { this.getContributors(); } - getContributors() { + getContributors = () => { fetch('https://api.github.com/repos/Adslot/adslot-ui/contributors') .then(response => response.json()) .then(contributors => { this.setState({ contributors }); }); - } + }; - renderContributors() { - return _.map(this.state.contributors, ( + renderContributors = () => + _.map(this.state.contributors, ( { login, avatar_url, contributions } // eslint-disable-line camelcase ) => ( )); - } render() { return ( diff --git a/src/components/adslot-ui/FilePicker/index.jsx b/src/components/adslot-ui/FilePicker/index.jsx index 3231eff09..615098eb5 100644 --- a/src/components/adslot-ui/FilePicker/index.jsx +++ b/src/components/adslot-ui/FilePicker/index.jsx @@ -7,32 +7,56 @@ require('./styles.scss'); const baseClass = 'filepicker-component'; -class FilePickerComponent extends React.Component { +class FilePickerComponent extends React.PureComponent { + static propTypes = { + disabled: PropTypes.bool, + dts: PropTypes.string, + filter: PropTypes.string, + isHighlighted: PropTypes.bool, + label: PropTypes.string, + onRemove: PropTypes.func, + onSelect: PropTypes.func.isRequired, + placeholder: PropTypes.string, + }; + + static defaultProps = { + isHighlighted: false, + label: 'Select', + placeholder: 'No file selected', + disabled: false, + }; + constructor(props) { super(props); - this.state = { isFileSelected: false, fileName: '' }; - - this.onChange = this.onChange.bind(this); - this.removeFile = this.removeFile.bind(this); + this.fileInput = React.createRef(); } - onChange(changeEvent) { + state = { + isFileSelected: false, + fileName: '', + }; + + onChange = changeEvent => { if (!this.state.isFileSelected) { this.setState({ isFileSelected: true, fileName: changeEvent.target.files[0].name }); this.props.onSelect(changeEvent.target.files[0]); } - } + }; - removeFile() { + onUploadBtnClick = () => { + this.fileInput.current.click(); + }; + + removeFile = () => { if (this.state.isFileSelected) { - this.fileInput.value = null; + this.fileInput.current.value = null; this.setState({ isFileSelected: false, fileName: '' }); if (this.props.onRemove) { this.props.onRemove(); } } - } + }; render() { const mainClass = classNames({ [`${baseClass}-highlight`]: this.props.isHighlighted }, baseClass, 'input-group'); @@ -57,17 +81,13 @@ class FilePickerComponent extends React.Component { ) : null}