mirror of
https://github.com/hanzoai/ui.git
synced 2026-11-20 22:36:27 +00:00
Squash merge of shadcn-ui/ui main branch into hanzo/ui, bringing in: - [email protected] through [email protected] releases - New apps/v4 directory structure - Registry system improvements and MCP server - Framework support (Vue, Svelte, React Native) - New templates (vite-app, monorepo-next, laravel) - Zod 4 compatibility (scoped override for zod@>4) - Test fixture corrections for alias resolution All 867 merge conflicts resolved preserving Hanzo customizations. 1020/1020 shadcn tests pass.
69 lines
1.5 KiB
TypeScript
69 lines
1.5 KiB
TypeScript
"use client"
|
|
|
|
import * as React from "react"
|
|
import { IconCheck, IconCopy } from "@tabler/icons-react"
|
|
|
|
import { trackEvent, type Event } from "@/lib/events"
|
|
import { cn } from "@/lib/utils"
|
|
import { Button } from "@/registry/new-york-v4/ui/button"
|
|
|
|
export function copyToClipboardWithMeta(value: string, event?: Event) {
|
|
navigator.clipboard.writeText(value)
|
|
if (event) {
|
|
trackEvent(event)
|
|
}
|
|
}
|
|
|
|
export function CopyButton({
|
|
value,
|
|
className,
|
|
variant = "ghost",
|
|
event,
|
|
...props
|
|
}: React.ComponentProps<typeof Button> & {
|
|
value: string
|
|
src?: string
|
|
event?: Event["name"]
|
|
tooltip?: string
|
|
}) {
|
|
const [hasCopied, setHasCopied] = React.useState(false)
|
|
|
|
React.useEffect(() => {
|
|
if (hasCopied) {
|
|
const timer = setTimeout(() => setHasCopied(false), 2000)
|
|
return () => clearTimeout(timer)
|
|
}
|
|
}, [hasCopied])
|
|
|
|
return (
|
|
<Button
|
|
data-slot="copy-button"
|
|
data-copied={hasCopied}
|
|
size="icon"
|
|
variant={variant}
|
|
className={cn(
|
|
"bg-code absolute top-3 right-2 z-10 size-7 hover:opacity-100 focus-visible:opacity-100",
|
|
className
|
|
)}
|
|
onClick={() => {
|
|
copyToClipboardWithMeta(
|
|
value,
|
|
event
|
|
? {
|
|
name: event,
|
|
properties: {
|
|
code: value,
|
|
},
|
|
}
|
|
: undefined
|
|
)
|
|
setHasCopied(true)
|
|
}}
|
|
{...props}
|
|
>
|
|
<span className="sr-only">Copy</span>
|
|
{hasCopied ? <IconCheck /> : <IconCopy />}
|
|
</Button>
|
|
)
|
|
}
|