Last active
March 12, 2020 04:29
-
-
Save davidgilbertson/61f318cfc2a06128bbc5e36c84cda37c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const {PropTypes} = React; | |
const ModalWrapper = props => { | |
const handleBackgroundClick = e => { | |
if (e.target === e.currentTarget) props.hideModal(); | |
}; | |
const onOk = () => { | |
props.onOk(); | |
props.hideModal(); | |
}; | |
const okButton = props.showOk | |
? ( | |
<button | |
onClick={onOk} | |
disabled={props.okDisabled} | |
> | |
{props.okText} | |
</button> | |
) : null; | |
return ( | |
<div onClick={handleBackgroundClick}> | |
<header> | |
<h1>{props.title}</h1> | |
<button onClick={props.hideModal}>Close</button> | |
</header> | |
{props.children} | |
{okButton} | |
</div> | |
); | |
}; | |
ModalWrapper.propTypes = { | |
// props | |
title: PropTypes.string, | |
showOk: PropTypes.bool, | |
okText: PropTypes.string, | |
okDisabled: PropTypes.bool, | |
width: PropTypes.number, | |
style: PropTypes.object, | |
children: PropTypes.oneOfType([ | |
PropTypes.array, | |
PropTypes.element, | |
PropTypes.string, | |
]).isRequired, | |
// methods | |
hideModal: PropTypes.func, | |
onOk: PropTypes.func, | |
}; | |
ModalWrapper.defaultProps = { | |
title: '', | |
showOk: true, | |
okText: 'OK', | |
okDisabled: false, | |
width: 400, | |
onOk: () => {} | |
}; | |
export default ModalWrapper; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment