Skip to content

Instantly share code, notes, and snippets.

@peterxjang
Created July 16, 2022 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterxjang/7b35f0eadd15354b38bb96ca7bea0ba4 to your computer and use it in GitHub Desktop.
Save peterxjang/7b35f0eadd15354b38bb96ca7bea0ba4 to your computer and use it in GitHub Desktop.
Simple React modal
.modal {
display: block;
position: fixed;
top: 0;
left: 0;
width:100%;
height: 100%;
background: rgba(0, 0, 0, 0.6);
}
.modal-main {
position:fixed;
background: white;
width: 80%;
height: auto;
top:50%;
left:50%;
transform: translate(-50%,-50%);
padding: 1em;
}
import "./Modal.css";
const Modal = (props) => {
if (props.show) {
return (
<div className="modal">
<section className="modal-main">
{props.children}
<button type="button" onClick={props.handleClose}>
Close
</button>
</section>
</div>
);
}
};
export default Modal;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment