2019-03-19 20:58:21 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-06-04 10:40:14 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2017-04-05 22:25:26 +08:00
|
|
|
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',
|
|
|
|
},
|
2019-05-24 23:32:31 +08:00
|
|
|
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,
|
2017-10-02 22:12:58 +08:00
|
|
|
disabled: PropTypes.bool,
|
2016-09-01 03:52:17 +08:00
|
|
|
}),
|
|
|
|
dismiss: PropTypes.shape({
|
|
|
|
callback: PropTypes.func,
|
2017-10-02 22:12:58 +08:00
|
|
|
disabled: PropTypes.bool,
|
2016-09-01 03:52:17 +08:00
|
|
|
}),
|
2017-10-02 22:12:58 +08:00
|
|
|
preventClosing: PropTypes.bool,
|
2019-05-25 03:51:50 +08:00
|
|
|
shouldCloseOnOverlayClick: PropTypes.bool,
|
2016-09-01 03:52:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
2017-04-05 22:25:26 +08:00
|
|
|
shouldCloseOnOverlayClick: false,
|
2016-09-01 03:52:17 +08:00
|
|
|
confirm: {
|
2017-10-02 22:12:58 +08:00
|
|
|
disabled: false,
|
2016-09-01 03:52:17 +08:00
|
|
|
},
|
|
|
|
dismiss: {
|
2019-06-22 01:39:12 +08:00
|
|
|
callback: () => {},
|
2017-10-02 22:12:58 +08:00
|
|
|
disabled: false,
|
2016-09-01 03:52:17 +08:00
|
|
|
},
|
2017-10-02 22:12:58 +08:00
|
|
|
preventClosing: false,
|
2016-09-01 03:52:17 +08:00
|
|
|
};
|
|
|
|
|
2019-03-19 20:58:21 +08:00
|
|
|
class ModalFullscreen extends PureComponent {
|
2019-05-25 03:51:50 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.handleAction = this.handleAction.bind(this);
|
|
|
|
}
|
|
|
|
|
2017-04-05 22:25:26 +08:00
|
|
|
handleAction(name) {
|
2019-05-25 03:51:50 +08:00
|
|
|
const { confirm, dismiss, modalHide } = 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 modalHide(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,
|
2019-05-25 03:51:50 +08:00
|
|
|
children,
|
2017-04-19 03:06:51 +08:00
|
|
|
modalisOpen,
|
2017-10-02 22:12:58 +08:00
|
|
|
preventClosing,
|
|
|
|
...otherProps
|
2016-09-01 03:52:17 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2019-05-24 23:32:31 +08:00
|
|
|
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 (
|
2017-04-19 03:06:51 +08:00
|
|
|
<ModalBase
|
2017-10-02 22:12:58 +08:00
|
|
|
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
|
2019-05-09 03:13:05 +08:00
|
|
|
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}`}
|
2017-10-02 22:12:58 +08:00
|
|
|
disabled={dismiss.disabled}
|
2019-05-25 03:51:50 +08:00
|
|
|
onClick={() => this.handleAction('dismiss')}
|
2019-05-09 03:13:05 +08:00
|
|
|
aria-describedby="modalDismissDescription"
|
2017-10-02 22:12:58 +08:00
|
|
|
/>
|
2016-09-01 03:52:17 +08:00
|
|
|
<Button
|
2019-05-09 03:13:05 +08:00
|
|
|
data-test="modalConfirmButton"
|
|
|
|
color="primary"
|
2019-05-24 23:32:31 +08:00
|
|
|
className={popoutIcon ? cx(styles.confirm, styles.popout) : styles.confirm}
|
2019-05-25 03:51:50 +08:00
|
|
|
label={confirm.label || intl.formatMessage(intlMessages.modalDone)}
|
2019-05-24 23:32:31 +08:00
|
|
|
aria-label={confirmAriaLabel}
|
2017-10-02 22:12:58 +08:00
|
|
|
disabled={confirm.disabled}
|
2019-05-25 03:51:50 +08:00
|
|
|
onClick={() => this.handleAction('confirm')}
|
2019-05-09 03:13:05 +08:00
|
|
|
aria-describedby="modalConfirmDescription"
|
2019-05-24 23:32:31 +08:00
|
|
|
icon={confirm.icon || null}
|
|
|
|
iconRight={popoutIcon}
|
2017-10-02 22:12:58 +08:00
|
|
|
/>
|
2016-09-01 03:52:17 +08:00
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
<div className={styles.content}>
|
2019-05-25 03:51:50 +08:00
|
|
|
{children}
|
2016-09-01 03:52:17 +08:00
|
|
|
</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
|
|
|
);
|
|
|
|
}
|
2017-10-02 22:12:58 +08:00
|
|
|
}
|
2016-09-01 03:52:17 +08:00
|
|
|
|
2017-04-05 22:25:26 +08:00
|
|
|
ModalFullscreen.propTypes = propTypes;
|
|
|
|
ModalFullscreen.defaultProps = defaultProps;
|
|
|
|
|
2019-05-17 06:13:08 +08:00
|
|
|
export default withModalState(injectIntl(ModalFullscreen));
|