Calm motion: animations on this site only fade, with no movement
CodeBlock
Copy button, line highlight, tabs per file
A listing the reader will copy from: an install command, an example, a config in two files. For two versions of the same text, use Diff. For a short inline mention, plain <code> is enough.
Basic
import { createApp } from "vue";
import { BlessButton } from "blessing-ui";
import "blessing-ui/tokens.css";
createApp(BlessButton).mount("#app");
pnpm add blessing-ui vue
- Pass
code(withlangandfilenamefor the header) orfilesfor tabs:[{ name, code, lang }]. Tabs switch with ← →, Home and End.v-model:activeis the open one. Copy takes the file you are looking at. lines="2,4-6"marks lines with a bar and a tint (1-based, and an array of numbers works too).line-numbersadds a gutter that is not read aloud and is left out when you select and copy.- Long lines scroll sideways.
wrapwraps them instead. The scroll area is reachable by keyboard. - It does not color syntax, and ships no highlighter. Fill the
#code="{ code, lang, lines }"slot with the output of Shiki, Prism or whatever you use. The header, tabs and copy button stay.linesthere is[{ n, text, hl }]if you want to keep the line marks. - Copy uses the clipboard API and falls back to a hidden textarea. The button says "Copied" for two seconds and screen readers hear it.
copyfires with the text, and:copy="false"removes the button.
Usage
ts
import { BlessCodeBlock } from "blessing-ui";API
Props
| Name | Type | Default | Description |
|---|---|---|---|
code | string | — | |
lang | string | — | |
filename | string | — | |
files | BlessCodeFile[] | — | several files as tabs; wins over `code` |
lines | string | number[] | — | lines to mark, e.g. `"2,4-6"` or `[2, 4, 5, 6]` (1-based) |
lineNumbers | boolean | — | |
copy | boolean | true | |
wrap | boolean | — | wrap long lines instead of scrolling sideways |
label | string | "Code" | |
labels | Partial<{ copy: string; copied: string; copiedLive: string; }> | — | |
active | number | 0 |
Events
| Name | Payload | Description |
|---|---|---|
copy | [code: string] | |
update:active | [value: number] |
Slots
| Name | Scope | Description |
|---|---|---|
code | { code: string; lang: string | undefined; lines: { n: number; text: string; hl: boolean; }[]; } |