DOCS
v0.4

Components / Code Block

Code Block

Syntax-highlighted code display with filename tab, language chip, copy button, line numbers, and optional collapse for long blocks.

typographyv0.1.0

Playground

Examples

TypeScript with filename
<cg-code-block></cg-code-block>
Minimal (no filename)
<cg-code-block></cg-code-block>
Collapsible long block
<cg-code-block collapsible line-numbers></cg-code-block>

Import

import { CgCodeBlock } from '@cognivo/components';
// Or tree-shake: import '@cognivo/components/cg-code-block';

Per-component imports ship only that component (~8 kB gzip).

API Reference

PropTypeDefaultDescription
codestringCode content
languagestringLanguage label (also used for syntax highlighting heuristics)
filenamestringFilename shown in the header tab
line-numbersbooleanfalseShow line numbers gutter
wrapbooleanfalseSoft-wrap long lines instead of horizontal scroll
collapsiblebooleanfalseCollapse blocks longer than 15 lines with a "Show all" affordance
rounded"none" | "sm" | "md" | "lg""lg"Border radius variant