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

100 lines
2.6 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
2017-10-11 06:08:51 +08:00
import cx from 'classnames';
import Button from '/imports/ui/components/button/component';
2019-05-17 06:13:08 +08:00
import { defineMessages, injectIntl } from 'react-intl';
2017-10-11 06:08:51 +08:00
import ModalBase, { withModalState } from '../base/component';
2018-01-08 14:17:18 +08:00
import { styles } from './styles';
2019-05-17 06:13:08 +08:00
const intlMessages = defineMessages({
modalClose: {
id: 'app.modal.close',
description: 'Close',
},
modalCloseDescription: {
id: 'app.modal.close.description',
description: 'Disregards changes and closes the modal',
},
});
const propTypes = {
title: PropTypes.string,
dismiss: PropTypes.shape({
callback: PropTypes.func,
}),
};
const defaultProps = {
2017-04-19 03:06:51 +08:00
shouldCloseOnOverlayClick: true,
2019-02-27 01:40:01 +08:00
shouldShowCloseButton: true,
overlayClassName: styles.overlay,
};
class ModalSimple extends Component {
2019-01-15 04:23:46 +08:00
constructor(props) {
super(props);
this.handleDismiss = this.handleDismiss.bind(this);
}
handleDismiss() {
2019-06-22 01:39:12 +08:00
const {
modalHide,
dismiss,
} = this.props;
if (!dismiss || !modalHide) return;
2019-06-22 01:39:12 +08:00
modalHide(dismiss.callback);
2019-01-15 04:23:46 +08:00
}
render() {
const {
2019-05-17 06:13:08 +08:00
intl,
title,
hideBorder,
dismiss,
2017-04-19 03:06:51 +08:00
className,
modalisOpen,
2019-01-11 06:58:42 +08:00
onRequestClose,
2019-02-27 01:40:01 +08:00
shouldShowCloseButton,
contentLabel,
2017-10-11 06:08:51 +08:00
...otherProps
} = this.props;
2019-01-15 04:23:46 +08:00
const closeModel = (onRequestClose || this.handleDismiss);
return (
2017-04-19 03:06:51 +08:00
<ModalBase
isOpen={modalisOpen}
className={cx(className, styles.modal)}
2019-01-15 04:23:46 +08:00
onRequestClose={closeModel}
contentLabel={title || contentLabel}
2017-04-19 03:06:51 +08:00
{...otherProps}
>
2018-12-22 02:53:21 +08:00
<header className={hideBorder ? styles.headerNoBorder : styles.header}>
<h1 className={styles.title}>{title}</h1>
2019-02-27 01:40:01 +08:00
{shouldShowCloseButton ? (
<Button
className={styles.dismiss}
2019-05-17 06:13:08 +08:00
label={intl.formatMessage(intlMessages.modalClose)}
aria-label={`${intl.formatMessage(intlMessages.modalClose)} ${title || contentLabel}`}
2019-02-27 01:40:01 +08:00
icon="close"
circle
hideLabel
onClick={closeModel}
aria-describedby="modalDismissDescription"
/>
) : null}
2018-12-22 02:53:21 +08:00
</header>
<div className={styles.content}>
{this.props.children}
</div>
2019-05-17 06:13:08 +08:00
<div id="modalDismissDescription" hidden>{intl.formatMessage(intlMessages.modalCloseDescription)}</div>
2017-04-19 03:06:51 +08:00
</ModalBase>
);
}
2017-10-11 06:08:51 +08:00
}
ModalSimple.propTypes = propTypes;
ModalSimple.defaultProps = defaultProps;
2019-05-17 06:13:08 +08:00
export default withModalState(injectIntl(ModalSimple));