Install
Pull Code Block from the barrel for everyday use, or the granular path when you want a tighter bundle.
import { CodeBlock } from "@brika/clay";import { CodeBlock } from "@brika/clay/components/code-block";A minimal example
Drop this into a page. Native HTML attributes pass through to the underlying primitive.
'use client';
import {
CodeBlock,
CodeBlockActions,
CodeBlockContent,
CodeBlockCopyButton,
CodeBlockHeader,
CodeBlockInfo,
} from '@brika/clay/components/code-block';
const SAMPLE = `import { Button } from "@brika/clay/components/button";
export default function Save() {
return <Button>Save changes</Button>;
}`;
/** Syntax-highlighted code with a filename header and a copy-to-clipboard button. */
export default function CodeBlockDefaultDemo() {
return (
<CodeBlock className="w-full max-w-lg">
<CodeBlockHeader>
<CodeBlockInfo>
{({ filename, language }) => (
<span className="flex min-w-0 items-center gap-2 font-mono text-muted-foreground text-xs">
<span className="truncate">{filename}</span>
<span className="text-[0.625rem] uppercase tracking-wider">{language}</span>
</span>
)}
</CodeBlockInfo>
<CodeBlockActions>
<CodeBlockCopyButton />
</CodeBlockActions>
</CodeBlockHeader>
<CodeBlockContent language="tsx" filename="save.tsx" showLineNumbers={false}>
{SAMPLE}
</CodeBlockContent>
</CodeBlock>
);
}Code Block, every way
Multiple Files
Switch between several files with a header tab bar; each tab can carry a file-type icon.
No Header
Omit the header entirely and float the copy button over the code.
Select Files
A dropdown scales better than tabs when there are many files; each item can carry a file-type icon.
Accessibility
- Code blocks are non-interactive regions; Tab moves through the copy button, not character by character.
- Copy button carries
aria-label="Copy code"and should announce success state via a live region. - Multi-file blocks follow the WAI-ARIA tabs pattern (
role="tablist"/tab/tabpanel); Left/Right arrows switch files. - Syntax highlighting is visual only; AT reads the raw code text without colour cues.
Theme tokens
Every CSS variable Code Block reads, with its default and the
dotted path you'd write in a ThemeConfig JSON
to override it. Set any of these in your theme to retune Code Block
without touching component code.
Code Block tokens
17 tokens--code-block-bgcolorvar(--muted)components.codeBlock.bgCode block background.
--code-block-border-colorcolorvar(--border)components.codeBlock.borderColorBorder color of the code-block surface and the header divider.
--code-block-subtle-bgcolorcolor-mix(in oklch, var(--muted) 30%, transparent)components.codeBlock.subtleBgBackground of the `subtle` variant, a faded muted tint that drops the surrounding chrome.
--code-block-header-bgcolorcolor-mix(in oklch, var(--muted) 60%, transparent)components.codeBlock.headerBgBackground color of the code-block header strip (filename + actions row).
--code-block-gutter-bgcolorcolor-mix(in oklch, var(--muted) 40%, transparent)components.codeBlock.gutterBgBackground color of the line-number gutter on the left edge.
--code-block-gutter-bordercolorcolor-mix(in oklch, var(--border) 60%, transparent)components.codeBlock.gutterBorderColor of the divider between the line-number gutter and the code body.
--code-block-gutter-labelcolorvar(--muted-foreground)components.codeBlock.gutterLabelText color of the line numbers in the gutter.
--code-block-tab-labelcolorvar(--muted-foreground)components.codeBlock.tabLabelText color of an inactive file tab in the header (multi-file blocks).
--code-block-tab-active-labelcolorvar(--foreground)components.codeBlock.tabActiveLabelText color of the active file tab in the header (multi-file blocks).
--code-block-radiusradiusvar(--radius-control)components.codeBlock.radiusCode block corner radius.
--code-block-font-familyfont-familyvar(--font-mono)components.codeBlock.fontFamilyTypeface for code-block.
--code-block-font-sizefont-sizevar(--text-body-md)components.codeBlock.fontSizeFont size for code-block.
--code-block-font-weightfont-weight500components.codeBlock.fontWeightFont weight for code-block.
--code-block-line-heightline-height1.25components.codeBlock.lineHeightLine height for code-block.
--code-block-letter-spacingletter-spacing0components.codeBlock.letterSpacingLetter spacing for code-block. Useful for caps labels.
--code-block-text-transformtext-transformnonecomponents.codeBlock.textTransformText transform for code-block (`uppercase`, `lowercase`, `capitalize`, `none`).
--code-block-backdrop-blurblur0pxcomponents.codeBlock.backdropBlurBackdrop blur applied to the code-block surface. Set non-zero for a frosted-glass treatment.
Override in a theme
Authoring a theme is plain JSON. Drop overrides under
components.codeBlock, the names
are camelCase versions of the variable suffix.
{
"id": "my-theme",
"name": "My Theme",
"description": "...",
"accentSwatches": ["#000"],
"components": {
"codeBlock": {
"radius": "var(--radius-control)"
}
}
}
Then apply with applyTheme(myTheme)
(see the theming guide),
scope it to a subtree with themeToCssVars(myTheme, mode),
or consume any token directly in your own JSX with the matching Tailwind utility
(e.g. bg-code-block-…) — see the
chips on each token row.
API reference
Props specific to Code Block. Native HTML attributes pass through to the underlying primitive, see the component source on GitHub for the full type signature.
- stringActive file value on first render (uncontrolled). Required when using
CodeBlockTabs. - (value: string) => voidFires with the newly selected file value when the active tab changes.
- stringActive file value for multi-file blocks (controlled). Pair with
onValueChange. - VariantProps<typeof codeBlockVariants>['variant']Visual treatment; "subtle" drops the surrounding chrome.