Copy Button

@sushindustries/ui

A glass chip that writes to the clipboard and confirms in the button itself.

Last updated Aug 17, 20265 min read
View as MarkdownEdit on GitHub

Choosing a ground

<CopyButton text={code} ground="slab" />   {/* the charcoal of a code block */}
<CopyButton text={command} ground="paper" />  {/* everywhere else */}
<CopyButton text={value} ground="accent" />
tsx

The chip is glass either way - fill plus edge, no blur - but one glass recipe does not read correctly on every background, so ground picks which recipe. Get it wrong and the button is still clickable, just faint or oddly bright against whatever it sits on.

Composing it

ground describes a material, so give it something with a visible boundary to sit on - a code block, an inline <code>, a card - rather than the bare page background. On fine pointers, showing it only on hover of a code-shell ancestor is common; on coarse pointers keep it always visible, since "appears on hover" cannot happen without a hover to begin with.

When not to use it

Copying something longer than a short string - a whole file, a large JSON blob a reader would want to inspect before trusting - is better served by CodeBlock, which pairs the same button with the content it is copying.

UsesIconIconThe glyph set, generated from a Markdown table where every drawing carries its reason. One component, typed names, no icon font.@sushindustries/ui · content
Used byCode BlockCode BlockA highlighted code slab with the CLI's colours, a lit top edge, and a copy button that confirms in place.@sushindustries/ui · contentSecret RevealSecret RevealA credential shown once: it wraps rather than scrolls, one click selects all of it, and the copy button sits under it rather than over it.@sushindustries/ui · contentShowcaseShowcaseA component in a real iframe at every width it has to survive, side by side, with its source and install commands.@sushindustries/ui · docs
Mentioned inCode Block