闭社主体 forked from https://github.com/tootsuite/mastodon
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.

55 lines
1.6 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import Motion from 'react-motion/lib/Motion';
  4. import spring from 'react-motion/lib/spring';
  5. import { FormattedMessage } from 'react-intl';
  6. class UploadArea extends React.PureComponent {
  7. static propTypes = {
  8. active: PropTypes.bool,
  9. onClose: PropTypes.func,
  10. };
  11. handleKeyUp = (e) => {
  12. e.preventDefault();
  13. e.stopPropagation();
  14. const keyCode = e.keyCode;
  15. if (this.props.active) {
  16. switch(keyCode) {
  17. case 27:
  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: `translateZ(0) 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. }
  45. export default UploadArea;