All components (204)
Code block
Data · CodeBlock
What it is and when to use it
A code block with its header (the file name or whatever it is), line numbers if requested, highlighted lines and a copy button. It does not color the syntax, on purpose: that would be a whole highlighter as a dependency.
When to use it
- Documentation, integration examples, API responses, terminal commands.
titlefor what it is ("LineaDeCarrito.tsx", "Response", "Terminal") andlanguageas a small label next to it.numberLinesandhighlight(line numbers, starting at 1) when specific lines are going to be discussed.withoutCopyremoves the copy button.
When not to
- A single piece of data to copy (an IBAN, a tracking code):
Copyable. - A single-use code that gets typed in:
CodeField.
Keyboard: Tab reaches the copy button and then the block itself, which is focusable: with focus inside, the arrow keys scroll it horizontally to read long lines.
Accessibility: the block is named by its title ("Code" if there is none) and the button by what it copies ("Copy LineaDeCarrito.tsx"). When copying, it says so with text in a role="status" ("Code copied"), and if the clipboard fails it says that too ("Could not copy") instead of pretending. The line numbers and the language label are not read.
Fine-tuning: CSS variables --amset-block-code-*: -font, -gap, -language, -line, -number, -padding, -radius, -title. The size changes the code font size, the padding and the gap of the line number.
What it looks like
npm install @amset/uinpx amset-ui theme<CodeBlock title="Install" language="bash" code={'npm install @amset/ui'} />Props
Import it with import { CodeBlock } from '@amset/ui'. Required props are marked.
| Prop | Type | What it does |
|---|---|---|
coderequired | string | — |
className | string | Merged with the library classes; it does not replace them. |
highlight | readonly number[] | Lines (starting at 1) that are highlighted. |
language | string | It is only a label: syntax is not colored here. |
numberLines | boolean | — |
size | "sm" | "md" | "lg" | — |
title | string | What appears in the header: a file name, "Response", "Terminal". |
withoutCopy | boolean | Removes the copy button. |
It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.
In the test bench
Every state and variant, to try one at a time, on its page at ui.amset.tech:
