Install
Run this in the app, after shadcn-vue init and the Beehexa theme (Button › Code):
npx shadcn-vue@latest add https://beehexa.design/r/code-block.json
Use
<script setup lang="ts">
import {
CodeBlock, CodeBlockActions, CodeBlockContent, CodeBlockCopyButton,
CodeBlockHeader, CodeBlockLine, CodeBlockTitle, CodeBlockToken, useHighlightedCode,
} from '@/components/ui/code-block'
const code = 'npm install @beehexa/design-tokens'
const lines = useHighlightedCode(code, 'bash')
</script>
<template>
<CodeBlock>
<CodeBlockHeader>
<CodeBlockTitle>Install</CodeBlockTitle>
<CodeBlockActions>
<CodeBlockCopyButton :value="code" label="Copy command" />
</CodeBlockActions>
</CodeBlockHeader>
<CodeBlockContent>
<CodeBlockLine v-for="(line, i) in lines" :key="i">
<CodeBlockToken v-for="(token, j) in line" :key="j" :token="token" />
</CodeBlockLine>
</CodeBlockContent>
</CodeBlock>
</template>
Languages load when first used. Add one to languages in highlighter.ts; a language not listed shows as plain text.
Props
| Part | Prop | Values | Notes |
|---|---|---|---|
CodeBlock |
variant |
default, destructive |
|
CodeBlock |
size |
default, sm |
sm tightens the padding; the text stays font.code.default |
CodeBlockContent |
lineNumbers |
boolean | Numbers are a CSS counter, never copied |
CodeBlockContent |
startLine |
number | First line number. Default 1 |
CodeBlockContent |
wrap |
boolean | Wraps long lines instead of scrolling sideways |
CodeBlockLine |
variant |
default, added, removed, highlighted |
|
CodeBlockCopyButton |
value |
string | The text copied |
CodeBlockCopyButton |
label, copiedLabel |
string | Name and tooltip, before and after copying. Default “Copy”, “Copied” |
CodeBlockCopyButton |
variant, size |
Button values | Default ghost, icon-xs |
useHighlightedCode(code, language) |
ref or getter | Returns the tokens of each line; only new lines are tokenized while code streams |
Built on
The shadcn-vue Code Block, with shiki for highlighting. Beehexa replaces shiki’s two fixed GitHub themes with one theme of CSS variables that fall back to the editor.syntax.* roles, so colours follow the theme. The copy button is an Icon button named by a tooltip, with label and copiedLabel for translated text.
Limitations
size="sm"keeps the 14 px code font: there is no smaller code role.- Beehexa has six syntax roles; shiki’s functions, parameters and type names share
editor.syntax.type.