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 [text, setText] = useState('React.js Cut And Paste Functionality'); const [isClipboardEmpty, setIsClipboardEmpty] = useState(true); const cutText = () => { // Copy the text to the clipboard navigator.clipboard.writeText(text); // Clear the input field setText(''); // Set isClipboardEmpty to false setIsClipboardEmpty(false); }; const pasteText = async () => { // Get the pasted text from the clipboard const pastedText = await navigator.clipboard.readText(); // Append the pasted text to the input field setText((prevText) => prevText + pastedText); // Set isClipboardEmpty to false if there is text in the clipboard setIsClipboardEmpty(pastedText.trim() === ''); }; return ( <div className='container'> <h2 className='title'>React js Cut And Paste Text</h2> <div className='input-container'> <input type="text" value={text} onChange={(e) => setText(e.target.value)} className='input-field' /> <button onClick={cutText} className='cut-button'> Cut </button> <button onClick={pasteText} disabled={isClipboardEmpty} className='paste-button'> Paste </button> </div> </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; } .title { font-size: 24px; color: #333; margin-bottom: 20px; } .input-container { display: flex; align-items: center; justify-content: center; } .input-field { flex: 1; padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-size: 16px; } .cut-button, .paste-button { margin-left: 10px; padding: 10px 20px; background-color: #007bff; color: #fff; border: none; border-radius: 4px; cursor: pointer; transition: background-color 0.3s ease; } .cut-button:hover, .paste-button:hover { background-color: #0056b3; } .paste-button:disabled { background-color: #ccc; cursor: not-allowed; } </style> </body> </html>