Code snippet
Syntax-highlighted source with copy-to-clipboard. Same WC powers the snippets across all three framework demos.
TypeScript (auto-detected)
interface User { id: number; name: string;}function greet(user: User): string { return `Hello, ${user.name}!`;}export const me: User = { id: 1, name: 'Pieterjan' };Vue SFC (explicit language)
<script setup lang="ts">import { ref } from 'vue';const count = ref(0);</script><template> <button @click="count++">Clicked {{ count }} times</button></template>Line numbers
interface User { id: number; name: string;}function greet(user: User): string { return `Hello, ${user.name}!`;}export const me: User = { id: 1, name: 'Pieterjan' };Theming
The block follows the page's data-bs-theme with no wiring. Pass theme to pin it instead.
interface User { id: number; name: string;}function greet(user: User): string { return `Hello, ${user.name}!`;}export const me: User = { id: 1, name: 'Pieterjan' };interface User { id: number; name: string;}function greet(user: User): string { return `Hello, ${user.name}!`;}export const me: User = { id: 1, name: 'Pieterjan' };Per-line annotations
Tab reaches the active line, then the arrow keys move between line links and Home / End jump to the ends. Each line number is a real link, so middle-click still opens it.
1interface User {2 id: number;3 name: string;4}56function greet(user: User): string {Branches: 1 of 2 taken7 return `Hello, ${user.name}!`;8}910export const me: User = { id: 1, name: 'Pieterjan' };Use the up and down arrow keys to move between line links, Home and End for the first and last line.
const COVERAGE: CodeLineAnnotation[] = [ { line: 7, kind: 'uncovered', label: '0' },];<BsCodeSnippet code={source} language="ts" lineNumbers annotations={COVERAGE} activeLine={active} lineHref={(line) => `#L${line}`} onLineActivate={(e) => { e.preventDefault(); setActive(e.line); }}/>/* kind is opaque — colour it yourself: .coverage .annotation-uncovered { background: rgb(220 53 69 / 16%); } */Constrained size
Give the component a height or max-height and the listing scrolls vertically inside it; constrain the width and long lines scroll horizontally.
interface User { id: number; name: string;}function greet(user: User): string { return `Hello, ${user.name}!`;}export const me: User = { id: 1, name: 'Pieterjan' };<BsCodeSnippet className="sized-snippet" code={source} language="ts" lineNumbers />/* .sized-snippet { max-height: 220px; } — the code area scrolls inside it. */Usage
import { BsCodeSnippet } from '@mintplayer/react-bootstrap/code-snippet';export function Example() { return ( <BsCodeSnippet language="tsx" code={`const greet = (n: string) => \`hi, ${n}\`;`} /> );}