Skip to content
This repository was archived by the owner on May 19, 2023. It is now read-only.

Commit f69540d

Browse files
committed
feat: added copytooltip component that copies values on click
1 parent fcea05c commit f69540d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, { FC, useState } from 'react'
2+
import Tooltip from '@material-ui/core/Tooltip'
3+
import { Typography } from '@material-ui/core'
4+
5+
export interface CopyTooltipProps {
6+
pretext?: string
7+
value: string
8+
}
9+
10+
const CopyTooltip: FC<CopyTooltipProps> = ({ pretext, value }) => {
11+
const [isCopied, setIsCopied] = useState(false)
12+
13+
return (
14+
<Tooltip
15+
interactive
16+
title={isCopied ? 'Copied!' : value}
17+
onClick={() => {
18+
navigator.clipboard.writeText(value)
19+
.then(() => { setIsCopied(true) })
20+
}}
21+
onClose={() => {
22+
setIsCopied(false)
23+
}}
24+
>
25+
<Typography>
26+
{pretext && `${pretext} ${value}`}
27+
{!pretext && value}
28+
</Typography>
29+
</Tooltip>
30+
)
31+
}
32+
33+
export default CopyTooltip

0 commit comments

Comments
 (0)