Skip to content
ui8kit

component / components

Nav Bar Menu

Nav Bar Menu component

Install

npx ui8kit add nav-bar-menu

Pulls in: nav-bar, nav-block, nav-links, 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 nav-bar-menu
components/nav-bar-menu.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 links of NavBar in a nav landmark; left out when there are no links. -->
<script lang="ts" module>
  import type { Snippet } from "svelte";
  import type { NavLink } from "../blocks/nav-bar.types";

  export type NavBarMenuProps = {
    label: string;
    links: NavLink[];
    current?: string;
    landmarkLabel?: string;
  };
</script>

<script lang="ts">
  import NavBlock from "../components/nav-block.svelte";
  import NavLinks from "../components/nav-links.svelte";

  let { label, links, current = "", landmarkLabel }: NavBarMenuProps = $props();
</script>

{#if ((links?.length ?? 0) > 0)}
  <NavBlock
    label={label}
    class={"order-last w-full overflow-x-auto md:order-none md:w-auto [&>div]:flex-nowrap md:[&>div]:flex-wrap [&_a]:shrink-0"}
    testid="site-nav"
    landmarkLabel={landmarkLabel}
  >
    <NavLinks links={links} current={current} />
  </NavBlock>
{/if}

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 nav-bar-menu
components/nav-bar-menu.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 links of NavBar in a nav landmark; left out when there are no links. */
import { type ReactNode } from "react";
import { NavBlock } from "../components/nav-block";
import { NavLinks } from "../components/nav-links";
import type { NavLink } from "../blocks/nav-bar.types";

export type NavBarMenuProps = {
  label: string;
  links: NavLink[];
  current?: string;
  landmarkLabel?: string;
};

export function NavBarMenu({ label, links, current = "", landmarkLabel }: NavBarMenuProps) {
  return (
    <>
      {((links?.length ?? 0) > 0) ? (
        <NavBlock
          label={label}
          className={"order-last w-full overflow-x-auto md:order-none md:w-auto [&>div]:flex-nowrap md:[&>div]:flex-wrap [&_a]:shrink-0"}
          testid="site-nav"
          landmarkLabel={landmarkLabel}
        >
          <NavLinks links={links} current={current} />
        </NavBlock>
      ) : null}
    </>
  );
}

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 nav-bar-menu
components/nav-bar-menu.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 links of NavBar in a nav landmark; left out when there are no links. -->
<script lang="ts">
import type { NavLink } from "../blocks/nav-bar.types";

export type NavBarMenuProps = {
  label: string;
  links: NavLink[];
  current?: string;
  landmarkLabel?: string;
};
</script>

<script setup lang="ts">
import NavBlock from "../components/nav-block.vue";
import NavLinks from "../components/nav-links.vue";

const { label, links, current = "", landmarkLabel } = defineProps<NavBarMenuProps>();
</script>

<template>
  <NavBlock v-if="((links?.length ?? 0) > 0)"
    :label="label"
    :class="'order-last w-full overflow-x-auto md:order-none md:w-auto [&>div]:flex-nowrap md:[&>div]:flex-wrap [&_a]:shrink-0'"
    testid="site-nav"
    :landmarkLabel="landmarkLabel"
  >
    <NavLinks :links="links" :current="current" />
  </NavBlock>
</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 nav-bar-menu
components/nav-bar-menu.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 links of NavBar in a nav landmark; left out when there are no links. */
import { type JSX } from "solid-js";
import { NavBlock } from "../components/nav-block";
import { NavLinks } from "../components/nav-links";
import type { NavLink } from "../blocks/nav-bar.types";

export type NavBarMenuProps = {
  label: string;
  links: NavLink[];
  current?: string;
  landmarkLabel?: string;
};

export function NavBarMenu({ label, links, current = "", landmarkLabel }: NavBarMenuProps) {
  return (
    <>
      {((links?.length ?? 0) > 0) ? (
        <NavBlock
          label={label}
          class={"order-last w-full overflow-x-auto md:order-none md:w-auto [&>div]:flex-nowrap md:[&>div]:flex-wrap [&_a]:shrink-0"}
          testid="site-nav"
          landmarkLabel={landmarkLabel}
        >
          <NavLinks links={links} current={current} />
        </NavBlock>
      ) : null}
    </>
  );
}

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 nav-bar-menu
blocks/nav-bar-menu.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/nav-bar-menu.json

package blocks

import (
	uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)

// NavBarMenuProps are the props of NavBarMenu; the values are the JSON shapes of the TypeScript props.
type NavBarMenuProps struct {
	Label any `json:"label"`
	Links any `json:"links"`
	Current any `json:"current"`
	LandmarkLabel any `json:"landmarkLabel"`
}

// The links of NavBar in a nav landmark; left out when there are no links.
templ NavBarMenu(p NavBarMenuProps) {
	{{ vLabel := p.Label }}
	{{ vLinks := p.Links }}
	{{ vCurrent := uiutils.Def(p.Current, "") }}
	{{ vLandmarkLabel := p.LandmarkLabel }}
	if uiutils.Gt(uiutils.Len(vLinks), float64(0)) {
		@NavBlock(NavBlockProps{Label: vLabel, Class: uiutils.Cnv("order-last w-full overflow-x-auto md:order-none md:w-auto [&>div]:flex-nowrap md:[&>div]:flex-wrap [&_a]:shrink-0"), Testid: "site-nav", LandmarkLabel: vLandmarkLabel}) {
			@NavLinks(NavLinksProps{Links: vLinks, Current: vCurrent})
		}
	}
}

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 nav-bar-menu
blocks/nav-bar-menu.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/nav-bar-menu.json
    The links of NavBar in a nav landmark; left out when there are no links.
    Props (p): label, links, current, landmarkLabel. -#}
{%- set v_label = (p.label ?? null) -%}
{%- set v_links = (p.links ?? null) -%}
{%- set v_current = (p.current ?? '') -%}
{%- set v_landmarkLabel = (p.landmarkLabel ?? null) -%}
{%- if og_t(og_gt(og_len(v_links), 0)) %}
  {%- set c_1 -%}
    {{ include('blocks/nav-links.html.twig', {'p': {'links': v_links, 'current': v_current}}, with_context = false) }}
  {%- endset -%}
  {{ include('blocks/nav-block.html.twig', {'p': {'label': v_label, 'className': og_cnv(['order-last w-full overflow-x-auto md:order-none md:w-auto [&>div]:flex-nowrap md:[&>div]:flex-wrap [&_a]:shrink-0']), 'testid': 'site-nav', 'landmarkLabel': v_landmarkLabel}, 'children': og_markup(c_1)}, with_context = false) }}
{%- endif %}

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 nav-bar-menu
blocks/nav-bar-menu.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/nav-bar-menu.json
    The links of NavBar in a nav landmark; left out when there are no links.
    Props (p): label, links, current, landmarkLabel. *}
{var $v_label = ($p['label'] ?? null)}
{var $v_links = ($p['links'] ?? null)}
{var $v_current = ($p['current'] ?? '')}
{var $v_landmarkLabel = ($p['landmarkLabel'] ?? null)}
{if og_t(og_gt(og_len($v_links), 0))}
  {capture $c_1}
    {=og_include('blocks/nav-links.latte', ['p' => ['links' => $v_links, 'current' => $v_current]])|noescape}
  {/capture}
  {=og_include('blocks/nav-block.latte', ['p' => ['label' => $v_label, 'className' => og_cnv(['order-last w-full overflow-x-auto md:order-none md:w-auto [&>div]:flex-nowrap md:[&>div]:flex-wrap [&_a]:shrink-0']), 'testid' => 'site-nav', 'landmarkLabel' => $v_landmarkLabel], 'children' => og_markup($c_1)])|noescape}
{/if}

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 nav-bar-menu
blocks/nav-bar-menu.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/nav-bar-menu.json
    The links of NavBar in a nav landmark; left out when there are no links.
    Props (p): label, links, current, landmarkLabel. -#}
{%- set v_label = og_def(p['label'], none) -%}
{%- set v_links = og_def(p['links'], none) -%}
{%- set v_current = og_def(p['current'], '') -%}
{%- set v_landmarkLabel = og_def(p['landmarkLabel'], none) -%}
{%- if og_t(og_gt(og_len(v_links), 0)) %}
  {%- set c_1 -%}
    {{ og_include('blocks/nav-links.html.j2', {'p': {'links': v_links, 'current': v_current}}) }}
  {%- endset -%}
  {{ og_include('blocks/nav-block.html.j2', {'p': {'label': v_label, 'className': og_cnv(['order-last w-full overflow-x-auto md:order-none md:w-auto [&>div]:flex-nowrap md:[&>div]:flex-wrap [&_a]:shrink-0']), 'testid': 'site-nav', 'landmarkLabel': v_landmarkLabel}, 'children': og_markup(c_1)}) }}
{%- endif %}

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 links of NavBar in a nav landmark; left out when there are no links.

Props of NavBarMenu
PropTypeDefault Description
label (required)string-accessible name of the navigation
links (required)NavLink[]-
current string""id of the current link
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