What it does
Each Code Block renders a bordered surface with a header that shows an optional language label and a copy button, followed by a scrollable <pre> block.
Use the showHeader and showLang props to toggle visibility of the header bar and the language badge independently.
Composition and API
Pass code as a string prop. Toggle line numbers with showLineNumbers and control clipboard behavior with enableClipboard.
Forward refs where you attach measurements or analytics. The component stamps data-slot attributes on every child element for easy custom styling.
Common use cases
- Documentation sites showing code samples with language labels.
- Blog posts that embed syntax-highlighted snippets.
- API response viewers that display JSON or XML payloads.
- CLI output panels in web-based terminal emulators.
Accessibility
The copy button is a native <button> with accessible labels. Line numbers are rendered as spans inside the <pre> element for screen reader compatibility.
This preview page exposes a single h1 in the hero for a clean outline.
Next.js integration notes
Colocate examples under the App Router, keep server and client boundaries explicit, and avoid pulling interactive overlays into unexpected server layouts.
Set NEXT_PUBLIC_SITE_URL so canonical and Open Graph URLs resolve on deploy.
FAQ
Does the Code Block component work with Next.js App Router?
Yes. Import it like any other React component; it is a client component that uses hooks for clipboard functionality, so keep it in client boundaries.
Can I customize the code block appearance with Tailwind CSS?
Zentauri UI exposes appearance variants (default, subtle, contrast, glass) and size options. You can further extend styles with className or override the underlying --zui-code-block-* CSS variables.
Does the Code Block component include syntax highlighting?
The component displays raw code text without a syntax highlighter. Pair it with a library like Prism or Shiki for tokenized highlighting in your application.