Code Block
A content-aware code container with syntax highlighting and copy functionality. Supports custom slot headers for package manager tabs.
Installation
npx raya-ui@latest add code-blockFile Structure
your-project
components
ui
code-block
CodeBlock.vue
API Reference
Props
codestringThe raw code string to highlight and display.
langstring"typescript"Language for syntax highlighting.
fileNamestringundefinedOptional text to display in the header bar. Omitted if the #header slot is used.
Slots
#headerCustom content for the header bar (e.g., placing AnimatedTabs inside). Completely overrides the fileName prop.
app.ts
function greet(name: string) {
return `Hello, ${name}!`;
}
console.log(greet('Raya UI'));Settings
source-code.vue
<script setup lang="ts">
import { CodeBlock } from '@/components/ui/code-block'
const code = `function greet(name: string) {
return `Hello, ${name}!`;
}
console.log(greet('Raya UI'));`
</script>
<template>
<CodeBlock
:code="code"
file-name="app.ts"
/>
</template>