Skip to content
Norn
Menu

norn-code-tabs

The same thing in a few forms, such as npm, yarn, and pnpm, as tabs over norn-code-blocks. Without a script every sample shows, stacked. Pass the samples in the default slot. Each tab is named by the sample's data-tab attribute, else its caption, else its label slot, else its language, all read from the markup. A name two samples share gets a number after the first, such as sh and sh 2, so every tab name is its own. The tabs follow the ARIA tabs pattern: arrow keys move between them, in the reading direction, and Home and End jump to the ends. Tabs that share a @group switch together, and the choice is remembered in this browser.

<norn-code-tabs> a container, from @allons-y/webc-patterns

Examples

Color scheme
Width

Open on its own

Source
<norn-code-tabs @group="package-manager">
	<template slot="label" webc:nokeep><span>Install commands</span></template>
	<norn-code-block data-tab="npm" @language="sh" @code="npm install --save-dev @example/project"></norn-code-block>
	<norn-code-block data-tab="yarn" @language="sh" @code="yarn add -D @example/project"></norn-code-block>
	<norn-code-block data-tab="pnpm" @language="sh" @code="pnpm add -D @example/project"></norn-code-block>
</norn-code-tabs>
Color scheme
Width

Open on its own

Source
<norn-code-tabs>
	<span slot="label">Config files</span>
	<norn-code-block @language="js" @caption="eleventy.config.js" :@code="'export default function (config) {\n\treturn {};\n}\n'"></norn-code-block>
	<norn-code-block @language="js" @caption="index.js" :@code="'import config from \'./eleventy.config.js\';\n'"></norn-code-block>
</norn-code-tabs>

Props

Write them with the @ prefix, and :@ for an expression.

NameTypeDescription
@group string Tabs with the same group, on any page, show the same choice.

Slots

NameDescription
default The samples, each a norn-code-block. For the terminal frame, give each sample @chrome="terminal": a slot can't take props from the tabs.
label The tab list's name, as one element, such as <span slot="label">Install commands</span>. Falls back to the site's componentStrings, then "Code samples".
sample A tab's name when its sample has no data-tab, caption, label, or language, with {n} for its number. Falls back to the site's componentStrings, then "Sample {n}".

Tokens

The global tokens from tokens.json the component reads. Set one in a project's tokens.css to change it everywhere.

Type a value to try it in every example above. Reset puts the default back.

Token Type Default Override
--norn-ui-accentThe brand color, shared by every component. <color> #2346d4
--norn-ui-border-colorHairline color. <color> light-dark(#d3d8e2, #2d323e)
--norn-ui-radius-sCorner radius of a part inside a component, and of inline code. A component's own radius is ui.border.radius. <length> 4px
--norn-ui-focus-offsetGap between an element and its focus ring. An element the ring would clip draws it inset, at the negative of this. <length> 2px
--norn-ui-state-hoverShare of the text color mixed into the background while the pointer is over a control. <percentage> 8%
--norn-ui-state-pressShare of the text color mixed into the background while a control is pressed, and of the accent on a selected or current item. <percentage> 12%
--norn-ui-motion-durationLength of a state change, such as a hover layer. <time> 150ms
--norn-ui-motion-easingEasing for every transition. <easing-function> cubic-bezier(0.2, 0, 0, 1)
--norn-ui-motion-slideLength of a selected state sliding to a new option, such as a checked segment or a selected tab. <color> 200ms
--norn-ui-motion-trailHow far the trailing edge of a sliding selected state lags its leading edge, so the shape stretches as it moves. <color> 90ms
--norn-ui-control-heightHeight of a button, field, or tab. A component raises it to 2.75rem for a coarse pointer. <length> 2.25rem
--norn-text-baseText color. <color> light-dark(#16181d, #eceef3)
--norn-text-mutedSecondary text color. <color> light-dark(#4b5160, #a4abba)
--norn-text-accentThe accent for text and links: darkened in light mode, lightened in dark mode. The lightness caps keep any accent at 4.5:1 or better. <color> light-dark(oklch(from color-mix(in oklch, var(--norn-ui-accent, #2346d4) 82%, black) min(l, 0.5) c h), oklch(from color-mix(in oklch, var(--norn-ui-accent, #2346d4) 55%, white) max(l, 0.72) c h))
--norn-font-size-sSmall text: captions, code, navigation, and notes. <length> 0.875rem
--norn-space-xsExtra small spacing step. <length> 0.5rem
--norn-space-sSmall spacing step. <length> 0.75rem