screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://unpkg.com/react@17.0.2/umd/react.development.js"></script> <script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.development.js"></script> <script src="https://cdn.jsdelivr.net/npm/@babel/standalone@7.14.6/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel" data-presets="env,react"> const { useState } = React; function App() { const [password, setPassword] = useState(""); const [showPassword, setShowPassword] = useState(false); const handleInputChange = (e) => { setPassword(e.target.value); }; const handleShowPassword = () => { setShowPassword(true); setTimeout(() => { setShowPassword(false); }, 5000); // 5000 milliseconds = 5 seconds }; return ( <div className="container"> <h3>React Js show password input field for 5 seconds</h3> <div className="input-container"> <input type={showPassword ? "text" : "password"} value={password} onChange={handleInputChange} className="password-input" /> <button onClick={handleShowPassword} className="password-button"> {showPassword ? "Hide" : "Show"} </button> </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { max-width: 400px; margin: 0 auto; padding: 20px; border-radius: 5px; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); font-family: Arial, sans-serif; } .input-container { position: relative; } .password-input { width: 100%; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 5px; outline: none; box-sizing: border-box; } .password-button { position: absolute; top: 50%; right: 10px; transform: translateY(-50%); background-color: #fff; border: none; cursor: pointer; font-size: 14px; color: #666; text-transform: uppercase; padding: 5px 10px; border-radius: 5px; outline: none; transition: background-color 0.3s ease; } .password-button:hover { background-color: #f1f1f1; } </style> </body> </html>