Code Tabs
Tabbed code snippets with per-tab copy and a localStorage-synced tab choice.
Import
import { CodeTabs } from "@cronus-ui/ui";
npx cronus-ui add code-tabs
Examples
.cronus
The same component declared in Cronus. Emitted at build time from the audit fixtures — the kernel renders it as HTML with no React.
default.cronus
app "audit-fixtures" {
port 5176
}
style {
preset aurora
theme dark
}
component CodeTabsDefault layout:inline style:code-tabs {
aria-label:"Install"
label "Install"
text "bun"
text "npm"
}
page "/audit/code-tabs/default" type:custom {
use CodeTabsDefault
}
API Reference
Generated from the component's exported types.
CodeTabsProps
Extends Omit<HTMLAttributes<HTMLDivElement>, "children" | "defaultValue" | "dir" | "onChange">
| Prop | Type | Default | Description |
|---|---|---|---|
items* | CodeTabsItem[] | — | The snippets to switch between — one tab + one panel per item. |
defaultLabel | string | — | Label selected on first render. Falls back to the first item when omitted or unknown. When is set, a stored choice (applied after mount) wins over this. |
storageKey | string | — | Persist the chosen label to `localStorage` under this key and keep every `CodeTabs` sharing the key in sync — across the page *and* across browser tabs. The stored value is only read after mount, so server-rendered HTML and the first client render always agree (no hydration mismatch). |
onLabelChange | (label: string) => void | — | Called with the newly selected label on user-initiated changes. |
className | string | — | Additional class names merged onto the root. |
id | string | — | DOM id of the root element. |