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.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app" class="container"></div> <script type="text/babel"> // Add the import statement for useState hook const { useState } = React; // Define the App component const App = () => { const [selectedYear, setSelectedYear] = useState(""); const handleYearChange = (event) => { setSelectedYear(event.target.value); }; const years = Array.from( { length: 50 }, (_, index) => new Date().getFullYear() - index ); return ( <div className="year-picker"> <h3>React Js Year Picker</h3> <select value={selectedYear} onChange={handleYearChange}> <option value="">Select a year</option> {years.map((year) => ( <option key={year} value={year}> {year} </option> ))} </select> {selectedYear && <p>You selected: {selectedYear}</p>} </div> ); }; ReactDOM.render(<App />, document.getElementById("app")); </script> <style> body { margin: 0; } .container { max-width: 400px; margin: 0 auto; padding: 20px; font-family: Arial, sans-serif; box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1); position: relative; } /* Styling for the select element */ .year-picker select { padding: 8px 12px; font-size: 16px; border: 1px solid #ccc; border-radius: 4px; outline: none; width: 100%; margin-bottom: 16px; } /* Styling for the select option */ .year-picker select option { padding: 8px; } /* Styling for the selected year */ .year-picker p { font-size: 14px; color: #333; } </style> </body> </html>