DocumentationComponentsTheme CreatorGitHub
Theme CreatorGitHubIntroduction
InstallationUsageTheming
ComponentsAccordionAction SheetAlertAlertDialogArea ChartAspectRatioAvatarBadgeBannerBar ChartBottom NavBreadcrumbButtonButtonGroupCalendarCardCarouselChartChatBubbleChatBubbleNewCheckboxChipCoachMarkCodeBlockCollapsibleColor PickerComboboxCommandContainerContextMenuDate PickerDividerDrawerDropdown MenuEmptyStateFABFieldFieldsetFile UploadFlexFormGridHoverCardIconButtonLabelLine ChartLinkMenubarMeterModalNavigation MenuNumberFieldOTP InputPaginationPickerPie ChartPopoverProgressPromptInputRadar ChartRadial ChartRadioRatingScroll AreaSearchSegmentedControlSelectShortcutSidebarSkeletonSliderCircularSliderMediaTrimmerSpacerSpinnerSplit ButtonStackStatusStepperSurfaceSwitchTableTabsTextareaTime PickerToastToggleButtonToggleGroupTokenizerToolbarTooltipTop Header DesktopTop Header Mobile
Contributing
Components

CodeBlock

Syntax-highlighted code display with single-file and multi-tab modes, a copy button, line highlighting, wrap and collapse โ€” on a self-contained neutral plate that can follow or lock its theme.

Playground

Installation

pnpm add @tessinaui/ui react-syntax-highlighter @types/react-syntax-highlighter

Usage

import { CodeBlock } from "@tessinaui/ui";
<CodeBlock
  language="typescript"
  filename="utils.ts"
  code={`export const add = (a: number, b: number) => a + b;`}
/>

When to use โ€” and when not to

CodeBlock displays static code: a snippet in docs, an install command, an API example, a code answer in an AI chat. It highlights, copies, wraps, collapses and tabs between files, and it paints its own neutral plate so it reads on any surface.

  • Live terminal / log streams โ€” a scrolling console with timestamps and filters is a log viewer, not a code block. Render the stream in its own component.
  • Diffs โ€” added/removed rows with dual gutters and split/unified views are their own control; a CodeBlock shows a snapshot, not a change.
  • Inline code inside a sentence โ€” use a <code> element (or an inline Code component); CodeBlock is always a block.

Examples

Default

A single-file code block with a filename and copy button.

Command

Hide the header with showHeader={false} for a bare snippet โ€” an install command or a one-liner โ€” with the copy control floating over the code. This is the dominant shape in developer docs.

Multi-tab

Provide tabs to switch between multiple files, each with its own language and copy state. The tab bar is one keyboard tab stop; arrow keys move between files.

Package managers

The tabs pattern is how a docs page offers the same command for npm, pnpm, yarn and bun.

Line highlighting

Highlight specific lines with highlightLines, paired with showLineNumbers for clarity.

Collapsible

Cap the height with maxHeight to reveal an expand/collapse toggle for long blocks. showMoreLabel / showLessLabel relabel the toggle.

Wrap

By default a long line scrolls horizontally. Set showLineWrap to wrap it instead โ€” useful for prose-like commands where horizontal scrolling hides the tail.

Sizes

Three sizes โ€” sm, md, and lg โ€” scale the whole block: code padding, the code type scale, and the chrome around it (header height, filename, copy control, tab bar, expand row). Type follows the shared data-display ladder, with the header one step below the code it labels.

Header actions

Pass any controls to headerActions โ€” a download button, an "open in playground" link, a language Select โ€” and they sit in the header before the copy button.

Theme

The plate is self-contained. theme="auto" (default) follows the page; theme="dark" or theme="light" locks it โ€” the dark-code-on-a-light-docs-page convention.

Loading

CodeBlockSkeleton renders a placeholder that matches the block's box while code is being fetched.

Language identifiers

language accepts any identifier supported by Prism. Common values:

typescript ยท tsx ยท javascript ยท jsx ยท bash ยท shell ยท python ยท css ยท scss ยท json ยท yaml ยท markdown ยท html ยท sql ยท rust ยท go

Pass "text" or omit language in a tab to display plain text with no highlighting.

API Reference

CodeBlock

Either code + language (single-file) or tabs (multi-file) is required. The root forwards className and any other div attributes (data-*, id, aria-*).

PropTypeDefaultDescription
codestringโ€”Code string โ€” single-file mode
languagestringโ€”Prism language identifier
filenamestringโ€”Shown in the header; when omitted the language badge is used
highlightLinesnumber[][]1-indexed line numbers to highlight
tabsCodeBlockTab[]โ€”Multi-tab mode โ€” replaces code, language, filename
theme"auto" | "light" | "dark""auto"auto follows the page; light / dark lock the plate
size"sm" | "md" | "lg""md"Padding, code type scale, and header/tab/expand chrome
rounded"none" | "sm" | "md" | "lg" | "full""lg"Corner radius โ€” full caps at the panel radius
showLineNumbersbooleanfalseRenders the line-number gutter
showLineWrapbooleanfalseWrap long lines instead of scrolling horizontally
showHeaderbooleantrueSingle-code mode only โ€” when false the copy control floats
showLangBadgebooleantrueShow the language badge when no filename is set
headerActionsReactNodeโ€”Extra controls in the header, before the copy button
maxHeightstring | numberโ€”Caps block height and adds an expand/collapse toggle
showMoreLabelstring"Show more"Expand-control label when collapsed
showLessLabelstring"Show less"Expand-control label when expanded
defaultCollapsedbooleantrueInitial collapsed state when maxHeight is set
collapsedbooleanโ€”Controlled collapsed state
onCollapsedChange(collapsed: boolean) => voidโ€”Fires when the expand/collapse button is clicked

CodeBlockSkeleton

Mirrors the block's box (ยง2b). Takes size, rounded, theme, plus lines (default 6), showHeader, showFilename, showLangBadge, showLineNumbers and maxHeight, and forwards className + div attributes.

CodeBlockTab

interface CodeBlockTab {
  name: string;              // Label shown in the tab button
  code: string;              // Code content for this tab
  language?: string;         // Prism language (defaults to "text")
  highlightLines?: number[]; // 1-indexed lines to highlight in this tab
}
CoachMarkCollapsible

On this page

PlaygroundInstallationUsageWhen to use โ€” and when not toExamplesDefaultCommandMulti-tabPackage managersLine highlightingCollapsibleWrapSizesHeader actionsThemeLoadingLanguage identifiersAPI ReferenceCodeBlockCodeBlockSkeletonCodeBlockTab