Abstracted out <LoadingModal/>

This commit is contained in:
orangemug 2018-06-18 19:06:16 +01:00
parent 558f3d649d
commit afbdaecd0a
3 changed files with 63 additions and 15 deletions

View file

@ -0,0 +1,49 @@
import React from 'react'
import PropTypes from 'prop-types'
import Button from '../Button'
import Modal from './Modal'
class LoadingModal extends React.Component {
static propTypes = {
isOpen: PropTypes.bool.isRequired,
onCancel: PropTypes.func.isRequired,
title: PropTypes.string.isRequired,
message: PropTypes.node.isRequired,
}
constructor(props) {
super(props);
}
underlayOnClick(e) {
// This stops click events falling through to underlying modals.
e.stopPropagation();
}
render() {
return <Modal
data-wd-key="loading-modal"
isOpen={this.props.isOpen}
underlayClickExits={false}
underlayProps={{
onClick: (e) => underlayProps(e)
}}
closeable={false}
title={this.props.title}
onOpenToggle={() => this.props.onCancel()}
>
<p>
{this.props.message}
</p>
<p className="maputnik-dialog__buttons">
<Button onClick={(e) => this.props.onCancel(e)}>
Cancel
</Button>
</p>
</Modal>
}
}
export default LoadingModal

View file

@ -11,6 +11,12 @@ class Modal extends React.Component {
title: PropTypes.string.isRequired,
onOpenToggle: PropTypes.func.isRequired,
children: PropTypes.node,
underlayClickExits: PropTypes.bool,
underlayProps: PropTypes.object,
}
static defaultProps = {
underlayClickExits: true
}
getApplicationNode() {
@ -21,6 +27,8 @@ class Modal extends React.Component {
if(this.props.isOpen) {
return <AriaModal
titleText={this.props.title}
underlayClickExits={this.props.underlayClickExits}
underlayProps={this.props.underlayProps}
getApplicationNode={this.getApplicationNode}
data-wd-key={this.props["data-wd-key"]}
verticallyCenter={true}

View file

@ -1,5 +1,6 @@
import React from 'react'
import PropTypes from 'prop-types'
import LoadingModal from './LoadingModal'
import Modal from './Modal'
import Button from '../Button'
import FileReaderInput from 'react-file-reader-input'
@ -195,22 +196,12 @@ class OpenModal extends React.Component {
</div>
</section>
<Modal
data-wd-key="loading-modal"
isOpen={this.state.activeRequest}
closeable={false}
<LoadingModal
isOpen={!!this.state.activeRequest}
title={'Loading style'}
onOpenToggle={() => this.onCancelActiveRequest()}
>
<p>
Loading: {this.state.activeRequestUrl}
</p>
<p className="maputnik-dialog__buttons">
<Button onClick={(e) => this.onCancelActiveRequest(e)}>
Cancel
</Button>
</p>
</Modal>
onCancel={(e) => this.onCancelActiveRequest(e)}
message={"Loading: "+this.state.activeRequestUrl}
/>
</Modal>
}
}