bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/modal/base/component.jsx

68 lines
1.5 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
2016-09-01 03:52:17 +08:00
import ReactModal from 'react-modal';
2018-01-08 14:17:18 +08:00
import { styles } from './styles.scss';
2016-09-01 03:52:17 +08:00
const propTypes = {
overlayClassName: PropTypes.string.isRequired,
portalClassName: PropTypes.string.isRequired,
contentLabel: PropTypes.string.isRequired,
2016-09-01 03:52:17 +08:00
isOpen: PropTypes.bool.isRequired,
};
const defaultProps = {
2017-04-19 03:06:51 +08:00
className: styles.modal,
overlayClassName: styles.overlay,
portalClassName: styles.portal,
contentLabel: 'Modal',
2017-04-19 03:06:51 +08:00
isOpen: true,
2016-09-01 03:52:17 +08:00
};
export default class ModalBase extends Component {
render() {
if (!this.props.isOpen) return null;
2017-01-27 22:32:54 +08:00
return (
2017-04-19 03:06:51 +08:00
<ReactModal {...this.props}>
2017-01-27 22:32:54 +08:00
{this.props.children}
</ReactModal>
);
2016-09-01 03:52:17 +08:00
}
2017-06-03 03:25:02 +08:00
}
2016-09-01 03:52:17 +08:00
ModalBase.propTypes = propTypes;
ModalBase.defaultProps = defaultProps;
2017-06-03 03:25:02 +08:00
export const withModalState = ComponentToWrap =>
class ModalStateWrapper extends Component {
constructor(props) {
super(props);
this.state = {
2017-04-19 03:06:51 +08:00
isOpen: true,
};
this.hide = this.hide.bind(this);
2017-04-19 03:06:51 +08:00
this.show = this.show.bind(this);
}
hide(cb = () => {}) {
Promise.resolve(cb())
.then(() => this.setState({ isOpen: false }));
}
show(cb = () => {}) {
Promise.resolve(cb())
.then(() => this.setState({ isOpen: true }));
}
render() {
2017-06-03 03:25:02 +08:00
return (<ComponentToWrap
2017-04-19 03:06:51 +08:00
{...this.props}
modalHide={this.hide}
modalShow={this.show}
modalisOpen={this.state.isOpen}
2017-06-03 03:25:02 +08:00
/>);
}
};