Created
July 16, 2022 17:28
-
-
Save peterxjang/7b35f0eadd15354b38bb96ca7bea0ba4 to your computer and use it in GitHub Desktop.
Simple React modal
This file contains 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
.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; | |
} |
This file contains 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 "./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