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://unpkg.com/@babel/standalone@7.14.7/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState } = React; function App() { const [checkboxes, setCheckboxes] = useState({ checkbox1: false, checkbox2: false, checkbox3: false, // Add more checkboxes here if needed }); const [checkAllResult, setCheckAllResult] = useState(""); const handleCheckboxChange = (checkboxName) => { setCheckboxes({ ...checkboxes, [checkboxName]: !checkboxes[checkboxName], }); }; const areAllCheckboxesChecked = () => { for (const checkboxName in checkboxes) { if (!checkboxes[checkboxName]) { return false; } } return true; }; const handleCheckAll = () => { if (areAllCheckboxesChecked()) { setCheckAllResult("All checkboxes are checked!"); } else { setCheckAllResult("Not all checkboxes are checked."); } }; return ( <div className="container"> <h3>React Js Check if all checkboxes are checked</h3> <label> <input type="checkbox" checked={checkboxes.checkbox1} onChange={() => handleCheckboxChange("checkbox1")} /> Checkbox 1 </label> <label> <input type="checkbox" checked={checkboxes.checkbox2} onChange={() => handleCheckboxChange("checkbox2")} /> Checkbox 2 </label> <label> <input type="checkbox" checked={checkboxes.checkbox3} onChange={() => handleCheckboxChange("checkbox3")} /> Checkbox 3 </label> {/* Add more checkboxes here if needed */} <button onClick={handleCheckAll}>Check All</button> <p>{checkAllResult}</p> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> /* Your existing CSS styles here */ .container { width: 400px; margin: 0 auto; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); padding: 20px; font-family: Arial, sans-serif; display: flex; flex-direction: column; align-items: flex-start; padding: 20px; } label { display: flex; align-items: center; margin-bottom: 10px; cursor: pointer; } input[type="checkbox"] { margin-right: 10px; } button { background-color: #4caf50; color: white; padding: 10px 20px; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #45a049; } p { margin-top: 10px; font-weight: bold; } /* Custom styles for the checkboxes */ input[type="checkbox"] { appearance: none; width: 20px; height: 20px; border: 2px solid #333; border-radius: 3px; cursor: pointer; } input[type="checkbox"]:checked { background-color: #4caf50; border: 2px solid #4caf50; color: white; } </style> </body> </html>