Code Block
DisplaySyntax-highlighted code preview powered by Shiki, with copy button, line numbers, and line highlights.
Code BlockDisplay · Web
Loading Storybook preview…
Installation
bun add @otfdashkit/ui
Usage
Import Code Block from @otfdashkit/ui.
Code
// Code Block — Syntax-highlighted code preview powered by Shiki, with copy button, line numbers, and line highlights.
//
// Install:
// bun add @otfdashkit/ui
import { CodeBlock } from '@otfdashkit/ui'
export function Example() {
return (
<CodeBlock>
{/* your content */}
</CodeBlock>
)
}Props
Props declared in the CodeBlock source. Inherited HTML attributes are not listed.
| Prop | Type | Default | Description |
|---|---|---|---|
| coderequired | string | Source code to render. | |
| filename | string | Optional caption rendered above the code (e.g. file name). | |
| highlightLines | number[] | [] | 1-indexed line numbers to highlight (subtle row tint). Default []. |
| language | 'tsx' | 'ts' | 'jsx' | 'js' | 'bash' | 'css' | 'json' | 'yaml' | 'markdown' | 'tsx' | Highlight grammar. Must be in the bundled set. Default 'tsx'. |
| showLineNumbers | boolean | false | Show 1-indexed line numbers in a gutter. Default false. |
| theme | 'light' | 'dark' | 'auto' | 'auto' | Theme override. 'auto' (default) follows the closest `dark`/`light` ancestor class. |