2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-10-11 06:08:51 +08:00
|
|
|
import cx from 'classnames';
|
2017-04-05 22:25:26 +08:00
|
|
|
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';
|
2017-04-05 22:25:26 +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',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2017-04-05 22:25:26 +08:00
|
|
|
const propTypes = {
|
2018-12-03 14:01:19 +08:00
|
|
|
title: PropTypes.string,
|
2017-04-05 22:25:26 +08:00
|
|
|
dismiss: PropTypes.shape({
|
2019-05-24 23:32:31 +08:00
|
|
|
callback: PropTypes.func,
|
2017-04-05 22:25:26 +08:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
2017-04-19 03:06:51 +08:00
|
|
|
shouldCloseOnOverlayClick: true,
|
2019-02-27 01:40:01 +08:00
|
|
|
shouldShowCloseButton: true,
|
2017-04-05 22:25:26 +08:00
|
|
|
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() {
|
|
|
|
this.props.modalHide(this.props.dismiss.callback);
|
|
|
|
}
|
|
|
|
|
2017-04-05 22:25:26 +08:00
|
|
|
render() {
|
|
|
|
const {
|
2019-05-17 06:13:08 +08:00
|
|
|
intl,
|
2017-04-05 22:25:26 +08:00
|
|
|
title,
|
2018-12-03 14:01:19 +08:00
|
|
|
hideBorder,
|
2017-04-05 22:25:26 +08:00
|
|
|
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,
|
2019-05-09 03:13:05 +08:00
|
|
|
contentLabel,
|
2017-10-11 06:08:51 +08:00
|
|
|
...otherProps
|
2017-04-05 22:25:26 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2019-01-15 04:23:46 +08:00
|
|
|
const closeModel = (onRequestClose || this.handleDismiss);
|
|
|
|
|
2017-04-05 22:25:26 +08:00
|
|
|
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}
|
2019-05-24 23:32:31 +08:00
|
|
|
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}>
|
2017-04-05 22:25:26 +08:00
|
|
|
<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>
|
2017-04-05 22:25:26 +08:00
|
|
|
<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-04-05 22:25:26 +08:00
|
|
|
);
|
|
|
|
}
|
2017-10-11 06:08:51 +08:00
|
|
|
}
|
2017-04-05 22:25:26 +08:00
|
|
|
|
|
|
|
ModalSimple.propTypes = propTypes;
|
|
|
|
ModalSimple.defaultProps = defaultProps;
|
|
|
|
|
2019-05-17 06:13:08 +08:00
|
|
|
export default withModalState(injectIntl(ModalSimple));
|