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://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 [isChecked, setIsChecked] = useState(false); const [isDisabled, setIsDisabled] = useState(false); const handleCheckboxChange = () => { setIsChecked(!isChecked); setIsDisabled(true); }; return ( <div className="container"> <h3>React Js Checkbox disabled after check</h3> <label> <input type="checkbox" checked={isChecked} disabled={isDisabled} onChange={handleCheckboxChange} /> Checkbox </label> </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; } h3 { margin-bottom: 20px; color: #333; } label { display: flex; align-items: center; cursor: pointer; font-size: 18px; color: #666; } input[type="checkbox"] { margin-right: 10px; appearance: none; width: 20px; height: 20px; border: 2px solid #999; border-radius: 4px; outline: none; transition: border-color 0.3s ease-in-out; } input[type="checkbox"]:checked { border-color: #55a630; background-color: #55a630; } input[type="checkbox"]:checked::before { content: ""; display: block; width: 10px; height: 10px; margin: 4px; background-color: #fff; border-radius: 2px; } input[type="checkbox"]:disabled { cursor: not-allowed; opacity: 0.6; } input[type="checkbox"]:disabled+span { color: #999; } </style> </body> </html>