Skip to content

Instantly share code, notes, and snippets.

@dsternlicht
Last active November 27, 2018 14:58
Show Gist options
  • Save dsternlicht/7c8a1495535c4e910ce4cb222e2a7325 to your computer and use it in GitHub Desktop.
Save dsternlicht/7c8a1495535c4e910ce4cb222e2a7325 to your computer and use it in GitHub Desktop.
React Modal component
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