ruvector/studio/components/ui/CopyButton.tsx
rUv 814f595995 feat(studio): Add complete RuVector Studio application
Major additions:
- Complete Next.js studio application with 1600+ components
- Docker support (Dockerfile.combined, docker-compose.yml)
- GCP deployment documentation and benchmarks
- SQL benchmark scripts for performance testing
- Sentry integration for monitoring
- Comprehensive test suite and mocks

Studio features:
- Dashboard and admin interfaces
- Data visualization components
- Authentication and user management
- API integration with RuVector backend
- Static data and public assets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 23:04:48 +00:00

76 lines
1.8 KiB
TypeScript

import { Check, Copy } from 'lucide-react'
import { ComponentProps, forwardRef, useEffect, useState } from 'react'
import { Button, cn, copyToClipboard } from 'ui'
type CopyButtonBaseProps = {
iconOnly?: boolean
copyLabel?: string
copiedLabel?: string
}
type CopyButtonWithText = CopyButtonBaseProps & {
text: string
asyncText?: never
}
type CopyButtonWithAsyncText = CopyButtonBaseProps & {
text?: never
asyncText: () => Promise<string> | string
}
export type CopyButtonProps = (CopyButtonWithText | CopyButtonWithAsyncText) &
ComponentProps<typeof Button>
const CopyButton = forwardRef<HTMLButtonElement, CopyButtonProps>(
(
{
text,
asyncText,
iconOnly = false,
children,
onClick,
copyLabel = 'Copy',
copiedLabel = 'Copied',
...props
},
ref
) => {
const [showCopied, setShowCopied] = useState(false)
useEffect(() => {
if (!showCopied) return
const timer = setTimeout(() => setShowCopied(false), 2000)
return () => clearTimeout(timer)
}, [showCopied])
return (
<Button
ref={ref}
onClick={async (e) => {
const textToCopy = asyncText ? await asyncText() : text
setShowCopied(true)
copyToClipboard(textToCopy)
onClick?.(e)
}}
{...props}
className={cn(
{
'px-1': iconOnly,
// '!pointer-events-auto': props.disabled,
},
props.className
)}
icon={
showCopied ? <Check strokeWidth={2} className="text-brand" /> : props.icon ?? <Copy />
}
>
{!iconOnly && <>{children ?? (showCopied ? copiedLabel : copyLabel)}</>}
</Button>
)
}
)
CopyButton.displayName = 'CopyButton'
export default CopyButton