screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; function App() { const [showModal, setShowModal] = useState(false); const toggleModal = () => { setShowModal(!showModal); }; const submitForm = (e) => { e.preventDefault(); // Perform form submission logic here // Display a message const message = document.createElement('p'); message.textContent = 'Form submitted! Closing in 5 seconds.'; document.querySelector('.modal-content').appendChild(message); // Close the modal after form submission with a delay of 5000 milliseconds (5 seconds) setTimeout(() => { // Remove the message document.querySelector('.modal-content').removeChild(message); // Close the modal toggleModal(); }, 5000); }; return ( <div className='container'> <h3>React Close Modal After 5 Seconds After Submit</h3> <button onClick={toggleModal}>Open Modal</button> {showModal && ( <div className="modal"> <div className="modal-content"> <button className="close-x" onClick={toggleModal}>X</button> <form onSubmit={submitForm}> <h3>React Js Close Modal after form submit</h3> {/* Form fields here */} <button type="submit">Submit</button> </form> </div> </div> )} </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); width: 600px; margin: 0 auto; padding: 20px; } button { padding: 10px 20px; background-color: #4287f5; color: #fff; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; } .modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: flex; align-items: center; justify-content: center; } .modal-content { background-color: #fff; padding: 40px; border-radius: 5px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); max-width: 400px; width: 100%; position: relative; } .close-x { position: absolute; top: 10px; right: 10px; padding: 5px; background-color: transparent; border: none; cursor: pointer; font-size: 18px; color: #555; } .close-x:hover { color: #ff0000; } form { display: flex; flex-direction: column; } form h3 { margin-bottom: 20px; } form button[type="submit"] { padding: 10px 20px; background-color: #4CAF50; color: #fff; border: none; border-radius: 5px; font-size: 16px; cursor: pointer; } form button[type="submit"]:hover { background-color: #45a049; } </style> </body> </html>