1
0
Fork 0

fix: Issues with exports

This commit is contained in:
joostdecock 2024-12-21 14:25:49 +01:00
parent d703707532
commit b4c4031fc5
20 changed files with 252 additions and 274 deletions

View file

@ -0,0 +1,33 @@
import React, { useState } from 'react'
import ReactDOMServer from 'react-dom/server'
import { CopyIcon, OkIcon } from '@freesewing/react/components/Icon'
import { CopyToClipboard as Copy } from 'react-copy-to-clipboard'
const strip = (html) =>
typeof DOMParser === 'undefined'
? html
: new DOMParser().parseFromString(html, 'text/html').body.textContent || ''
const handleCopied = (setCopied) => {
setCopied(true)
setTimeout(() => setCopied(false), 1000)
}
export const CopyToClipboard = ({ content }) => {
const [copied, setCopied] = useState(false)
const text =
typeof content === 'string' ? content : strip(ReactDOMServer.renderToStaticMarkup(content))
return (
<Copy text={text} onCopy={() => handleCopied(setCopied)}>
<button className={copied ? 'text-success' : ''}>
{copied ? (
<OkIcon className="w-5 h-5 text-success-content bg-success rounded-full p-1" stroke={4} />
) : (
<CopyIcon className="w-5 h-5 text-inherit" />
)}
</button>
</Copy>
)
}