2016-05-01 23:20:55 +05:30
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
|
|
|
|
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 (
|
|
|
|
<div>
|
|
|
|
{popups.map((popup, index) => {
|
2016-05-11 10:56:44 +05:30
|
|
|
const Popup = popup.type;
|
2016-05-01 23:20:55 +05:30
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
onClose: this.onClose(popup)
|
|
|
|
};
|
|
|
|
const props = typeof popup.props === 'function'
|
|
|
|
? popup.props(defaultProps)
|
|
|
|
: {...defaultProps, ...popup.props};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.overlay} key={popup.type + index}>
|
|
|
|
<div className={styles.popup}>
|
|
|
|
<Popup {...props} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
onClose(popup) {
|
|
|
|
return this.props.destroy.bind(null, popup);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { destroy } from 'components/ui/popup/actions';
|
|
|
|
|
|
|
|
export default connect((state) => ({
|
|
|
|
...state.popup
|
|
|
|
}), {
|
|
|
|
destroy
|
|
|
|
})(PopupStack);
|