2016-09-01 03:52:17 +08:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
|
|
|
import ReactModal from 'react-modal';
|
|
|
|
import styles from './styles.scss';
|
|
|
|
import cx from 'classnames';
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
isOpen: PropTypes.bool.isRequired,
|
|
|
|
onShow: PropTypes.func,
|
|
|
|
onHide: PropTypes.func,
|
2017-01-27 05:00:24 +08:00
|
|
|
isTransparent: PropTypes.bool
|
2016-09-01 03:52:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
isOpen: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class ModalBase extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.handleAfterOpen = this.handleAfterOpen.bind(this);
|
|
|
|
this.handleRequestClose = this.handleRequestClose.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleAfterOpen() {
|
|
|
|
const { onShow } = this.props;
|
|
|
|
if (onShow) {
|
|
|
|
onShow.call(this, ...arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRequestClose() {
|
|
|
|
const { onHide } = this.props;
|
|
|
|
if (onHide) {
|
|
|
|
onHide.call(this, ...arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
isOpen,
|
|
|
|
onShow,
|
|
|
|
onHide,
|
|
|
|
className,
|
2017-01-27 05:00:24 +08:00
|
|
|
isTransparent,
|
2016-09-01 03:52:17 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2017-01-27 22:32:54 +08:00
|
|
|
let styleOverlay = (isTransparent) ? styles.audioOverlay : styles.overlay;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ReactModal
|
|
|
|
className={cx(styles.modal, className)}
|
|
|
|
overlayClassName={styleOverlay}
|
|
|
|
portalClassName={styles.portal}
|
|
|
|
isOpen={isOpen}
|
|
|
|
onAfterOpen={this.handleAfterOpen}
|
|
|
|
onRequestClose={this.handleRequestClose}>
|
|
|
|
{this.props.children}
|
|
|
|
</ReactModal>
|
|
|
|
);
|
2016-09-01 03:52:17 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ModalBase.propTypes = propTypes;
|
|
|
|
ModalBase.defaultProps = defaultProps;
|