Zero-config syntax highlighting for React. Built exclusively for the BertUI ecosystem.
The simplest way to add beautiful, functional code blocks to your BertUI applications. Dark theme by default, copy button included, zero configuration required.
β οΈ BertUI Compatibility Note: bertui-code v1.0.1 is tested with BertUI's strict transpiler. See the BertUI Compatibility section for details.
- Zero-config by default - Just wrap your code
- Multiple themes - Dark, light, pink + custom colors
- Built-in copy button - One click to copy any code
- Line numbers - Optional, beautifully aligned
- Inline code snippets - Perfect for documentation
- 20+ language support - Auto-detection included
- Multi-variant tabs - Toggle between npm/pnpm/bun/yarn and more
- Zero dependencies - Except React (peer dependency)
- BertUI-certified - Tested with BertUI's strict transpiler
bun add bertui-code@1.0.1
npm install bertui-code@1.0.1
import { Code, InlineCode, CodeVariants, CodeVariant } from 'bertui-code';
// Basic code block
const hello = "world";
console.log(hello);
// With line numbers
function calculate(a, b) {
return a + b;
}
// Package manager variants (NEW in v1.0.1!) npm install bertui-code pnpm add bertui-code bun add bertui-code yarn add bertui-code
// Inline code
Use the useState hook for state management.
```Toggle between different versions of the same code snippet with zero config:
npm run dev pnpm dev bun dev yarn devFeatures:
- β Auto-generates tabs from labels
- β Theme-aware styling (dark/light/pink)
- β
Sticky tabs for long docs (
stickyTabs={true}) - β
Configurable tab position (
tabPosition="bottom") - β Keyboard accessible, ARIA compliant
bertui-code v1.0.1 is certified for BertUI's strict transpiler. Follow these rules and it will never crash:
// β GOOD - BertUI never looks inside string variables const myCode = 'function hello(name) {\n' + ' return "Hello " + name + "!";\n' + '}';
{myCode}
// β GOOD - Even JSX/TypeScript works in strings! const tsCode = 'interface User {\n' + ' id: string;\n' + ' name: string;\n' + '}\n';
{tsCode}
// β BAD - BertUI WILL crash with "Expected } but found :"
{function hello() { return "world"; }}
### β
**DO: Use React.createElement pattern**
// β
GOOD - Works in BertUI
import React from 'react';
export default function Page() {
return React.createElement(Code, {
language: 'javascript',
showLineNumbers: true
}, 'const x = 1;');
// β
GOOD - Always use ={true}
<CodeVariants stickyTabs={true}>
// β BAD - BertUI crashes on shorthand
### π **BertUI Compatibility Checklist**
| Pattern | Status | Why |
|---------|--------|-----|
| `const code = '...'` | β
**SAFE** | Strings are opaque to BertUI |
| `` <Code>{`code`}</Code> `` | β **CRASH** | BertUI parses template literal content |
| `language="typescript"` | β οΈ **MAY CRASH** | Only safe if code is in string variable |
| `stickyTabs={true}` | β
**SAFE** | Explicit value works |
| `stickyTabs` | β **CRASH** | Shorthand props not supported |
| `React.createElement` | β
**SAFE** | No JSX transform needed |
---
## π¨ **Themes & Colors**
### Built-in Themes
```jsx
<Code theme="dark"> // Default
<Code theme="light"> // Light mode
<Code theme="pink"> // Pink mode
<Code colors={{ background: '#0a0a0a', text: '#00ff00', header: '#1a1a1a', border: '#00ff00', meta: '#00ff00', button: '#00ff00' }}
// Custom hacker theme
| Prop | Type | Default | Description |
|---|---|---|---|
children |
string |
Required | The code to display |
language |
string |
'javascript' |
Programming language |
theme |
'dark' | 'light' | 'pink' |
'dark' |
Color theme |
colors |
Object |
{} |
Custom color overrides |
showLineNumbers |
boolean |
false |
Show line numbers |
showCopyButton |
boolean |
true |
Show copy button |
className |
string |
'' |
Additional CSS classes |
| Prop | Type | Default | Description |
|---|---|---|---|
children |
CodeVariant[] |
Required | Array of variants |
theme |
'dark' | 'light' | 'pink' |
'dark' |
Color theme |
defaultVariant |
number | string |
0 |
Default tab by index or label |
stickyTabs |
boolean |
false |
Make tabs sticky on scroll |
tabPosition |
'top' | 'bottom' |
'top' |
Tab bar position |
showCopyButton |
boolean |
true |
Show copy button |
colors |
Object |
{} |
Custom colors for code |
tabColors |
Object |
{} |
Custom colors for tabs |
| Prop | Type | Default | Description |
|---|---|---|---|
children |
string |
Required | The code for this variant |
label |
string |
Required | Tab label (npm, pnpm, etc) |
language |
string |
'javascript' |
Language for this variant |
showLineNumbers |
boolean |
false |
Show line numbers |
| Prop | Type | Default | Description |
|---|---|---|---|
children |
string |
Required | The inline code |
theme |
'dark' | 'light' | 'pink' |
'dark' |
Color theme |
// code-examples.js export const npmExample = 'npm install bertui-code'; export const jsExample = 'function add(a, b) {\n' + ' return a + b;\n' + '}';
// page.jsx
import { jsExample } from './code-examples.js';
{jsExample}
const longCode = 'import React from "react";\n' + '\n' + 'export function Button({ children }) {\n' + ' return (\n' + ' \n' + ' {children}\n' + ' \n' + ' );\n' + '}\n';
// β GOOD - In a .ts file export const tsCode = 'const name: string = "John";';
// β BAD - In a .jsx file const tsCode = 'const name: string = "John";'; // BertUI may crash!
// test-page.jsx - Create a test page to verify BertUI compatibility import { Code } from 'bertui-code'; const testCode = 'console.log("Hello BertUI!");';
export default function TestPage() { return React.createElement(Code, {}, testCode); }
npm install bertui-code pnpm add bertui-code bun add bertui-code yarn add bertui-code {javascriptExample} {typescriptExample} {pythonExample} {curlExample} {fetchExample} {axiosExample}
Cause: TypeScript syntax in .jsx file or template literal in JSX Fix: Move code to string variable outside component
Cause: BertUI doesn't support React 18 automatic JSX runtime
Fix: Use React.createElement or add /** @jsx React.createElement */
Cause: BertUI doesn't support {stickyTabs} shorthand
Fix: Always use stickyTabs={true}
bertui-code/ βββ src/ β βββ Code.js # Main code block component β βββ CodeVariants.js # Multi-variant tabs (NEW) β βββ CodeVariant.js # Individual variant (NEW) β βββ CopyButton.js # Copy button component β βββ InlineCode.js # Inline code component β βββ ThemeProvider.js # Theme context (optional) β βββ index.js # Main exports βββ dist/ # Built files βββ package.json # v1.0.1 βββ README.md # You are here
- BertUI: β v1.0.1 certified - Tested with strict transpiler
- React: β 18.0.0+ (peer dependency)
- Browsers: β Chrome, Firefox, Safari, Edge
- Bun: β Recommended package manager
MIT Β© Pease Ernest
Part of the BertUI ecosystem
Built with β€οΈ for developers who value simplicity and speed
GitHub β’ npm β’ BertUI Compatibility
v1.0.1 β’ Zero-config β’ BertUI-certified