PILOT // NEXTUI
CopyField
Read-only code field with a one-click copy-to-clipboard button. Shows a checkmark and "Copied!" confirmation for 2 seconds after copying. Client component.
$
Or install the base component for free:
Live Preview
Usage
TSX
<CopyField value="npm install @scope/sdk" label="Install command" />Source
TSX
'use client'
import { useState } from 'react'
import type * as React from 'react'
import { cn } from '@/lib/utils'
interface CopyFieldProps {
value: string
label?: string
}
export function CopyField({ value, label }: CopyFieldProps): React.JSX.Element {
const [copied, setCopied] = useState(false)
function handleCopy() {
navigator.clipboard.writeText(value).then(() => {
setCopied(true)
setTimeout(() => setCopied(false), 2000)
})
}
return (
<div className="pilot-copy-field" role="group" aria-label={label}>
<code className="pilot-copy-value">{value}</code>
<button
type="button"
className={cn('pilot-copy-btn', copied && 'pilot-copy-btn--copied')}
onClick={handleCopy}
aria-label={copied ? 'Copied' : 'Copy to clipboard'}
>
{copied ? (
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<polyline points="20 6 9 17 4 12" />
</svg>
) : (
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2" />
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
</svg>
)}
<span>{copied ? 'Copied!' : 'Copy'}</span>
</button>
</div>
)
}
Works withNext.js 15React 19Tailwind v4TypeScript 5
More from PILOT // NEXT
Button
Dashboard button with primary, secondary, and ghost variants in three sizes. Handles disabled links by rendering an aria-disabled span instead of a Link.
View sourceNo preview
DateRangePicker
Dropdown date range selector with preset intervals (7, 14, 30, 90 days). Displays the computed date range in the trigger button and closes on route change. Client component.
View sourceNo preview