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; const App = () => { const [selectedCategory, setSelectedCategory] = useState(null); const [selectedSubcategory, setSelectedSubcategory] = useState(null); const categories = ['Electronics', 'Clothing', 'Books']; const subcategories = { Electronics: ['Phones', 'Laptops', 'Cameras'], Clothing: ['Shirts', 'Pants', 'Dresses'], Books: ['Fiction', 'Non-fiction', 'Sci-Fi'], }; return ( <div className='container'> <h3>React Js Category Subcategory dropdown Example</h3> <h2>Category Dropdown</h2> <select onChange={(e) => setSelectedCategory(e.target.value)}> <option value="">Select Category</option> {categories.map((category) => ( <option key={category} value={category}> {category} </option> ))} </select> <h2>Subcategory Dropdown</h2> <select onChange={(e) => setSelectedSubcategory(e.target.value)}> <option value="">Select Subcategory</option> {selectedCategory && subcategories[selectedCategory].map((subcategory) => ( <option key={subcategory} value={subcategory}> {subcategory} </option> ))} </select> <div> <h2>Selected:</h2> <p>Category: {selectedCategory}</p> <p>Subcategory: {selectedSubcategory}</p> </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { text-align: center; padding: 20px; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); margin: 0 auto; max-width: 600px; } select { width: 100%; padding: 8px; border: 1px solid #ccc; border-radius: 4px; background-color: white; font-size: 16px; margin-bottom: 15px; } ul { list-style: none; padding: 0; } li { padding: 10px; margin: 5px 0; background-color: #fff; border: 1px solid #ccc; border-radius: 5px; cursor: pointer; transition: background-color 0.3s, transform 0.3s; } li:hover { background-color: #f0f0f0; } </style> </body> </html>