]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/features/ui/components/modal_root.js
1 import React
from 'react';
2 import PropTypes
from 'prop-types';
3 import MediaModal
from './media_modal';
4 import OnboardingModal
from './onboarding_modal';
5 import VideoModal
from './video_modal';
6 import BoostModal
from './boost_modal';
7 import ConfirmationModal
from './confirmation_modal';
8 import TransitionMotion
from 'react-motion/lib/TransitionMotion';
9 import spring
from 'react-motion/lib/spring';
11 const MODAL_COMPONENTS
= {
13 'ONBOARDING': OnboardingModal
,
16 'CONFIRM': ConfirmationModal
,
19 class ModalRoot
extends React
.PureComponent
{
22 type: PropTypes
.string
,
23 props: PropTypes
.object
,
24 onClose: PropTypes
.func
.isRequired
,
27 handleKeyUp
= (e
) => {
28 if ((e
.key
=== 'Escape' || e
.key
=== 'Esc' || e
.keyCode
=== 27)
29 && !!this.props
.type
) {
34 componentDidMount () {
35 window
.addEventListener('keyup', this.handleKeyUp
, false);
38 componentWillUnmount () {
39 window
.removeEventListener('keyup', this.handleKeyUp
);
43 return { opacity: 0, scale: 0.98 };
47 return { opacity: spring(0), scale: spring(0.98) };
51 const { type
, props
, onClose
} = this.props
;
52 const visible
= !!type
;
58 data: { type
, props
},
59 style: { opacity: spring(1), scale: spring(1, { stiffness: 120, damping: 14 }) },
66 willEnter
={this.willEnter
}
67 willLeave
={this.willLeave
}>
68 {interpolatedStyles
=>
69 <div className
='modal-root'>
70 {interpolatedStyles
.map(({ key
, data: { type
, props
}, style
}) => {
71 const SpecificComponent
= MODAL_COMPONENTS
[type
];
74 <div key
={key
} style
={{ pointerEvents: visible
? 'auto' : 'none' }}>
75 <div role
='presentation' className
='modal-root__overlay' style
={{ opacity: style
.opacity
}} onClick
={onClose
} />
76 <div className
='modal-root__container' style
={{ opacity: style
.opacity
, transform: `translateZ(0px) scale(${style.scale})` }}>
77 <SpecificComponent
{...props
} onClose
={onClose
} />
90 export default ModalRoot
;
This page took 0.088448 seconds and 4 git commands to generate.