Components · Data Display
CopyableCode
One command people copy and run, on a code surface with a copy button that confirms with a check.
Also called Command line
import { CopyableCode } from "@botiverse/raft-ui";One line that people copy and run elsewhere: the command that connects a computer, installs the CLI or signs in. The command sits on a code surface with a copy button beside it; after a copy, the button shows a check for a moment.
When to use
Anatomy
CopyableCodeRoot: holds the command and the button, and handles the copy. Required.CopyableCode: the command. Its text is what gets copied. Required.CopyableCodeAction: the copy button, an icon Button. Required.
Variants
States
Behavior
- The button copies the text content of
CopyableCode.onCopyruns only after the copy succeeded. - Without
truncate, a long command wraps; with it, the command stays on one line and scrolls sideways.
Content
- Show the command exactly as people run it.
- When a copy fails, say so and say what to do: "Couldn't copy the command. Copy the text manually, or check the browser's clipboard permission."
Accessibility
CopyableCodeActionis labeled "Copy code" and "Copied code" by default, and announces the change (aria-live="polite"). Give it anaria-labelthat names what is copied: "Copy login command".- Tell the person about a failed copy in words, through
onError(a Toast or a status line). The icon alone doesn't say it failed. - The command is a
codeelement, so screen readers read it as text.
Rules
- Set the command in Space Mono,
text-mono-code, onlayer-codewith aline-hairlineborder. - Keep a command on one line: use
truncate, don't let it wrap. - Don't copy the
$prompt. Keep the prompt out ofCopyableCode, because everything in it is copied.
API
CopyableCode
Also takes the attributes of its element.
CopyableCodeAction
Also takes the attributes of its element.
CopyableCodeRoot
Also takes the attributes of its element.
Related
Changes
- 0.4.0 · Breaking Changes
CopyableCodeActionlabel props removed.ariaLabelandcopiedAriaLabelare gone; use the standardaria-labelprop instead. The default label still swaps between "Copy code" and "Copied code". ([b3786da](https://github.com/botiverse/rui/commit/b3786da)) - 0.1.0 · Breaking ChangesFlattened
CopyableCode: the preset andCopyableCode.Codecompound API are removed. ComposeCopyableCodeRoot,CopyableCode, andCopyableCodeAction;CopyableCodeCodePropsis gone and data-slots were renamed.