Magoo Component UI logo Magoo Component UI
← Catalog

Code Sample Tabs

code-sample-tabs organism experimental

A tabbed multi-language code block - switch languages with an ARIA tablist and copy the active sample with one click.

Also in: Navigation

The width preview needs a screen wider than the chosen width — use a larger device (or a desktop browser) to see the desktop and tablet layouts.

Default
curl https://api.example.com/v1/orders \
  -H "Authorization: Bearer sk_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "amount": 1999, "currency": "usd" }'
const res = await fetch("https://api.example.com/v1/orders", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${apiKey}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ amount: 1999, currency: "usd" }),
});
const order = await res.json();
import requests

res = requests.post(
    "https://api.example.com/v1/orders",
    headers={"Authorization": f"Bearer {api_key}"},
    json={"amount": 1999, "currency": "usd"},
)
order = res.json()
TwoLanguages
curl https://api.example.com/v1/me \
  -H "Authorization: Bearer sk_live_..."
import requests

res = requests.get(
    "https://api.example.com/v1/me",
    headers={"Authorization": f"Bearer {api_key}"},
)

Props

NameTypeReq
label string
samples array ✓

Related components

How to use

Layout and the initial visible panel are pure markup (the active sample carries data-active=true, and inactive panels are hidden by a data-[active=false]:hidden utility), so a panel renders in screenshots with no JavaScript. behavior.js wires the interaction: clicking a tab - or arrowing Left/Right/Home/End across the tablist - activates it and reveals its panel; the copy button reads the active panel's code, calls navigator.clipboard.writeText, and briefly shows "Copied!". It dispatches a code-sample-tabs:change event (detail.index) on switch. The portable self-init reads everything from the DOM - no props object is passed.

Use cases

navmedia WCAG AA SEO 35 dir: ltr ai-generated