闭社主体 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.

60 lines
1.7 KiB

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