01 Software

UI

CodeBlock

Shiki syntax-highlighted code block

CodeBlock

A syntax-highlighted code block component powered by Shiki. Supports server pre-rendering, copy button, and line numbers.

Basic Usage

import { CodeBlock } from '@01.software/sdk/ui/code-block'

<CodeBlock code="const x = 1" language="typescript" />

Props

PropTypeDefaultDescription
codestringCode string to highlight (required)
languagestring'typescript'Language identifier (e.g. 'typescript', 'python', 'json')
themeBundledTheme'github-dark'Shiki theme
classNamestringWrapper CSS class
initialJSX.ElementPre-rendered JSX from server via highlight()
showLineNumbersbooleanfalseShow line numbers
showCopyButtonbooleantrueShow copy button

Server Pre-rendering (Next.js)

Pre-render with highlight() in a server component for instant display on the client:

import { CodeBlock, highlight } from '@01.software/sdk/ui/code-block'

// Server Component
async function CodeExample() {
  const code = 'const greeting = "Hello"'
  const initial = await highlight(code, 'typescript')
  return <CodeBlock code={code} language="typescript" initial={initial} />
}

As RichTextContent Block

import { RichTextContent } from '@01.software/sdk/ui/rich-text'
import { CodeBlock } from '@01.software/sdk/ui/code-block'

<RichTextContent
  data={content}
  blocks={{
    Code: ({ node }) => (
      <CodeBlock code={node.fields.code} language={node.fields.language} />
    ),
  }}
/>

Exports

ExportDescription
CodeBlockMain component
CodeBlockPropsProps type
highlight(code, lang, theme?)Server pre-render function
BundledThemeShiki theme type

On this page