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; const ReusableInput = ({ type, placeholder, value, onChange, label }) => { return ( <div> <label className="label-class">{label}</label> <input className="input-class" type={type} placeholder={placeholder} value={value} onChange={(e) => onChange(e.target.value)} /> </div> ); } function App() { const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [email, setEmail] = useState(''); return ( <div className='container'> <h1>React Js Reusable Input Fields Example</h1> <ReusableInput type="text" placeholder="Enter username" value={username} onChange={setUsername} label="Username:" /> <ReusableInput type="email" placeholder="Enter EMail" value={email} onChange={setEmail} label="Email:" /> <ReusableInput type="password" placeholder="Enter password" value={password} onChange={setPassword} label="Password:" /> <p>Username: {username}</p> <p>Email: {email}</p> <p>Password: {password}</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> * { box-sizing: border-box; } .container { margin: 0 auto; width: 600px; 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); padding: 20px; } /* Style for label element */ .label-class { font-size: 16px; font-weight: bold; color: #333; margin-bottom: 8px; } /* Style for input element */ .input-class { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; color: #555; transition: border-color 0.3s ease; } .input-class:focus { border-color: #007BFF; outline: none; box-shadow: 0 0 5px rgba(0, 123, 255, 0.5); } </style> </body> </html>