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.6 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import Motion from 'flavours/glitch/util/optional_motion';
  4. import spring from 'react-motion/lib/spring';
  5. import { FormattedMessage } from 'react-intl';
  6. export default class UploadArea extends React.PureComponent {
  7. static propTypes = {
  8. active: PropTypes.bool,
  9. onClose: PropTypes.func,
  10. };
  11. handleKeyUp = (e) => {
  12. const keyCode = e.keyCode;
  13. if (this.props.active) {
  14. switch(keyCode) {
  15. case 27:
  16. e.preventDefault();
  17. e.stopPropagation();
  18. this.props.onClose();
  19. break;
  20. }
  21. }
  22. }
  23. componentDidMount () {
  24. window.addEventListener('keyup', this.handleKeyUp, false);
  25. }
  26. componentWillUnmount () {
  27. window.removeEventListener('keyup', this.handleKeyUp);
  28. }
  29. render () {
  30. const { active } = this.props;
  31. return (
  32. <Motion defaultStyle={{ backgroundOpacity: 0, backgroundScale: 0.95 }} style={{ backgroundOpacity: spring(active ? 1 : 0, { stiffness: 150, damping: 15 }), backgroundScale: spring(active ? 1 : 0.95, { stiffness: 200, damping: 3 }) }}>
  33. {({ backgroundOpacity, backgroundScale }) =>
  34. (<div className='upload-area' style={{ visibility: active ? 'visible' : 'hidden', opacity: backgroundOpacity }}>
  35. <div className='upload-area__drop'>
  36. <div className='upload-area__background' style={{ transform: `scale(${backgroundScale})` }} />
  37. <div className='upload-area__content'><FormattedMessage id='upload_area.title' defaultMessage='Drag & drop to upload' /></div>
  38. </div>
  39. </div>)
  40. }
  41. </Motion>
  42. );
  43. }
  44. }