Skip to content

CodeTabs

The same code in several languages, one at a time. The choice is remembered across the site.

import CodeTabs from '@sypnia/ui/astro/CodeTabs.astro'

On this page
  1. One task, three ways
  2. One file, and its skeleton
  3. When to use it
  4. For everyone

One task, three ways

Choose Python: with sync="lang" every other set of the same group follows, on this page and the next ones.

TypeScript

const data = new Data({ token: process.env.SYPNIA_TOKEN });
const rows = await data.table('orders').rows({ limit: 20 });
Code
---
import CodeTabs from '@sypnia/ui/astro/CodeTabs.astro';
const ts = `const data = new Data({ token: process.env.SYPNIA_TOKEN });\nconst rows = await data.table('orders').rows({ limit: 20 });`;
const py = `data = Data(token=os.environ["SYPNIA_TOKEN"])\nrows = data.table("orders").rows(limit=20)`;
const sh = `curl https://data.sypnia.com/v1/tables/orders/rows?limit=20 \\\n  -H "Authorization: Bearer $SYPNIA_TOKEN"`;
---
<CodeTabs sync="lang" items={[{ label: 'TypeScript', lang: 'ts', code: ts, id: 'ts' }, { label: 'Python', lang: 'python', code: py, id: 'python' }, { label: 'curl', lang: 'sh', code: sh, id: 'curl' }]} />

One file, and its skeleton

CodeBlock names the file and lights lines (mark). CodeBlockSkeleton under it.

astro.config.mjs
import { defineConfig } from 'astro/config';

export default defineConfig({
  site: 'https://docs.example.com',
  integrations: [],
});
Code
---
// One file, with its name in the bar and two lines lit.
import CodeBlock from '@sypnia/ui/astro/CodeBlock.astro';
import CodeBlockSkeleton from '@sypnia/ui/astro/CodeBlockSkeleton.astro';
const code = `import { defineConfig } from 'astro/config';\n\nexport default defineConfig({\n  site: 'https://docs.example.com',\n  integrations: [],\n});`;
---
<div class="sy-stack" style="--gap:var(--s-4)">
  <CodeBlock code={code} lang="ts" title="astro.config.mjs" mark={[4]} />
  <CodeBlockSkeleton lines={4} />
</div>

When to use it

Use it when

  • An SDK in several languages, or a task done with the SDK, the CLI or the API.

Do not use it when

  • Package managers only: that is PackageTabs.
  • Code that is not the same thing in each tab.

For everyone

  • Tabs follow the WAI-ARIA pattern: arrow keys, Home and End.
  • Without JavaScript every version shows, each under its own name.
  • The copy button says «Copied» to screen readers too.
  1. One task, three ways
  2. One file, and its skeleton
  3. When to use it
  4. For everyone

    Search pages, sections and terms