fix: Issues with exports
This commit is contained in:
parent
d703707532
commit
b4c4031fc5
20 changed files with 252 additions and 274 deletions
33
packages/react/components/CopyToClipboard/index.mjs
Normal file
33
packages/react/components/CopyToClipboard/index.mjs
Normal 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>
|
||||
)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue