Files
supabase/apps/ui-library/components/command-copy-button.tsx
Saxon FletcherandJonathan Summers-Muir 3a95aec3ee Chore/library styles (#34465)
* use our own tree view

* fix padidng

* updated styles

---------

Co-authored-by: Jonathan Summers-Muir <MildTomato@users.noreply.github.com>
2025-03-27 10:12:47 +00:00

30 lines
705 B
TypeScript

'use client'
import { Check, Copy } from 'lucide-react'
import { useEffect, useState } from 'react'
import { Button_Shadcn_ } from 'ui'
export function CommandCopyButton({ command }: { command: string }) {
const [copied, setCopied] = useState(false)
useEffect(() => {
if (copied) {
const timeout = setTimeout(() => setCopied(false), 2000)
return () => clearTimeout(timeout)
}
}, [copied])
return (
<Button_Shadcn_
variant="ghost"
size="icon"
onClick={() => {
navigator.clipboard.writeText(command)
setCopied(true)
}}
>
{copied ? <Check className="h-4 w-4" /> : <Copy className="h-4 w-4" />}
</Button_Shadcn_>
)
}