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.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.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 [toastVisible, setToastVisible] = useState(false); const [toastContent, setToastContent] = useState(''); const handleToastClick = () => { const dynamicContent = 'This is a dynamically generated message!'; setToastContent(dynamicContent); setToastVisible(true); setTimeout(() => { setToastVisible(false); }, 5000); }; return ( <div className='container'> <h3>React Js Toast Message | Notification</h3> <button id="toast-btn" className="toast button" onClick={handleToastClick}> Toast Message </button> {toastVisible && ( <div className="toast-container "> <div className="toast" role="alert" aria-live="assertive" aria-atomic="true"> <div className="toast-body">{toastContent}</div> </div> </div> )} </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } body { font-family: Arial, sans-serif; margin: 0; padding: 0; } .container { text-align: center; padding: 20px; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); margin: 0 auto; width: 600px; } h3 { margin-bottom: 20px; } .toast.button { padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 4px; cursor: pointer; } .toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; } .toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; } .toast { position: relative; min-width: 300px; padding: 10px 20px; background-color: #343a40; color: #fff; border: 1px solid #343a40; border-radius: 4px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); transition: opacity 0.3s ease-in-out; } .toast-body { margin-bottom: 0; } </style> </body> </html>