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

150 lines
4.0 KiB
React
Raw Normal View History

import React, { PureComponent } 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';
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',
},
newTabLabel: {
id: 'app.modal.newTab',
description: 'aria label used to indicate opening a new window',
},
2019-05-17 06:13:08 +08:00
});
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,
shouldCloseOnOverlayClick: 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: {
2019-06-22 01:39:12 +08:00
callback: () => {},
disabled: false,
2016-09-01 03:52:17 +08:00
},
preventClosing: false,
2016-09-01 03:52:17 +08:00
};
class ModalFullscreen extends PureComponent {
constructor(props) {
super(props);
this.handleAction = this.handleAction.bind(this);
}
handleAction(name) {
const { confirm, dismiss } = this.props;
const { callback: callBackConfirm } = confirm;
const { callback: callBackDismiss } = dismiss;
let callback;
switch (name) {
case 'confirm':
callback = callBackConfirm;
break;
case 'dismiss':
callback = callBackDismiss;
break;
default:
break;
}
return 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,
children,
isOpen,
preventClosing,
...otherProps
2016-09-01 03:52:17 +08:00
} = this.props;
const popoutIcon = confirm.icon === 'popout_window';
let confirmAriaLabel = `${confirm.label || intl.formatMessage(intlMessages.modalDone)} `;
if (popoutIcon) {
confirmAriaLabel = `${confirmAriaLabel} ${intl.formatMessage(intlMessages.newTabLabel)}`;
}
2016-09-01 03:52:17 +08:00
return (
2021-11-11 03:10:35 +08:00
<Styled.FullscreenModal
id="fsmodal"
isOpen={isOpen || preventClosing}
2017-04-19 03:06:51 +08:00
contentLabel={title}
2021-11-11 03:10:35 +08:00
overlayClassName={"fullscreenModalOverlay"}
2017-04-19 03:06:51 +08:00
{...otherProps}
>
2021-11-11 03:10:35 +08:00
<Styled.Header>
<Styled.Title>{title}</Styled.Title>
<Styled.Actions>
<Styled.DismissButton
data-test="modalDismissButton"
2019-05-17 06:13:08 +08:00
label={intl.formatMessage(intlMessages.modalClose)}
aria-label={`${intl.formatMessage(intlMessages.modalClose)} ${title}`}
disabled={dismiss.disabled}
onClick={() => this.handleAction('dismiss')}
aria-describedby="modalDismissDescription"
color="secondary"
/>
2021-11-11 03:10:35 +08:00
<Styled.ConfirmButton
data-test="modalConfirmButton"
color="primary"
label={confirm.label || intl.formatMessage(intlMessages.modalDone)}
aria-label={confirmAriaLabel}
disabled={confirm.disabled}
onClick={() => this.handleAction('confirm')}
aria-describedby="modalConfirmDescription"
icon={confirm.icon || null}
iconRight={popoutIcon}
2021-11-11 03:10:35 +08:00
popout={popoutIcon ? 'popout' : 'simple'}
/>
2021-11-11 03:10:35 +08:00
</Styled.Actions>
</Styled.Header>
<Styled.Content>
{children}
2021-11-11 03:10:35 +08:00
</Styled.Content>
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>
2021-11-11 03:10:35 +08:00
</Styled.FullscreenModal>
2016-09-01 03:52:17 +08:00
);
}
}
2016-09-01 03:52:17 +08:00
ModalFullscreen.propTypes = propTypes;
ModalFullscreen.defaultProps = defaultProps;
export default injectIntl(ModalFullscreen);