Fill Before Copy

Turns placeholders like <YOUR_API_KEY> in a code sample into fields and holds Copy until they're filled, so broken commands aren't pasted.

StopsPasted a command with YOUR_API_KEY in it

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/fill-before-copy.json

The files land in your project. They're yours to edit.

Usage

fill-before-copy-usage.tsx
import { FillBeforeCopy } from "@/components/ui/fill-before-copy"

<FillBeforeCopy code={code} defaultValue={{ project_id: "prj_8f3k2" }} />

What it catches

  • Placeholders left in a command or config snippet
  • Which placeholder is still empty, by moving focus to it
  • Custom placeholder syntaxes via `pattern`

Props

FillBeforeCopy props
PropTypeDefault
code* (required)

The snippet, with placeholders like `<YOUR_API_KEY>` or `{{project_id}}`.

string—
title

Header text, e.g. "Terminal" or "bash".

string"Terminal"
pattern

Which placeholder syntax to detect.

RegExpPLACEHOLDER
value

Controlled values by placeholder name.

Record<string, string>—
defaultValue

Initial values when uncontrolled.

Record<string, string>{}
onValueChange

Called with every value on each change.

(value: Record<string, string>) => void—
unfilled

"block" refuses to copy until every placeholder is filled; "warn" asks once, then copies.

"block" | "warn""block"
onCopy

Called with the filled text that went to the clipboard.

(text: string) => void—
fillLabel

Templates: `{count}` and `{names}` are filled in.

string"Fill {count}"
leftText

Status text counting placeholders left ({count} is filled in).

string"Still a placeholder: {names}."
readyText

Status text when every placeholder is filled.

string"All placeholders filled."
copyLabel

Copy button text.

string"Copy"
copiedLabel

Shown after copying.

string"Copied"
copyAnywayLabel

Text for copying with placeholders left.

string"Copy anyway"
blockedText

Shown when Copy is blocked.

string"Couldn't copy. Your browser blocked clipboard access."

* required. Also accepts the native props of <div> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Each placeholder field has an aria-label from its name, with aria-invalid when asked to fill it
  • Copy is described by an aria-live="polite" status; blocked copy moves focus to the first empty field
  • Errors use role="alert"

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Only finds placeholders matching the pattern
  • Values typed into the fields are in the page; avoid pre-filling real secrets in shared docs

What it stops

Pasted a command with YOUR_API_KEY in it

Also known as

code snippet · copy button · placeholder · docs · curl · api key · template · copy to clipboard

Dependencies

Pairs well with