I am trying to create a custom Modal in react. Followed most of tutorials I found and my Modal just never shows up. On the other hand react-modal did work, but I was having trouble styling it. Nevertheless my custom Modal should work, though it doesn't give any sings of life when I click on the icon.
My header:
function Header () {
const [isOpen, setIsOpen] = useState(false)
return(
<>
<header className="header">
<div className="wrap">
<span className="btn-icon">
<IconPlus onClick={() => setIsOpen(true)} className="icon icon-plus js-modal-init"/>
</span>
</div>
<div className="header-inner">
<div className="wrap">
<img className="logo" src="images/pic.svg" alt="Pic"/>
<div className="date-wrap">
<IconCalendar className="icon icon-plus js-modal-init"/>
<time>02 / 08 / 2019</time>
</div>
</div>
</div>
</header>
<ModalWindow open={isOpen} onClose={() => setIsOpen(false)} />
</>
)
}
ModalWindow:
export const ModalWindow = ({open, onClose}) => {
if(!open) return null
return(
<div className="modal-wrap js-modal">
<div className="modal js-modal-inner">
<h2>Create a task:</h2>
<form action="">
<div className="field-wrap">
<label className="label" for="">Title:</label>
<input className="field" type="text" id="" placeholder="Enter title here..."/>
</div>
<div className="field-wrap">
<label className="label" for="">Hours:</label>
<input className="field" type="text" id="" placeholder="Add hours here..."/>
</div>
<div className="btn-wrap align-right">
<input onClick={onClose} className="btn" type="submit" value="Create"/>
</div>
</form>
</div>
</div>
)
}
css:
.modal-wrap {
display: flex;
visibility: visible;
position: fixed;
z-index: 1;
top: 0;
left: 0;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
transition: 350ms ease-in-out;
opacity: 0;
background-color: rgba(0, 0, 0, 0.7);
}
.modal {
position: relative;
width: 100%;
max-width: 700px;
padding: 50px 40px;
background-color: #fff;
box-shadow: 2px 2px 15px rgba(0, 0, 0, 0.2);
}
.modal h2 {
margin-top: 0;
margin-bottom: 1em;
color: #666;
font-size: 30px;
font-weight: 300;
}
.modal-wrap.is-visible {
visibility: visible;
opacity: 1;
}