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.

52 lines
1.8 KiB

  1. import React from 'react';
  2. import ImmutablePropTypes from 'react-immutable-proptypes';
  3. import PropTypes from 'prop-types';
  4. import IconButton from '../../../components/icon_button';
  5. import { defineMessages, injectIntl } from 'react-intl';
  6. import UploadProgressContainer from '../containers/upload_progress_container';
  7. import Motion from 'react-motion/lib/Motion';
  8. import spring from 'react-motion/lib/spring';
  9. const messages = defineMessages({
  10. undo: { id: 'upload_form.undo', defaultMessage: 'Undo' },
  11. });
  12. class UploadForm extends React.PureComponent {
  13. static propTypes = {
  14. media: ImmutablePropTypes.list.isRequired,
  15. onRemoveFile: PropTypes.func.isRequired,
  16. intl: PropTypes.object.isRequired,
  17. };
  18. onRemoveFile = (e) => {
  19. const id = Number(e.currentTarget.parentElement.getAttribute('data-id'));
  20. this.props.onRemoveFile(id);
  21. }
  22. render () {
  23. const { intl, media } = this.props;
  24. const uploads = media.map(attachment =>
  25. <div className='compose-form__upload' key={attachment.get('id')}>
  26. <Motion defaultStyle={{ scale: 0.8 }} style={{ scale: spring(1, { stiffness: 180, damping: 12 }) }}>
  27. {({ scale }) =>
  28. <div className='compose-form__upload-thumbnail' data-id={attachment.get('id')} style={{ transform: `translateZ(0) scale(${scale})`, backgroundImage: `url(${attachment.get('preview_url')})` }}>
  29. <IconButton icon='times' title={intl.formatMessage(messages.undo)} size={36} onClick={this.onRemoveFile} />
  30. </div>
  31. }
  32. </Motion>
  33. </div>
  34. );
  35. return (
  36. <div className='compose-form__upload-wrapper'>
  37. <UploadProgressContainer />
  38. <div className='compose-form__uploads-wrapper'>{uploads}</div>
  39. </div>
  40. );
  41. }
  42. }
  43. export default injectIntl(UploadForm);