react-clipboard-simple
Version:
Component that allows user to copy text on simple click.
27 lines (22 loc) • 803 B
JavaScript
import React,{useState} from 'react'
export default function ReactClipboard({children,keyword}) {
const [copy,setCopy]=useState(false)
const clip=(e)=>{
window.navigator.clipboard.writeText(keyword)
setCopy(true)
setTimeout(()=>{
setCopy(false)
},1000)
}
return (React.createElement(
"div",
{ onClick: clip, title: "add to clipboard", style: { position: "relative",cursor:"pointer" } },
children,
copy && React.createElement(
"span",
{ style: { backgroundColor: "yellow", color: "red", display: "inline-block", padding: "5px", position: "absolute", left: "20px", top: "2px", borderRadius: "3px" } },
"Copied"
)
)
)
}