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

115 lines
3.3 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import Button from '/imports/ui/components/button/component';
2016-09-01 03:52:17 +08:00
import cx from 'classnames';
2019-05-17 06:13:08 +08:00
import { defineMessages, injectIntl } from 'react-intl';
2017-10-06 20:50:01 +08:00
import ModalBase, { withModalState } from '../base/component';
2018-01-08 14:17:18 +08:00
import { styles } from './styles.scss';
2016-09-01 03:52:17 +08:00
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',
},
modalDone: {
id: 'app.modal.confirm',
description: 'Close',
},
modalDoneDescription: {
id: 'app.modal.confirm.description',
description: 'Disregards changes and closes the modal',
},
});
2016-09-01 03:52:17 +08:00
const propTypes = {
title: PropTypes.string.isRequired,
confirm: PropTypes.shape({
callback: PropTypes.func.isRequired,
disabled: PropTypes.bool,
2016-09-01 03:52:17 +08:00
}),
dismiss: PropTypes.shape({
callback: PropTypes.func,
disabled: PropTypes.bool,
2016-09-01 03:52:17 +08:00
}),
preventClosing: PropTypes.bool,
2016-09-01 03:52:17 +08:00
};
const defaultProps = {
shouldCloseOnOverlayClick: false,
2016-09-01 03:52:17 +08:00
confirm: {
disabled: false,
2016-09-01 03:52:17 +08:00
},
dismiss: {
disabled: false,
2016-09-01 03:52:17 +08:00
},
preventClosing: false,
2016-09-01 03:52:17 +08:00
};
class ModalFullscreen extends PureComponent {
handleAction(name) {
const action = this.props[name];
return this.props.modalHide(action.callback);
2016-09-01 03:52:17 +08:00
}
render() {
const {
2019-05-17 06:13:08 +08:00
intl,
2016-09-01 03:52:17 +08:00
title,
confirm,
2017-04-19 03:06:51 +08:00
dismiss,
className,
modalisOpen,
preventClosing,
...otherProps
2016-09-01 03:52:17 +08:00
} = this.props;
return (
2017-04-19 03:06:51 +08:00
<ModalBase
isOpen={modalisOpen || preventClosing}
2017-04-19 03:06:51 +08:00
className={cx(className, styles.modal)}
contentLabel={title}
{...otherProps}
>
2016-09-01 03:52:17 +08:00
<header className={styles.header}>
<h1 className={styles.title}>{title}</h1>
<div className={styles.actions}>
<Button
data-test="modalDismissButton"
2016-09-01 03:52:17 +08:00
className={styles.dismiss}
2019-05-17 06:13:08 +08:00
label={intl.formatMessage(intlMessages.modalClose)}
aria-label={`${intl.formatMessage(intlMessages.modalClose)} ${title}`}
disabled={dismiss.disabled}
2017-10-11 23:06:29 +08:00
onClick={this.handleAction.bind(this, 'dismiss')}
aria-describedby="modalDismissDescription"
/>
2016-09-01 03:52:17 +08:00
<Button
data-test="modalConfirmButton"
color="primary"
2016-09-01 03:52:17 +08:00
className={styles.confirm}
2019-05-17 06:13:08 +08:00
label={intl.formatMessage(intlMessages.modalDone)}
aria-label={`${intl.formatMessage(intlMessages.modalDone)} ${title}`}
disabled={confirm.disabled}
2017-10-11 23:06:29 +08:00
onClick={this.handleAction.bind(this, 'confirm')}
aria-describedby="modalConfirmDescription"
/>
2016-09-01 03:52:17 +08:00
</div>
</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>
<div id="modalConfirmDescription" hidden>{intl.formatMessage(intlMessages.modalDoneDescription)}</div>
2017-04-19 03:06:51 +08:00
</ModalBase>
2016-09-01 03:52:17 +08:00
);
}
}
2016-09-01 03:52:17 +08:00
ModalFullscreen.propTypes = propTypes;
ModalFullscreen.defaultProps = defaultProps;
2019-05-17 06:13:08 +08:00
export default withModalState(injectIntl(ModalFullscreen));