BankaiCodeBlock
A block code primitive: a native <pre><code> with a copy-to-clipboard button. For an identifier or short snippet inside a sentence, reach for the inline BankaiCode instead.
Example
Pass the snippet as the code prop — it is both what renders and the exact string the copy button writes. Click Copy to try it.
pnpm add @bankai-vue/core @bankai-vue/theme-bankai<template>
<BankaiCodeBlock language="ts" :code="snippet" />
</template>Bring your own highlighter
Core highlights nothing — it stays design- and tooling-agnostic. The language prop only reflects as a language-<lang> class on the <code>, the de-facto hook a highlighter (Shiki, Prism, highlight.js) or your own CSS keys off. To render already-highlighted markup, pass it through the default slot; the code prop stays the exact string the copy button writes, so the copied text is never the highlighter's wrapper markup.
Accessible copy
The copy button is a composed BankaiButton whose accessible name tracks its visible label; a successful copy is announced (and re-announced on a repeat copy) through a visually hidden role="status" live region. Override the copyLabel / copiedLabel props to set both the button text and the announcement for one block, use the copy slot (which receives the copied state) to swap in an icon, or set :copyable="false" to drop the button entirely. The copied state's duration is tunable per-block via copiedDuration (ms) and globally via BankaiConfig.codeBlockCopiedDuration (default 2000).
To localize the labels app-wide rather than per block, set a locale in the i18n config instead of the props — see the internationalization guide. A per-block prop always wins over the configured locale.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | — | The code as a string. It is the source of truth for the clipboard (the copy button writes exactly this) and, when the default slot is not used, the text rendered inside the <code>. |
language | string | — | Language identifier. Reflected verbatim as the language-<language> class on the <code> — the de-facto convention a BYO syntax highlighter (Shiki, Prism, highlight.js) or CSS keys off. Core itself highlights nothing. |
copyable | boolean | true | Render the copy-to-clipboard button (and its role="status" live region). Set false to omit it. |
copyLabel | string | — | The copy button's accessible name and its idle label text (when the copy slot is not used). Overrides the resolved codeBlock.copy message for this block; unset, it resolves through the global i18n config (BankaiI18nConfig ), defaulting to the English 'Copy'. |
copiedLabel | string | — | The button's label text after a successful copy (when the copy slot is not used) and the message announced by the role="status" live region. Overrides the resolved codeBlock.copied message for this block; unset, it resolves through the global i18n config (BankaiI18nConfig ), defaulting to the English 'Copied'. |
copiedDuration | number | — | How long (ms) the copy button stays in its "copied" state after a successful copy before reverting to idle. Overrides the global codeBlockCopiedDuration config (BankaiConfig ) for this block. |
Emits
This component emits no events.
Slots
| Slot | Description |
|---|---|
default | Rendered code body — an escape hatch for pre-highlighted markup (e.g. a BYO highlighter's output). When omitted, the raw code prop renders verbatim as text. Either way the copy button writes the code prop, so the copied text stays exact regardless of what is rendered. |
copy | Copy-button content. Receives the current copied state so a consumer can swap label/icon. When omitted, the button shows the copyLabel / copiedLabel text. |
Exposes
This component exposes nothing on its instance.
Theming
Every token is a :root custom property applied through zero-specificity :where() rules, so a single plain declaration overrides one — no selector, no !important. Set it globally on :root or locally on any ancestor.
| Token | Default | Purpose |
|---|---|---|
--bankai-code-block-bg | var(--bankai-color-surface) | Panel background. |
--bankai-code-block-font-family | var(--bankai-font-mono) | Monospace font stack. |
--bankai-code-block-font-size | var(--bankai-text-size-sm) | Code font size. |
--bankai-code-block-line-height | 1.6 | Code line height. |
--bankai-code-block-radius | var(--bankai-radius) | Panel corner radius. |
--bankai-code-block-padding-block | var(--bankai-space-8) | Vertical padding of the scrolling panel. |
--bankai-code-block-padding-inline | var(--bankai-space-8) | Horizontal padding of the scrolling panel. |
--bankai-code-block-copy-offset | var(--bankai-space-4) | Inset of the copy button from the top inline-end corner. |