Code snippet
Code snippet is used to display code or commands for user to copy and paste.
Example
Usage
Variants
The default variant, base, renders on a light gray background.
Use the white variant to add contrast against a gray background. Typically used with forms.
With label
Without label
Without copy button
Guidelines
When to use
- When displaying a block of code or a command for user to copy and paste.
When not to use
- If referencing a code term inside a sentence, use a code component instead.
Props
| Name | Default | Description |
|---|---|---|
variant | "base" | "base" | "white"The variant determines the background color of the code snippet. |
code | — | stringCode snippet. |
label | — | stringLabel to show above the code snippet. |
hasCopyButton | true | booleanWhether to show a copy button. |