Skip to main content

Overview

The CodeBlock component displays syntax-highlighted code using Shiki. Features a custom dark theme optimized for the Gadget design system.
This is a client component ("use client") and uses React hooks for syntax highlighting.

Import

Basic Usage

Props

string
required
The source code to display.
string
required
The programming language for syntax highlighting. Supports any Shiki BundledLanguage (typescript, javascript, python, etc.).
string
Optional title displayed in a header above the code block.
boolean
default:"false"
Whether to display line numbers.
string
Additional CSS classes to apply.
The CodeBlock component extends HTMLAttributes<HTMLDivElement>, so all standard div attributes are supported.

Examples

With Title

With Line Numbers

Multiple Languages

Theme

The CodeBlock uses a custom “gadget-dark” theme with the following syntax colors:
  • Comments: #55556A (muted gray)
  • Keywords: #7C6FFF (purple)
  • Strings: #22C55E (green)
  • Functions: #C4B5FD (light purple)
  • Numbers: #F59E0B (orange)
  • Variables: #F2F2F5 (foreground)
  • Types: #7C6FFF (purple)
  • Constants: #EF4444 (red)
  • Object Keys: #C4B5FD (light purple)
Background: #0A0A0F (dark background)
Foreground: #F2F2F5 (light foreground)

Fallback Rendering

If Shiki fails to load or highlight the code, the component automatically falls back to a plain text rendering with the same styling structure.

Styling

  • Border with border-color
  • Dark background matching the theme
  • Rounded corners
  • Overflow-x-auto for horizontal scrolling
  • 12px (xs) font size with relaxed leading
  • 12px (3) padding

Component Definition

Location: packages/gadget-ui/src/components/code-block.tsx:56 The component uses useEffect to asynchronously highlight code with Shiki and update the rendered HTML.