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.

43 lines
1.5 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import UploadButton from './upload_button';
  4. import IconButton from './icon_button';
  5. const UploadForm = React.createClass({
  6. propTypes: {
  7. media: ImmutablePropTypes.list.isRequired,
  8. is_uploading: React.PropTypes.bool,
  9. onSelectFile: React.PropTypes.func.isRequired,
  10. onRemoveFile: React.PropTypes.func.isRequired
  11. },
  12. mixins: [PureRenderMixin],
  13. render () {
  14. let uploads = this.props.media.map(function (attachment) {
  15. return (
  16. <div key={attachment.get('id')} style={{ borderRadius: '4px', marginBottom: '10px' }} className='transparent-background'>
  17. <div style={{ width: '100%', height: '100px', borderRadius: '4px', background: `url(${attachment.get('preview_url')}) no-repeat center`, backgroundSize: 'cover' }}>
  18. <IconButton icon='times' title='Undo' size={36} onClick={() => this.props.onRemoveFile(attachment.get('id'))} />
  19. </div>
  20. </div>
  21. );
  22. }.bind(this));
  23. const noMoreAllowed = (this.props.media.some(m => m.get('type') === 'video')) || (this.props.media.size > 3);
  24. return (
  25. <div style={{ marginBottom: '20px', padding: '10px', paddingTop: '0' }}>
  26. <UploadButton onSelectFile={this.props.onSelectFile} disabled={this.props.is_uploading || noMoreAllowed } />
  27. <div style={{ marginTop: '10px', overflow: 'hidden' }}>
  28. {uploads}
  29. </div>
  30. </div>
  31. );
  32. }
  33. });
  34. export default UploadForm;