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.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/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> <script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4"></script> </head> <body> <div id="app"></div> <div id="output"></div> <!-- Add a div to display the split string --> <script type="text/babel"> const { useState } = React; function App() { const [inputString] = useState('fontAwesoemicons'); // Replace with your desired input string const [chunkSize] = useState(2); // Replace with your desired chunk size const [outputChunks, setOutputChunks] = useState([]); const splitString = () => { const chunks = []; for (let i = 0; i < inputString.length; i += chunkSize) { chunks.push(inputString.slice(i, i + chunkSize)); } setOutputChunks(chunks); }; return ( <div className='container'> <h3 className='heading'>React js String Split by its Length</h3> <p className='paragraph'>String: {inputString}</p> <button className='button' onClick={splitString}>Split String</button> <div className='output'> <p>{outputChunks.join(', ')}</p> </div> </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { max-width: 500px; margin: 0 auto; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); display: flex; flex-direction: column; align-items: center; justify-content: center; } /* Style for the heading */ .heading { font-size: 24px; margin-bottom: 10px; color: #333; } /* Style for the paragraph */ .paragraph { font-size: 16px; margin-bottom: 20px; color: #555; } /* Style for the button */ .button { background-color: #007bff; color: #fff; border: none; padding: 10px 20px; border-radius: 5px; font-size: 18px; cursor: pointer; transition: background-color 0.3s ease; } .button:hover { background-color: #0056b3; } /* Style for the output */ .output { margin-top: 10px; } .output p { font-size: 16px; color: #333; margin: 0; } </style> </body> </html>