The code powering m.abunchtell.com https://m.abunchtell.com
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

85 linhas
2.2 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. import MediaModal from './media_modal';
  3. import VideoModal from './video_modal';
  4. import BoostModal from './boost_modal';
  5. import { TransitionMotion, spring } from 'react-motion';
  6. const MODAL_COMPONENTS = {
  7. 'MEDIA': MediaModal,
  8. 'VIDEO': VideoModal,
  9. 'BOOST': BoostModal
  10. };
  11. const ModalRoot = React.createClass({
  12. propTypes: {
  13. type: React.PropTypes.string,
  14. props: React.PropTypes.object,
  15. onClose: React.PropTypes.func.isRequired
  16. },
  17. mixins: [PureRenderMixin],
  18. handleKeyUp (e) {
  19. if (e.key === 'Escape' && !!this.props.type) {
  20. this.props.onClose();
  21. }
  22. },
  23. componentDidMount () {
  24. window.addEventListener('keyup', this.handleKeyUp, false);
  25. },
  26. componentWillUnmount () {
  27. window.removeEventListener('keyup', this.handleKeyUp);
  28. },
  29. willEnter () {
  30. return { opacity: 0, scale: 0.98 };
  31. },
  32. willLeave () {
  33. return { opacity: spring(0), scale: spring(0.98) };
  34. },
  35. render () {
  36. const { type, props, onClose } = this.props;
  37. const items = [];
  38. if (!!type) {
  39. items.push({
  40. key: type,
  41. data: { type, props },
  42. style: { opacity: spring(1), scale: spring(1, { stiffness: 120, damping: 14 }) }
  43. });
  44. }
  45. return (
  46. <TransitionMotion
  47. styles={items}
  48. willEnter={this.willEnter}
  49. willLeave={this.willLeave}>
  50. {interpolatedStyles =>
  51. <div className='modal-root'>
  52. {interpolatedStyles.map(({ key, data: { type, props }, style }) => {
  53. const SpecificComponent = MODAL_COMPONENTS[type];
  54. return (
  55. <div key={key}>
  56. <div role='presentation' className='modal-root__overlay' style={{ opacity: style.opacity, transform: `translateZ(0px)` }} onClick={onClose} />
  57. <div className='modal-root__container' style={{ opacity: style.opacity, transform: `translateZ(0px) scale(${style.scale})` }}>
  58. <SpecificComponent {...props} onClose={onClose} />
  59. </div>
  60. </div>
  61. );
  62. })}
  63. </div>
  64. }
  65. </TransitionMotion>
  66. );
  67. }
  68. });
  69. export default ModalRoot;