<div id="root"></div>
.container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  position: relative;
}

button {
  margin: 10px;
  width: 200px;
  height: 70px;
  border-radius: 10px;
  border: none;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  color: white;
  background-color: blueviolet;
}

.modal {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  z-index: 2;
}

.modal-content {
  text-align: center;
  width: 500px;
  height: 400px;
  background-color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  border-radius: 10px;
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.5);
  padding: 20px;
}

.close {
  position: relative;
  width: 50px;
  height: 30px;
  cursor: pointer;
  border-radius: 3px;
  left: -220px;
  top: -80px;
}
import React, { useState} from 'https://esm.sh/react@18.2.0'
import ReactDOM from 'https://esm.sh/react-dom@18.2.0'

const App = () => {
  const [isModalOpen, setIsModalOpen] = useState(false);
  const [isOfferAccepted, setIsOfferAccepted] = useState(false);

  const handleModalOpen = () => {
    setIsModalOpen(true);
  };

  const handleModalClose = () => {
    setIsModalOpen(false);
  };

  const handleAccepted = () => {
    setIsModalOpen(false);
    setIsOfferAccepted(true);
  };

  return (
    <div className='container'>
      {isOfferAccepted ? (
        <h1>Offer Accepted !!</h1>
      ) : (
        <button onClick={handleModalOpen}>Show Offer</button>
      )}
      {isModalOpen && (
         <div className='modal' onClick={handleModalClose}>
         <div className='modal-content' onClick={(e) => e.stopPropagation()}>
           <button className='close' onClick={handleModalClose}>
             X
           </button>
           <h3>Click the button below to accept our amazing offer !!</h3>
           <button className='accept' onClick={handleAccepted}>
             Accept Offer
           </button>
         </div>
       </div>
      )}
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById("root"))
View Compiled
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.