CodeBlock
Theme-aware syntax highlighting with a plain-code fallback while Shiki loads.
import { CodeBlock } from "phoundry-ui";const message = "Hello";API
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
coderequired | string | — | Source code to display; surrounding whitespace is trimmed. |
lang | string | 'svelte' | Shiki language. ts and js resolve to typescript and javascript. |
colorSchemeRoot | HTMLElement | null | null | Element whose computed Theme variables supply syntax colors; defaults to document.documentElement. |
class | ClassValue | — | Additive classes on the stable root. |
style | string | — | Inline styles on the stable root. |
Styling
The stable root hook is .ph-code-block for both the fallback pre and the highlighted wrapper div. class and style target that root. data-highlighted is false while plain code is displayed and true when Shiki’s markup is ready. The fallback and generated markup use local vanilla CSS; only generated pre and code descendants require bounded global selectors. --ph-code-block-font customizes the code font and defaults to the existing system monospace stack. Syntax colors follow the active named Theme; highlighting reacts to Theme changes and ignores stale async results.
Replace .phi-code-block and .phi-code-block-fallback identification hooks with .ph-code-block and data-highlighted. Internal part selectors and Shiki’s DOM are not stable customization hooks.