2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
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';
|
2017-10-06 20:50:01 +08:00
|
|
|
import ModalBase, { withModalState } from '../base/component';
|
|
|
|
import styles from './styles.scss';
|
2016-09-01 03:52:17 +08:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
title: PropTypes.string.isRequired,
|
|
|
|
confirm: PropTypes.shape({
|
|
|
|
callback: PropTypes.func.isRequired,
|
|
|
|
label: PropTypes.string.isRequired,
|
|
|
|
description: PropTypes.string,
|
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,
|
|
|
|
label: PropTypes.string.isRequired,
|
|
|
|
description: PropTypes.string,
|
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,
|
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: {
|
|
|
|
label: 'Done',
|
|
|
|
description: 'Saves changes and closes the modal',
|
2017-10-02 22:12:58 +08:00
|
|
|
disabled: false,
|
2016-09-01 03:52:17 +08:00
|
|
|
},
|
|
|
|
dismiss: {
|
|
|
|
label: 'Cancel',
|
|
|
|
description: 'Disregards changes and closes the modal',
|
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
|
|
|
};
|
|
|
|
|
2017-04-05 22:25:26 +08:00
|
|
|
class ModalFullscreen extends Component {
|
|
|
|
handleAction(name) {
|
|
|
|
const action = this.props[name];
|
2017-10-02 22:12:58 +08:00
|
|
|
return this.props.modalHide(action.callback);
|
2016-09-01 03:52:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
title,
|
|
|
|
confirm,
|
2017-04-19 03:06:51 +08:00
|
|
|
dismiss,
|
|
|
|
className,
|
|
|
|
modalisOpen,
|
2017-10-02 22:12:58 +08:00
|
|
|
preventClosing,
|
|
|
|
...otherProps
|
2016-09-01 03:52:17 +08:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
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
|
|
|
|
className={styles.dismiss}
|
|
|
|
label={dismiss.label}
|
2017-10-02 22:12:58 +08:00
|
|
|
disabled={dismiss.disabled}
|
2017-10-11 23:06:29 +08:00
|
|
|
onClick={this.handleAction.bind(this, 'dismiss')}
|
2017-10-02 22:12:58 +08:00
|
|
|
aria-describedby={'modalDismissDescription'}
|
|
|
|
/>
|
2016-09-01 03:52:17 +08:00
|
|
|
<Button
|
|
|
|
color={'primary'}
|
|
|
|
className={styles.confirm}
|
|
|
|
label={confirm.label}
|
2017-10-02 22:12:58 +08:00
|
|
|
disabled={confirm.disabled}
|
2017-10-11 23:06:29 +08:00
|
|
|
onClick={this.handleAction.bind(this, 'confirm')}
|
2017-10-02 22:12:58 +08:00
|
|
|
aria-describedby={'modalConfirmDescription'}
|
|
|
|
/>
|
2016-09-01 03:52:17 +08:00
|
|
|
</div>
|
|
|
|
</header>
|
|
|
|
<div className={styles.content}>
|
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
<div id="modalDismissDescription" hidden>{dismiss.description}</div>
|
|
|
|
<div id="modalConfirmDescription" hidden>{confirm.description}</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;
|
|
|
|
|
2017-04-19 03:06:51 +08:00
|
|
|
export default withModalState(ModalFullscreen);
|