Download apps/vis/web/src/components/shared/CopyButton.tsx from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 817 Bytes
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/apps/vis/web/src/components/shared/CopyButton.tsx
- Command line
-
hf download hf://SaylorTwift/kimi-code/apps/vis/web/src/components/shared/CopyButton.tsx
-
curl -L -o CopyButton.tsx https://huggingface.co/SaylorTwift/kimi-code/resolve/main/apps/vis/web/src/components/shared/CopyButton.tsx
817 Bytes
| import { useState } from 'react'; | |
| interface CopyButtonProps { | |
| value: string; | |
| label?: string; | |
| className?: string; | |
| } | |
| export function CopyButton({ value, label = 'copy', className = '' }: CopyButtonProps) { | |
| const [state, setState] = useState<'idle' | 'ok' | 'err'>('idle'); | |
| return ( | |
| <button | |
| onClick={(e) => { | |
| e.stopPropagation(); | |
| navigator.clipboard | |
| .writeText(value) | |
| .then(() =>{ setState('ok'); }) | |
| .catch(() =>{ setState('err'); }) | |
| .finally(() => setTimeout(() =>{ setState('idle'); }, 1200)); | |
| }} | |
| className={`font-mono text-[10px] text-fg-3 transition-colors hover:text-fg-1 ${className}`} | |
| title={`Copy ${value}`} | |
| > | |
| {state === 'idle' ? label : state === 'ok' ? '✓ copied' : '✗ err'} | |
| </button> | |
| ); | |
| } | |