import { useContext, useState } from 'react'
import { ReactComponent as CopySVG } from '../svgs/copy.svg'
import { ReactComponent as CopiedSVG } from '../svgs/copied.svg'
import type { NodeMeta } from '../types'
import { writeClipboard } from '../utils'
import { JsonViewContext } from './json-view'
interface Props {
node: any
nodeMeta: NodeMeta
}
export default function CopyButton({ node, nodeMeta }: Props) {
const { customizeCopy, CopyComponent, CopiedComponent } = useContext(JsonViewContext)
const [copied, setCopied] = useState(false)
const copyHandler = (event: React.MouseEvent) => {
event.stopPropagation()
const value = customizeCopy(node, nodeMeta)
if (typeof value === 'string' && value) {
writeClipboard(value)
}
setCopied(true)
setTimeout(() => setCopied(false), 3000)
}
return copied ? (
typeof CopiedComponent === 'function' ? (
) : (
)
) : typeof CopyComponent === 'function' ? (
) : (
)
}