You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.6 KiB
62 lines
1.6 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import IconButton from '../../../components/icon_button';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
8 years ago
|
import { defineMessages, injectIntl } from 'react-intl';
|
||
|
|
||
|
const messages = defineMessages({
|
||
|
upload: { id: 'upload_button.label', defaultMessage: 'Add media' }
|
||
|
});
|
||
8 years ago
|
|
||
8 years ago
|
|
||
|
const iconStyle = {
|
||
|
height: null,
|
||
|
lineHeight: '27px'
|
||
|
}
|
||
|
|
||
8 years ago
|
class UploadButton extends React.PureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
constructor (props, context) {
|
||
|
super(props, context);
|
||
|
this.handleChange = this.handleChange.bind(this);
|
||
|
this.handleClick = this.handleClick.bind(this);
|
||
|
this.setRef = this.setRef.bind(this);
|
||
|
}
|
||
8 years ago
|
|
||
|
handleChange (e) {
|
||
|
if (e.target.files.length > 0) {
|
||
|
this.props.onSelectFile(e.target.files);
|
||
|
}
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
handleClick () {
|
||
8 years ago
|
this.fileElement.click();
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
setRef (c) {
|
||
|
this.fileElement = c;
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
|
render () {
|
||
8 years ago
|
|
||
8 years ago
|
const { intl, resetFileKey, disabled } = this.props;
|
||
8 years ago
|
|
||
8 years ago
|
return (
|
||
8 years ago
|
<div className='compose-form__upload-button'>
|
||
8 years ago
|
<IconButton icon='camera' title={intl.formatMessage(messages.upload)} disabled={disabled} onClick={this.handleClick} className='compose-form__upload-button-icon' size={18} inverted style={iconStyle}/>
|
||
8 years ago
|
<input key={resetFileKey} ref={this.setRef} type='file' multiple={false} onChange={this.handleChange} disabled={disabled} style={{ display: 'none' }} />
|
||
8 years ago
|
</div>
|
||
|
);
|
||
|
}
|
||
|
|
||
8 years ago
|
}
|
||
|
|
||
|
UploadButton.propTypes = {
|
||
|
disabled: PropTypes.bool,
|
||
|
onSelectFile: PropTypes.func.isRequired,
|
||
|
style: PropTypes.object,
|
||
|
resetFileKey: PropTypes.number,
|
||
|
intl: PropTypes.object.isRequired
|
||
|
};
|
||
8 years ago
|
|
||
8 years ago
|
export default injectIntl(UploadButton);
|