Skip to content
ui8kit

component / components

Menu Section Nav

Menu Section Nav component

Install

npx ui8kit add menu-section-nav

Pulls in: block, compose, kit-box, kit-link, link, list, list-item, utils

Preview

Code

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdn
npx ui8kit add menu-section-nav
components/menu-section-nav.svelte
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  The sections of a menu as chips that jump to them: a nav landmark named by `label`, one link per section to
  `#<prefix>-<key>`.
-->
<script lang="ts" module>
  import type { Snippet } from "svelte";

  export type MenuSectionNavProps = {
    label: string;
    sections: Array<{ id: string; key: string; title: string }>;
    prefix: string;
    landmarkLabel?: string;
  };
</script>

<script lang="ts">
  import Block from "../compose/Block.svelte";
  import Link from "../compose/Link.svelte";
  import List from "../compose/List.svelte";
  import ListItem from "../compose/ListItem.svelte";
  import { tpl, urlOf } from "../utils";

  let { label, sections, prefix, landmarkLabel }: MenuSectionNavProps = $props();
</script>

<Block tag="nav" aria-label={(landmarkLabel ?? label)} data-slot="section-nav">
  <List tag="ul" class="flex flex-wrap gap-2">
    {#each sections as s (s.id)}
      <ListItem data-slot="sections-row">
        <Link
          href={urlOf(tpl("#{0}-{1}", prefix, s.key))}
          variant="nav"
          size="sm"
          class="h-8 rounded px-4 inset-ring inset-ring-border"
        >
          {s.title}
        </Link>
      </ListItem>
    {/each}
  </List>
</Block>

Svelte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdn
npx ui8kit add menu-section-nav
components/menu-section-nav.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * The sections of a menu as chips that jump to them: a nav landmark named by `label`, one link per section to
 * `#<prefix>-<key>`.
 */
import { type ReactNode } from "react";
import { Block, Link, List, ListItem } from "../compose";
import { tpl, urlOf } from "../utils";

export type MenuSectionNavProps = {
  label: string;
  sections: Array<{ id: string; key: string; title: string }>;
  prefix: string;
  landmarkLabel?: string;
};

export function MenuSectionNav({ label, sections, prefix, landmarkLabel }: MenuSectionNavProps) {
  return (
    <Block tag="nav" aria-label={(landmarkLabel ?? label)} data-slot="section-nav">
      <List tag="ul" className="flex flex-wrap gap-2">
        {(sections ?? []).map((s) => (
          <ListItem key={s.id} data-slot="sections-row">
            <Link
              href={urlOf(tpl("#{0}-{1}", prefix, s.key))}
              variant="nav"
              size="sm"
              className="h-8 rounded px-4 inset-ring inset-ring-border"
            >
              {s.title}
            </Link>
          </ListItem>
        ))}
      </List>
    </Block>
  );
}

React registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdn
npx ui8kit add menu-section-nav
components/menu-section-nav.vue
<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
  The sections of a menu as chips that jump to them: a nav landmark named by `label`, one link per section to
  `#<prefix>-<key>`.
-->
<script lang="ts">
export type MenuSectionNavProps = {
  label: string;
  sections: Array<{ id: string; key: string; title: string }>;
  prefix: string;
  landmarkLabel?: string;
};
</script>

<script setup lang="ts">
import Block from "../compose/Block.vue";
import Link from "../compose/Link.vue";
import List from "../compose/List.vue";
import ListItem from "../compose/ListItem.vue";
import { tpl, urlOf } from "../utils";

const { label, sections, prefix, landmarkLabel } = defineProps<MenuSectionNavProps>();
</script>

<template>
  <Block tag="nav" :aria-label="(landmarkLabel ?? label)" data-slot="section-nav">
    <List tag="ul" class="flex flex-wrap gap-2">
      <ListItem v-for="s in sections" :key="s.id" data-slot="sections-row">
        <Link
          :href="urlOf(tpl('#{0}-{1}', prefix, s.key))"
          variant="nav"
          size="sm"
          class="h-8 rounded px-4 inset-ring inset-ring-border"
        >
          {{ s.title }}
        </Link>
      </ListItem>
    </List>
  </Block>
</template>

Vue registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdn
npx ui8kit add menu-section-nav
components/menu-section-nav.tsx
// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
 * The sections of a menu as chips that jump to them: a nav landmark named by `label`, one link per section to
 * `#<prefix>-<key>`.
 */
import { For, type JSX } from "solid-js";
import { Block, Link, List, ListItem } from "../compose";
import { tpl, urlOf } from "../utils";

export type MenuSectionNavProps = {
  label: string;
  sections: Array<{ id: string; key: string; title: string }>;
  prefix: string;
  landmarkLabel?: string;
};

export function MenuSectionNav({ label, sections, prefix, landmarkLabel }: MenuSectionNavProps) {
  return (
    <Block tag="nav" aria-label={(landmarkLabel ?? label)} data-slot="section-nav">
      <List tag="ul" class="flex flex-wrap gap-2">
        <For each={sections ?? []}>{(s) => (
          <ListItem data-slot="sections-row">
            <Link
              href={urlOf(tpl("#{0}-{1}", prefix, s.key))}
              variant="nav"
              size="sm"
              class="h-8 rounded px-4 inset-ring inset-ring-border"
            >
              {s.title}
            </Link>
          </ListItem>
        )}</For>
      </List>
    </Block>
  );
}

Solid registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdn
npx ui8kit add menu-section-nav
blocks/menu-section-nav.templ
// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Source: packages/compose-gen/specs/organisms/menu-section-nav.json

package blocks

import (
	"github.com/ui8kit/codegen/generated/templ/ui/box"
	"github.com/ui8kit/codegen/generated/templ/compose"
	"github.com/ui8kit/codegen/generated/templ/ui/link"
	uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)

// MenuSectionNavProps are the props of MenuSectionNav; the values are the JSON shapes of the TypeScript props.
type MenuSectionNavProps struct {
	Label any `json:"label"`
	Sections any `json:"sections"`
	Prefix any `json:"prefix"`
	LandmarkLabel any `json:"landmarkLabel"`
}

// The sections of a menu as chips that jump to them: a nav landmark named by `label`, one link per section to `#<prefix>-<key>`.
templ MenuSectionNav(p MenuSectionNavProps) {
	{{ vLabel := p.Label }}
	{{ vSections := p.Sections }}
	{{ vPrefix := p.Prefix }}
	{{ vLandmarkLabel := p.LandmarkLabel }}
	@compose.Block(compose.BlockProps{BoxProps: box.BoxProps{Tag: "nav", Attrs: uiutils.Attrs("aria-label", uiutils.Coalesce(vLandmarkLabel, vLabel), "data-slot", "section-nav")}}) {
		@compose.List(compose.ListProps{BoxProps: box.BoxProps{Tag: "ul", Class: "flex flex-wrap gap-2"}}) {
			for _, vS := range uiutils.L(vSections) {
				@compose.ListItem(compose.ListItemProps{BoxProps: box.BoxProps{Attrs: uiutils.Attrs("data-slot", "sections-row")}}) {
					@compose.Link(compose.LinkProps{Variant: "nav", Size: "sm", LinkProps: link.LinkProps{Href: uiutils.URL(uiutils.Tpl("#{0}-{1}", vPrefix, uiutils.Get(vS, "key")), false), Class: "h-8 rounded px-4 inset-ring inset-ring-border"}}) {
						{ uiutils.Text(uiutils.Get(vS, "title")) }
					}
				}
			}
		}
	}
}

templ registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdn
npx ui8kit add menu-section-nav
blocks/menu-section-nav.html.twig
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/organisms/menu-section-nav.json
    The sections of a menu as chips that jump to them: a nav landmark named by `label`, one link per section to `#<prefix>-<key>`.
    Props (p): label, sections, prefix, landmarkLabel. -#}
{%- set v_label = (p.label ?? null) -%}
{%- set v_sections = (p.sections ?? null) -%}
{%- set v_prefix = (p.prefix ?? null) -%}
{%- set v_landmarkLabel = (p.landmarkLabel ?? null) -%}
{%- set c_4 -%}
  {%- set c_3 -%}
    {%- for v_s in og_l(v_sections) %}
      {%- set c_2 -%}
        {%- set c_1 -%}
          {{ og_text(og_get(v_s, ['title'])) }}
        {%- endset -%}
        {{ include('compose/Link.html.twig', {'href': og_url(og_s(og_tpl('#{0}-{1}', [v_prefix, og_get(v_s, ['key'])]))), 'variant': 'nav', 'size': 'sm', 'class': 'h-8 rounded px-4 inset-ring inset-ring-border', 'children': c_1}, with_context = false) }}
      {%- endset -%}
      {{ include('compose/ListItem.html.twig', {'attrs': og_attrs(['data-slot', 'sections-row']), 'children': c_2}, with_context = false) }}
    {%- endfor %}
  {%- endset -%}
  {{ include('compose/List.html.twig', {'tag': 'ul', 'class': 'flex flex-wrap gap-2', 'children': c_3}, with_context = false) }}
{%- endset -%}
{{ include('compose/Block.html.twig', {'tag': 'nav', 'attrs': og_attrs(['aria-label', og_coalesce([v_landmarkLabel, v_label]), 'data-slot', 'section-nav']), 'children': c_4}, with_context = false) }}

Twig registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdn
npx ui8kit add menu-section-nav
blocks/menu-section-nav.latte
{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/organisms/menu-section-nav.json
    The sections of a menu as chips that jump to them: a nav landmark named by `label`, one link per section to `#<prefix>-<key>`.
    Props (p): label, sections, prefix, landmarkLabel. *}
{var $v_label = ($p['label'] ?? null)}
{var $v_sections = ($p['sections'] ?? null)}
{var $v_prefix = ($p['prefix'] ?? null)}
{var $v_landmarkLabel = ($p['landmarkLabel'] ?? null)}
{capture $c_4}
  {capture $c_3}
    {foreach og_l($v_sections) as $v_s}
      {capture $c_2}
        {capture $c_1}
          {=og_text(og_get($v_s, ['title']))}
        {/capture}
        {=og_include('compose/Link.latte', ['href' => og_url(og_s(og_tpl('#{0}-{1}', [$v_prefix, og_get($v_s, ['key'])]))), 'variant' => 'nav', 'size' => 'sm', 'class' => 'h-8 rounded px-4 inset-ring inset-ring-border', 'children' => (string) $c_1])|noescape}
      {/capture}
      {=og_include('compose/ListItem.latte', ['attrs' => og_attrs(['data-slot', 'sections-row']), 'children' => (string) $c_2])|noescape}
    {/foreach}
  {/capture}
  {=og_include('compose/List.latte', ['tag' => 'ul', 'class' => 'flex flex-wrap gap-2', 'children' => (string) $c_3])|noescape}
{/capture}
{=og_include('compose/Block.latte', ['tag' => 'nav', 'attrs' => og_attrs(['aria-label', og_coalesce([$v_landmarkLabel, $v_label]), 'data-slot', 'section-nav']), 'children' => (string) $c_4])|noescape}

Latte registry item (JSON)

Point the CLI at this runtime once, then add the item:

npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdn
npx ui8kit add menu-section-nav
blocks/menu-section-nav.html.j2
{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
    Source: packages/compose-gen/specs/organisms/menu-section-nav.json
    The sections of a menu as chips that jump to them: a nav landmark named by `label`, one link per section to `#<prefix>-<key>`.
    Props (p): label, sections, prefix, landmarkLabel. -#}
{%- set v_label = og_def(p['label'], none) -%}
{%- set v_sections = og_def(p['sections'], none) -%}
{%- set v_prefix = og_def(p['prefix'], none) -%}
{%- set v_landmarkLabel = og_def(p['landmarkLabel'], none) -%}
{%- set c_4 -%}
  {%- set c_3 -%}
    {%- for v_s in og_l(v_sections) %}
      {%- set c_2 -%}
        {%- set c_1 -%}
          {{ og_text(og_get(v_s, ['title'])) }}
        {%- endset -%}
        {{ og_include('compose/link.html.j2', {'p': {'Href': og_url(og_s(og_tpl('#{0}-{1}', [v_prefix, og_get(v_s, ['key'])]))), 'Variant': 'nav', 'Size': 'sm', 'Class': 'h-8 rounded px-4 inset-ring inset-ring-border'}, 'children': c_1}) }}
      {%- endset -%}
      {{ og_include('compose/list-item.html.j2', {'p': {'Attrs': og_attrs(['data-slot', 'sections-row'])}, 'children': c_2}) }}
    {%- endfor %}
  {%- endset -%}
  {{ og_include('compose/list.html.j2', {'p': {'Tag': 'ul', 'Class': 'flex flex-wrap gap-2'}, 'children': c_3}) }}
{%- endset -%}
{{ og_include('compose/block.html.j2', {'p': {'Tag': 'nav', 'Attrs': og_attrs(['aria-label', og_coalesce([v_landmarkLabel, v_label]), 'data-slot', 'section-nav'])}, 'children': c_4}) }}

Jinja2 registry item (JSON)

Props

Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.

The sections of a menu as chips that jump to them: a nav landmark named by `label`, one link per section to `#<prefix>-<key>`.

Props of MenuSectionNav
PropTypeDefault Description
label (required)string-accessible name of the nav
sections (required)Array<{ id: string; key: string; title: string }>-
prefix (required)string-the block id the section ids start with
landmarkLabel string-accessible name of the landmark of this component when the page shows it more than once (a variant); replaces the heading name of the root landmark, follows the name of a nested one

Used in