1
0
Fork 0

feat(fs.shared): Add copy-to-clipboard. Closes #1519

This commit is contained in:
Joost De Cock 2022-01-16 18:47:47 +01:00
parent ab96362d97
commit f5877d9abe
5 changed files with 49 additions and 7 deletions

View file

@ -0,0 +1,27 @@
import ReactDOMServer from 'react-dom/server'
import { useState, useEffect } from 'react'
import CopyIcon from 'shared/components/icons/copy.js'
import {CopyToClipboard} from 'react-copy-to-clipboard'
const strip = html => new DOMParser()
.parseFromString(html, 'text/html')
.body.textContent || ""
const CopyToClipboardIcon = ({ content }) => {
const [copied, setCopied] = useState(false)
const text = (typeof content === 'string')
? content
: strip(ReactDOMServer.renderToStaticMarkup(content))
return (
<CopyToClipboard text={text} onCopy={() => setCopied(true)}>
<button className={copied ? 'text-success' : ''}><CopyIcon /></button>
</CopyToClipboard>
)
}
export default CopyToClipboardIcon