--- name: code-block-usage description: Instructions and guidelines for using the code-block components (CodeBlock, CodeBlockSource, InternalCodeBlock) within the sona-ui repository. --- # Code Block Components in Sona-UI This skill describes how to correctly utilize the suite of code-block components available within the `sona-ui` repository: `CodeBlock`, `CodeBlockSource`, and `InternalCodeBlock`. These components provide rich syntax highlighting using Shiki, line highlighting, and diff support. ## Available Components ### 1. `CodeBlock` Location: `src/components/code-block/code-block.tsx` This is the main foundational block that creates a context-aware boundary. It provides elements like tabs, header, line numbers, and floating copy capabilities. **Usage:** Use `CodeBlock` when you need maximum granular control over the UI, explicitly laying out headers, tabs, or applying specific stylings to the `
` wrapper.
```tsx
import { CodeBlock, CodeBlockHeader, CodeBlockPre, CodeBlockCode } from "@/components/code-block/code-block";
```
**Props:**
- `code` (string): The raw code to be highlighted.
- `language` (string): The syntax highlighting language (default: `javascript`).
- `floatingCopy` (boolean): Shows a floating copy button overlay.
- `highlightLines` (number[] | string): Array of line numbers to highlight differently.
- `focusLines` (number[] | string): Blurs out lines that are not in focus.
- `showDiff` (boolean): Indicates deleted/added lines using the `[data-diff]` lines internally.
---
### 2. `CodeBlockSource`
Location: `src/components/code-block/code-block-source.tsx`
This component takes a `filePath` (or falls back to `code` prop) to dynamically read the exact source code of a file from the disk and pass it down into the `CodeBlock`.
**Usage:**
Ideal for documentation pages where you want the code block to stay intrinsically synchronized with the file's current truth instead of manually copy-pasting code snippets into your TSX. **Requires usage within a server component since it performs filesystem reads (`readFileContent`).**
```tsx
import { CodeBlockSource } from "@/components/code-block/code-block-source";
// Usage in a server component
```
---
### 3. `InternalCodeBlock`
Location: `src/components/code-block/internal-code-block.tsx`
A pre-wired abstraction perfectly suited for simple code block rendering without boilerplate.
**Usage:**
When you just want to pass `code`, `language`, and `filename` and get a standard block structure.
```tsx
import { InternalCodeBlock } from "@/components/code-block/internal-code-block";
```
---
## Technical Dependencies
When modifying or working with these components, be aware of the following cross-dependencies:
- **Shiki:** Handles syntax highlighting dynamically.
- **Base UI:** Components like `