Multi-Language Code Tabs
A terminal-styled code panel with a row of language tabs above it. Clicking a tab swaps in that language's code sample for calling the same example endpoint, updates the window header's filename, and highlights the active tab. A copy button always copies whichever sample is currently showing.
Docs
Installation
A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its button dependencies and any missing npm packages, and installs them straight into your project.
npx shadcn add https://staaarter.com/r/multi-language-code-tabs.jsonPrefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/devtools/devtools29.tsx instead.
Usage
The file also exports devtools29Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.
import { Devtools29, devtools29Demo } from "@/components/blocks/devtools/devtools29"; export default function Page() { return <Devtools29 {...devtools29Demo} />; }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| heading | string | "Call it from anywhere" | Section heading. |
| description | string | "The same endpoint, called from four different languages." | Section intro text below the heading. |
| samples | CodeSample[] | none | One entry per language tab, rendered in the order given. |
| className | string | none | Extra classes for the outer section element. |
Types
type CodeToken = { text: string; tone?: "keyword" | "string" }; type CodeSample = { language: string; fileName: string; /** Canonical text copied to the clipboard; `lines` is a hand-highlighted rendering of this same text. */ code: string; lines: CodeToken[][]; };
Behavior notes
- Tab switching is real client-side state: clicking a language tab updates which sample is active, re-renders the code panel with that sample's lines, updates the window header's filename to that sample's fileName, and marks the clicked tab visually active via aria-selected.
- The copy button is real (navigator.clipboard.writeText) and always copies the active sample's code field, the canonical plain-text version, not the highlighted lines markup. Copied state resets to the icon whenever you switch tabs.
- Syntax coloring is a simplified manual approximation, not a real tokenizer: each sample's lines array is a hand-authored list of text/tone spans ("keyword" or "string") that must already match the plain code string word-for-word. There is no lexer or language grammar involved, so if you edit code without also updating lines to match, the copied text and the on-screen text will silently diverge.
- Only a couple of tokens per line are ever tagged with a tone in the bundled samples, in keeping with that being a lightweight visual approximation rather than full syntax highlighting.
More DevTools Blocks
View all →api-endpoints-sample-call
API Endpoints With Sample Call
Reference list of API endpoints paired with a live sample request and response panel.
cicd-pipeline-status
CI/CD Pipeline Status
Recent CI/CD pipeline runs with per-stage status chips and overall run badges.
code-diff-viewer
Code Diff Viewer
Unified code diff panel with a file header change summary and colored addition/deletion lines.
keyboard-shortcuts-reference
Keyboard Shortcuts Reference
Grouped keyboard shortcut reference with keycap-styled key combos.
performance-waterfall
Performance Waterfall
Network request waterfall chart with cascading timing bars colored by duration.
service-health-board
Service Health Board
Infrastructure status board with a live summary strip and per-service uptime, latency, and health.