screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.14.0/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.14.0/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 [r, setR] = useState(110); const [g, setG] = useState(169); const [b, setB] = useState(114); const rgbToHex = (r, g, b) => { let hex = ((r << 16) | (g << 8) | b).toString(16); return "#" + "0".repeat(6 - hex.length) + hex; }; const handleInputChange = (e) => { const value = parseInt(e.target.value); const name = e.target.name; if (!isNaN(value)) { if (name === "r") setR(value); else if (name === "g") setG(value); else if (name === "b") setB(value); } }; return ( <div className="container"> <h4 className="title">React Js Convert RGB Color to Hex Color</h4> <div className="color-inputs"> <label> R: <input type="number" name="r" value={r} min="0" max="255" onChange={handleInputChange} /> </label> <label> G: <input type="number" name="g" value={g} min="0" max="255" onChange={handleInputChange} /> </label> <label> B: <input type="number" name="b" value={b} min="0" max="255" onChange={handleInputChange} /> </label> </div> <p className="rgb-text"> RGB Color: rgb({r}, {g}, {b}) </p> <div className="color-box" style={{ backgroundColor: rgbToHex(r, g, b) }} > Hexa Color: {rgbToHex(r, g, b)} </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { margin: 0 auto; width: 500px; 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; display: flex; flex-direction: column; align-items: center; height: 100vh; } .title { font-size: 24px; font-weight: bold; margin-bottom: 16px; } .rgb-text { font-size: 18px; margin-bottom: 16px; } .color-box { width: 200px; height: 200px; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: bold; color: #fff; text-align: center; } .color-inputs { display: flex; justify-content: center; margin-bottom: 16px; } .color-inputs label { margin: 0 8px; } /* Additional styles for better visual appeal */ .color-box { box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); border-radius: 8px; } </style> </body> </html>