skip section navigation

Codegroup

Codegroup presents related code alternatives as tabs. use it when someone needs one version of the same step, rather than making them scroll past every package manager’s command.

npm
npm install @ciabi/loafkit-ui

usage

svelte
<script>
	import { Codegroup } from '@ciabi/loafkit-ui';
	const entries = [
		{ label: 'npm', language: 'sh', code: 'npm install @ciabi/loafkit-ui' },
		{ label: 'pnpm', language: 'sh', code: 'pnpm add @ciabi/loafkit-ui' }
	];
</script>

<Codegroup {entries} aria-label="Install Loafkit" />

entries

name the tablist for the alternatives it contains. selection stays inside the component; there is no selected-entry binding.

Left and Right arrows move between tabs, and Home and End reach the first and last. each tab controls its named panel. only the active entry mounts a Codeblock, whose copy action copies that entry’s source.

API reference

Codegroup

Component
entries
Default: []

the alternative code examples, one tab per entry.

aria-label
Default: 'Code examples'

the tablist’s accessible name.

class
Default: ''

extra classes on the component root.

style

inline styles on the component root.

CodegroupEntry

Type

one entry supplied to Codegroup.

label

tab label and fallback code-panel title.

code

literal source for this alternative.

language

highlighting language; Codeblock falls back to plaintext.

filename

code-panel title, replacing the entry label.