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

115 lines
2.6 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
2019-05-17 06:13:08 +08:00
import { defineMessages, injectIntl } from 'react-intl';
2021-11-11 03:10:35 +08:00
import Styled 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,
}),
headerPosition: PropTypes.string,
};
const defaultProps = {
2017-04-19 03:06:51 +08:00
shouldCloseOnOverlayClick: true,
2019-02-27 01:40:01 +08:00
shouldShowCloseButton: true,
overlayClassName: 'modalOverlay',
headerPosition: 'inner',
};
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 {
2022-11-24 22:53:30 +08:00
id,
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,
headerPosition,
'data-test': dataTest,
2017-10-11 06:08:51 +08:00
...otherProps
} = this.props;
const closeModal = (onRequestClose || this.handleDismiss);
2019-01-15 04:23:46 +08:00
const handleRequestClose = (event) => {
closeModal();
if (event) {
event.persist();
if (event.type === 'click') {
setTimeout(() => {
document.activeElement.blur();
}, 0);
}
}
}
return (
2021-11-11 03:10:35 +08:00
<Styled.SimpleModal
2022-11-24 22:53:30 +08:00
id="simpleModal"
2017-04-19 03:06:51 +08:00
isOpen={modalisOpen}
2021-11-11 03:10:35 +08:00
className={className}
onRequestClose={handleRequestClose}
contentLabel={title || contentLabel}
dataTest={dataTest}
2017-04-19 03:06:51 +08:00
{...otherProps}
>
<Styled.Header
hideBorder={hideBorder}
headerPosition={headerPosition}
shouldShowCloseButton={shouldShowCloseButton}
modalDismissDescription={intl.formatMessage(intlMessages.modalCloseDescription)}
closeButtonProps={{
label: intl.formatMessage(intlMessages.modalClose),
'aria-label': `${intl.formatMessage(intlMessages.modalClose)} ${title || contentLabel}`,
onClick: handleRequestClose,
}}
>
{title}
</Styled.Header>
2021-11-11 03:10:35 +08:00
<Styled.Content>
{this.props.children}
2021-11-11 03:10:35 +08:00
</Styled.Content>
</Styled.SimpleModal>
);
}
2017-10-11 06:08:51 +08:00
}
ModalSimple.propTypes = propTypes;
ModalSimple.defaultProps = defaultProps;
export default injectIntl(ModalSimple);