azure-devops-ui
Version:
React components for building web UI in Azure DevOps
1 lines • 831 B
JavaScript
import*as React from"react";import*as ReactDOM from"react-dom";function copyToClipboard(e,t){if(e instanceof HTMLElement)copy(e,t);else{const o=document.createElement("div");o.classList.add("visually-hidden"),o.setAttribute("aria-hidden","true"),o.setAttribute("role","presentation"),o.setAttribute("style","{color: inherit; background-color: inherit;}"),document.body.appendChild(o);e=React.createElement("div",{ref:e=>{e&&(copy(e,t),window.setTimeout(()=>{ReactDOM.unmountComponentAtNode(o),document.body.removeChild(o)},0))},style:{whiteSpace:"pre",color:"inherit",backgroundColor:"inherit"}},e);ReactDOM.render(e,o)}}function copy(e,t){var o=document.createRange(),n=window.getSelection();n.removeAllRanges(),o.selectNodeContents(e),n.addRange(o),document.execCommand("copy"),n.removeAllRanges(),t&&t()}export{copyToClipboard};