CopyableText, CodeSnippet
Fiddlefern 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
CopyableTextfor one value someone copies: a key, an ID, a URL.variantfits it to the context:default,innerCopyorchip.CodeSnippetfor 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
copySuccessMessagewhen several snippets share a screen. placeholdersmarks a word people replace, such asmy_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 andplaceholders. - 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
copyAriaLabelwhen “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
| Prop | Values |
|---|---|
| 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
- CodeBlockFiles and multi-line code as Fern Docs shows them: a title bar, highlighting, line numbers, copy.Fiddle
- Input, TextareaText entry. Always with a
Label; errors viaaria-invalidand aNote.Frond - ButtonEvery clickable. Variants: default, outline, ghost, ghostMuted, destructive, destructiveOutline, link.Frond
- TooltipName or detail on hover and focus. Takes a
shortcut.Frond
Typography
Beautiful display and mono fonts that scale for all sizes.