Files
supabase/apps/studio/components/ui/CopyButton.tsx
T
Joshen Lim 6af9ff6061 Chore/user management v2 panel (#29468)
* Midway implementing user management v2 panel

* Do up overview panel less provider information

* Midway provider info

* Wrap up provider information

* Add banned until banner

* Slight adjustment to search input

* Fix

* Fix provider icons in data grid

* Fix

* Moar fixes

* Add loading line

* Address some feedback

* Reorder some elements in the user overview panel

* Fix icons going over cell headers
2024-09-25 12:40:18 +08:00

47 lines
1.1 KiB
TypeScript

import { Check, Clipboard } from 'lucide-react'
import { useEffect, useState } from 'react'
import { copyToClipboard } from 'lib/helpers'
import { Button, ButtonProps } from 'ui'
export interface CopyButtonProps extends ButtonProps {
text: string
iconOnly?: boolean
copyLabel?: string
copiedLabel?: string
}
const CopyButton = ({
text,
iconOnly = false,
children,
onClick,
copyLabel = 'Copy',
copiedLabel = 'Copied',
...props
}: CopyButtonProps) => {
const [showCopied, setShowCopied] = useState(false)
useEffect(() => {
if (!showCopied) return
const timer = setTimeout(() => setShowCopied(false), 2000)
return () => clearTimeout(timer)
}, [showCopied])
return (
<Button
onClick={async (e) => {
setShowCopied(true)
await copyToClipboard(text)
onClick?.(e)
}}
{...props}
icon={
showCopied ? <Check strokeWidth={2} className="text-brand" /> : props.icon ?? <Clipboard />
}
>
{!iconOnly && <>{children ?? (showCopied ? copiedLabel : copyLabel)}</>}
</Button>
)
}
export default CopyButton