<div id="app"></div>
.modal__container {
  height: 100vh;
  width: 100vw;
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal__wrapper {
  display: flex;
  justify-content: center;
  max-width: 200px;
}

.modal__content {
  background: lightgrey;
  border: 1px solid black;
  display: flex;
  flex-flow: column;
  height: 100%;
  padding: 5px;
  margin-bottom: 5px;
}

h4 {
  text-align: center;
}

button {
  width: max-content;
  margin: auto;
}
/*
* https://frontendeval.com/questions/modal-overlay
*
* Build a modal control and overlay
*/

const Modal = () => {
  const [show, setShow] = React.useState(false);
  const [accepted, setAccepted] = React.useState(false);
  
  handleClick = () => {
    setShow(show => !show);
  }
  
  handleOutsideClick = (e ) => {
    if (show && e.target.className === 'modal__container') { setShow(false); }
  }
  
  handleAccepted = () => {
    setShow(false);
    setAccepted(true);
  }
  
  return (
    <div className='modal__container' onClick={ handleOutsideClick }>
      <div className='modal__wrapper'>
        { (!show && !accepted) && <button onClick={ handleClick }>Show Offer</button> }
        { show && (
          <div className='modal__content'>
            <div className='modal__content__header'>
              <button onClick={ handleClick }>X</button>
            </div>
            <h4>Click the button below to accept our amazing offer!</h4>
            <button onClick={ handleAccepted }>Accept Offer</button>
          </div>
        )}
        { accepted && <h4>Offer accepted</h4>}
      </div>
    </div>
  )
}

const App = () => {
  return <Modal />
}

ReactDOM.render(<App />, document.getElementById('app'));
View Compiled
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js
  2. https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.1/umd/react-dom.production.min.js