mirror of
https://github.com/supabase/supabase.git
synced 2026-10-11 04:15:04 +03:00
* 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
47 lines
1.1 KiB
TypeScript
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
|