-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathindex.tsx
44 lines (35 loc) · 1.23 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*--------------------------------------------------------------------------
* Copyright (c) 2019-2021, Postgres.ai, Nikolay Samokhvalov nik@postgres.ai
* All Rights Reserved. Proprietary and confidential.
* Unauthorized copying of this file, via any medium is strictly prohibited
*--------------------------------------------------------------------------
*/
import clsx from 'clsx'
import copy from 'copy-to-clipboard'
import useCountDown from 'react-countdown-hook'
import { Button } from '@postgres.ai/shared/components/Button2'
import styles from './styles.module.scss'
type Props = {
value: string
className?: string
}
const COOLDOWN_INTERVAL = 1000
const COOLDOWN_TIME = 1000
export const FormattedText = (props: Props) => {
const { value, className } = props
const [timeLeft, { start }] = useCountDown(0, COOLDOWN_INTERVAL)
const handleCopy = () => {
copy(value)
start(COOLDOWN_TIME)
}
return (
<div className={clsx(styles.root, className)}>
<pre className={styles.content}>{value}</pre>
<div className={styles.copyButtonContainer}>
<Button size="sm" onClick={handleCopy} className={styles.copyButton}>
{timeLeft ? 'Copied' : 'Copy'}
</Button>
</div>
</div>
)
}