mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 18:05:11 +03:00
* Add lucide-react to docs (to make the autocomplete work). * Migrate the docs app icons. * Migrate the ui-patterns. * Remove the old icons from ui package. * Migrate the www app from react-feather icons. * Migrate all of studio icons. * Migrate the only component in design-system. * Fix an old import in ui package. Revert an import in docs app. * Fix some pages in www. * Remove unneeded files used in generation of icons. * Fix a prettier error. * Fix more issues in www. * Fix an issue in Log Date picker. * Replace all string sizes with number sizes because the icons grew in some cases. * Fix more imports in security page. * Fix an extra import. * Remove the size prop from all icons if they're in a button and they match the button size. * Minor fixes for docs and www. --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
45 lines
1.1 KiB
TypeScript
45 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)
|
|
}}
|
|
icon={showCopied ? <Check strokeWidth={2} className="text-brand" /> : <Clipboard />}
|
|
{...props}
|
|
>
|
|
{!iconOnly && <>{children ?? (showCopied ? copiedLabel : copyLabel)}</>}
|
|
</Button>
|
|
)
|
|
}
|
|
export default CopyButton
|