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> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useState, useEffect } = React; function App() { const LoadingButton = ({ onClick, isLoading, text }) => { return ( <button className="loading-button" onClick={onClick} disabled={isLoading}> {isLoading ? <div className="loader"></div> : text} </button> ); }; const [isLoading, setIsLoading] = useState(false); const handleClick = () => { setIsLoading(true); // Simulate an API request or any async operation setTimeout(() => { setIsLoading(false); }, 5000); }; return ( <div className='container'> <h3>React js Loading Spinner Button Example</h3> <LoadingButton onClick={handleClick} isLoading={isLoading} text="Submit Form" /> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { font-family: Arial, sans-serif; padding: 20px; border-radius: 5px; box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2); max-width: 600px; margin: 0 auto; text-align: center; } .loading-button { font-family: 'Anek Malayalam', sans-serif; background-color: #fadb14; border: none; outline: none; border-radius: 8px; font-weight: 700; font-size: 14px; color: #ffffff; min-width: 200px; min-height: 36px; cursor: pointer; outline: none; } .loading-button:disabled { background: #e7e8e9; color: #9fa3a9; cursor: not-allowed; } .loader { border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; width: 10px; height: 10px; animation: spin 1s linear infinite; display: inline-block; margin-right: 10px; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } </style> </body> </html>