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://cdn.jsdelivr.net/npm/@babel/standalone@7.14.6/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel" data-presets="env,react"> const { useState } = React; function App() { const [copyText, setCopyText] = useState("Text to be copied"); const [result, setResult] = useState(""); const copyToClipboard = () => { navigator.clipboard.writeText(copyText).then( () => setResult("Text copied to clipboard"), (err) => console.error("Could not copy text: ", err) ); }; return ( <div class="container"> <h3>React copy to clipboard</h3> <label>Text to be copied:</label> <input type="text" value={copyText} onChange={(e) => setCopyText(e.target.value)} /> <button onClick={copyToClipboard}>Copy</button> {result && <pre>{result}</pre>} </div> ); } ReactDOM.render(<App />, document.getElementById("app")); </script> <style> .container { margin: 20px; font-family: Arial, sans-serif; width: 400px; margin: 0 auto; } label { display: block; margin-bottom: 10px; font-weight: bold; } input[type="text"] { width: 300px; padding: 8px; margin-bottom: 15px; border: 1px solid #ccc; border-radius: 4px; font-size: 14px; } button { padding: 8px 12px; background-color: #4caf50; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 14px; } button:hover { background-color: #45a049; } pre { background-color: #f4f4f4; padding: 10px; font-family: Consolas, Monaco, monospace; overflow: auto; font-size: 14px; } </style> </body> </html>