2017-06-04 10:40:14 +08:00
|
|
|
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 { withModalState } from '../base/component';
|
|
|
|
import Styled 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
|
|
|
}),
|
2022-11-11 02:09:21 +08:00
|
|
|
headerPosition: PropTypes.string,
|
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,
|
2022-11-09 01:51:36 +08:00
|
|
|
overlayClassName: 'modalOverlay',
|
2022-11-11 02:09:21 +08:00
|
|
|
headerPosition: 'inner',
|
2017-04-05 22:25:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
2019-06-22 01:47:10 +08:00
|
|
|
if (!dismiss || !modalHide) return;
|
2019-06-22 01:39:12 +08:00
|
|
|
modalHide(dismiss.callback);
|
2019-01-15 04:23:46 +08:00
|
|
|
}
|
|
|
|
|
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,
|
2022-11-11 02:09:21 +08:00
|
|
|
headerPosition,
|
2022-03-01 03:46:13 +08:00
|
|
|
'data-test': dataTest,
|
2017-10-11 06:08:51 +08:00
|
|
|
...otherProps
|
2017-04-05 22:25:26 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2021-09-01 04:08:26 +08:00
|
|
|
const closeModal = (onRequestClose || this.handleDismiss);
|
2019-01-15 04:23:46 +08:00
|
|
|
|
2021-09-01 04:08:26 +08:00
|
|
|
const handleRequestClose = (event) => {
|
|
|
|
closeModal();
|
|
|
|
|
|
|
|
if (event) {
|
|
|
|
event.persist();
|
|
|
|
|
|
|
|
if (event.type === 'click') {
|
|
|
|
setTimeout(() => {
|
|
|
|
document.activeElement.blur();
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-11-09 01:51:36 +08:00
|
|
|
|
2017-04-05 22:25:26 +08:00
|
|
|
return (
|
2021-11-11 03:10:35 +08:00
|
|
|
<Styled.SimpleModal
|
2017-04-19 03:06:51 +08:00
|
|
|
isOpen={modalisOpen}
|
2021-11-11 03:10:35 +08:00
|
|
|
className={className}
|
2021-09-01 04:08:26 +08:00
|
|
|
onRequestClose={handleRequestClose}
|
2019-05-24 23:32:31 +08:00
|
|
|
contentLabel={title || contentLabel}
|
2022-03-01 03:46:13 +08:00
|
|
|
data={{
|
2022-11-09 01:51:36 +08:00
|
|
|
test: dataTest ?? null,
|
2022-03-01 03:46:13 +08:00
|
|
|
}}
|
2017-04-19 03:06:51 +08:00
|
|
|
{...otherProps}
|
|
|
|
>
|
2022-11-11 02:09:21 +08:00
|
|
|
<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>
|
2017-04-05 22:25:26 +08:00
|
|
|
{this.props.children}
|
2021-11-11 03:10:35 +08:00
|
|
|
</Styled.Content>
|
|
|
|
</Styled.SimpleModal>
|
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));
|