2016-05-01 23:20:55 +05:30
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
2016-06-04 01:08:59 +05:30
|
|
|
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
|
|
|
|
|
2016-05-01 23:20:55 +05:30
|
|
|
import styles from './popup.scss';
|
|
|
|
|
|
|
|
export class PopupStack extends Component {
|
|
|
|
static displayName = 'PopupStack';
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
popups: PropTypes.arrayOf(PropTypes.shape({
|
2016-05-11 10:56:44 +05:30
|
|
|
type: PropTypes.func,
|
2016-05-01 23:20:55 +05:30
|
|
|
props: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
|
|
|
|
})),
|
|
|
|
destroy: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2016-05-11 10:56:44 +05:30
|
|
|
const {popups} = this.props;
|
2016-05-01 23:20:55 +05:30
|
|
|
|
|
|
|
return (
|
2016-06-04 01:08:59 +05:30
|
|
|
<ReactCSSTransitionGroup
|
|
|
|
transitionName={{
|
|
|
|
enter: styles.trEnter,
|
2016-06-04 11:31:10 +05:30
|
|
|
enterActive: styles.trEnterActive,
|
|
|
|
leave: styles.trLeave,
|
|
|
|
leaveActive: styles.trLeaveActive
|
2016-06-04 01:08:59 +05:30
|
|
|
}}
|
|
|
|
transitionEnterTimeout={500}
|
|
|
|
transitionLeaveTimeout={500}
|
|
|
|
>
|
2016-05-01 23:20:55 +05:30
|
|
|
{popups.map((popup, index) => {
|
2016-07-26 10:10:45 +05:30
|
|
|
const {Popup} = popup;
|
2016-05-01 23:20:55 +05:30
|
|
|
|
|
|
|
return (
|
2016-07-26 10:10:45 +05:30
|
|
|
<div className={styles.overlay} key={index}
|
|
|
|
onClick={this.onOverlayClick(popup)}
|
|
|
|
>
|
|
|
|
<Popup onClose={this.onClose(popup)} />
|
2016-05-01 23:20:55 +05:30
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
2016-06-04 01:08:59 +05:30
|
|
|
</ReactCSSTransitionGroup>
|
2016-05-01 23:20:55 +05:30
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onClose(popup) {
|
|
|
|
return this.props.destroy.bind(null, popup);
|
|
|
|
}
|
2016-06-03 00:42:20 +05:30
|
|
|
|
2016-07-26 10:10:45 +05:30
|
|
|
onOverlayClick(popup) {
|
2016-06-03 00:42:20 +05:30
|
|
|
return (event) => {
|
2016-07-26 10:10:45 +05:30
|
|
|
if (event.target !== event.currentTarget || popup.disableOverlayClose) {
|
2016-06-03 00:42:20 +05:30
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
this.props.destroy(popup);
|
|
|
|
};
|
|
|
|
}
|
2016-05-01 23:20:55 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { destroy } from 'components/ui/popup/actions';
|
|
|
|
|
|
|
|
export default connect((state) => ({
|
|
|
|
...state.popup
|
|
|
|
}), {
|
|
|
|
destroy
|
|
|
|
})(PopupStack);
|