Last active
November 27, 2018 14:58
-
-
Save dsternlicht/7c8a1495535c4e910ce4cb222e2a7325 to your computer and use it in GitHub Desktop.
React Modal component
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'; | |
import PropTypes from 'prop-types'; | |
import './modal.css'; | |
const Modal = ({ children, customClass, show, closeCallback }) => ( | |
<div className={`modal ${customClass}`} style={{ display: show ? 'block' : 'none'}}> | |
<div className="overlay" onClick={closeCallback}></div> | |
<div className="modal_content"> | |
{children} | |
<button title="Close" className="close_modal" onClick={closeCallback}> | |
<i className="fas fa-times"></i> | |
</button> | |
</div> | |
</div> | |
); | |
Modal.propTypes = { | |
children: PropTypes.element, | |
customClass: PropTypes.string, | |
show: PropTypes.bool, | |
closeCallback: PropTypes.func, | |
}; | |
Modal.defaultProps = { | |
children: <div>Empty Modal</div>, | |
customClass: '', | |
show: false, | |
closeCallback: () => (false) | |
}; | |
export default Modal; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment