CopyableText, CodeSnippet

Fiddle
Values a user copies: commands, keys, URLs.
fern generate

Usage

The import, then a use to start from. Both copy as they are.

Import
import { CodeSnippet } from "@/components/ui/CodeSnippet";import { CopyableText } from "@/components/ui/CopyableText";
Example
<CopyableText text={token} variant="chip" copyAriaLabel="Copy the API token" /> <CodeSnippet code="npm install -g fern-api" copySuccessMessage="Copied the install command" />

When to use

Use it for

  • CopyableText for one value someone copies: a key, an ID, a URL. variant fits it to the context: default, innerCopy or chip.
  • CodeSnippet for a command or a short snippet inside a form or a dialog. Long lines scroll instead of wrapping, and the copy button is its own column.
  • Name the toast with copySuccessMessage when several snippets share a screen.
  • placeholders marks a word people replace, such as my_tool, with a wavy underline and a tooltip that says what goes there. Copy still copies the command as written.

Avoid

  • A placeholder in angle brackets (<name>): pasted into a shell, < is a redirect. Use a sample word and placeholders.
  • A file or multi-line code with a name: use CodeBlock, which highlights it the way Fern Docs does.
  • Text people read but don't copy.
  • A copy button of your own: both confirm a copy the same way.

Accessibility

Checks

  • The copy button has a name; pass copyAriaLabel when “Copy” alone doesn't say what it copies.
  • Each placeholder is focusable, so its tooltip opens from the keyboard, and its name includes the hint.

API

Read from each component's stories, the same source as COMPONENTS.md, and kept in step by check:design-system.

CopyableText

PropValues
variant"default""innerCopy""chip"
VariantsDefaultInnerCopyLongTextWithCopyCallbackChip

CodeSnippet

Its stories don't declare argTypes, so no props are listed. The variants show its states.
VariantsDefaultLongUrlScrollsHorizontallyShellCommandWithPlaceholderLongSingleLineMultilineHighlightedNoCopyButtonCustomCopyMessageNarrowCappedHeightWithCopyCallback

Keep going

Typography
Beautiful display and mono fonts that scale for all sizes.