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.

45 lines
1.6 KiB

  1. import ImmutablePropTypes from 'react-immutable-proptypes';
  2. import PropTypes from 'prop-types';
  3. import IconButton from '../../../components/icon_button';
  4. import { defineMessages, injectIntl } from 'react-intl';
  5. import UploadProgressContainer from '../containers/upload_progress_container';
  6. import { Motion, spring } from 'react-motion';
  7. const messages = defineMessages({
  8. undo: { id: 'upload_form.undo', defaultMessage: 'Undo' }
  9. });
  10. class UploadForm extends React.PureComponent {
  11. render () {
  12. const { intl, media } = this.props;
  13. const uploads = media.map(attachment =>
  14. <div key={attachment.get('id')} style={{ margin: '5px', flex: '1 1 0' }}>
  15. <Motion defaultStyle={{ scale: 0.8 }} style={{ scale: spring(1, { stiffness: 180, damping: 12 }) }}>
  16. {({ scale }) =>
  17. <div style={{ transform: `translateZ(0) scale(${scale})`, width: '100%', height: '100px', borderRadius: '4px', background: `url(${attachment.get('preview_url')}) no-repeat center`, backgroundSize: 'cover' }}>
  18. <IconButton icon='times' title={intl.formatMessage(messages.undo)} size={36} onClick={this.props.onRemoveFile.bind(this, attachment.get('id'))} />
  19. </div>
  20. }
  21. </Motion>
  22. </div>
  23. );
  24. return (
  25. <div style={{ overflow: 'hidden' }}>
  26. <UploadProgressContainer />
  27. <div style={{ display: 'flex', padding: '5px' }}>{uploads}</div>
  28. </div>
  29. );
  30. }
  31. }
  32. UploadForm.propTypes = {
  33. media: ImmutablePropTypes.list.isRequired,
  34. onRemoveFile: PropTypes.func.isRequired,
  35. intl: PropTypes.object.isRequired
  36. };
  37. export default injectIntl(UploadForm);