一键导入
code-block-usage
Instructions and guidelines for using the code-block components (CodeBlock, CodeBlockSource, InternalCodeBlock) within the sona-ui repository.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Instructions and guidelines for using the code-block components (CodeBlock, CodeBlockSource, InternalCodeBlock) within the sona-ui repository.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | code-block-usage |
| description | Instructions and guidelines for using the code-block components (CodeBlock, CodeBlockSource, InternalCodeBlock) within the sona-ui repository. |
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.
CodeBlockLocation: 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 <pre> wrapper.
import { CodeBlock, CodeBlockHeader, CodeBlockPre, CodeBlockCode } from "@/components/code-block/code-block";
<CodeBlock code={"const x = 1;"} language="typescript" showDiff={false} highlightLines={[1]}>
<CodeBlockHeader filename="example.ts" />
<CodeBlockPre lineNumbers={true}>
<CodeBlockCode />
</CodeBlockPre>
</CodeBlock>
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.CodeBlockSourceLocation: 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).
import { CodeBlockSource } from "@/components/code-block/code-block-source";
// Usage in a server component
<CodeBlockSource filePath="src/components/button/button.tsx" language="tsx">
<CodeBlockPre>
<CodeBlockCode />
</CodeBlockPre>
</CodeBlockSource>
InternalCodeBlockLocation: 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.
import { InternalCodeBlock } from "@/components/code-block/internal-code-block";
<InternalCodeBlock
code="console.log('Hello');"
language="javascript"
filename="hello.js"
/>
When modifying or working with these components, be aware of the following cross-dependencies:
<Menu> and styling merge utilities (@base-ui/react/use-render, @base-ui/react/merge-props).lucide-react for standard UI icons and @icons-pack/react-simple-icons for language-specific glyphs.Tabs from @/components/tabs/tabsScrollArea from @/components/scroll-area/scroll-areaCopyButton from ../copy-button/copy-buttonreadFileContent from @/lib/file-utils (For CodeBlockSource)CodeBlockSource for internal code: When referencing files already within the sona-ui repository, use CodeBlockSource with absolute paths relative to root or workspace relative paths that readFileContent supports. This keeps documentation synced with reality.CodeBlockHeader, CodeBlockPre, CodeBlockLanguage, CodeBlockCode, etc., must be placed inside <CodeBlock>, as they consume context (like lines, nodes, code, showDiff).- and +, use showDiff and let the component's internal shiki parsing colorize the deltas appropriately via the standard patch formatting.If you need to bootstrap these components into another standalone project, full source code for the components is provided in the reference/ block of this skill.
Integrate a new component into the Sona UI library end to end — the full per-component pipeline of writing the component, demo, docs, registry entry, nav link, playground controls, regenerating the registry, and verifying it live. Use this whenever the user wants to add, create, scaffold, register, or "wire up" a new component in this repo (sona-ui), or mentions doing "the steps" / "the pipeline" to bring a component into the library — even if they only hand you the component code or just a name and an idea. Trigger it for phrases like "add a <name> component", "new component", "integrate this into the registry", "scaffold a component", or "set up the docs/playground for X".
Guidelines and rules for using the CodeBlockSource component, specifically handling how source files and code are read from the system in the Sona-UI repository.
Instructions and guidelines for using the component-preview and component-preview-server components within the Sona-UI repository. Includes details on registry fetching.