Skip to content
ui8kit

component / components

Nav Links

Nav Links component

Install

npx ui8kit add nav-links

Pulls in: compose, group, kit-box, menu-entry, nav-bar, utils

Preview

OverviewOrdersCustomersReportsSettings

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-links
components/nav-links.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 a top bar in a row; the current one carries aria-current. side: all, or the first or second half
  of the list.
-->
<script lang="ts" module>
  import type { Snippet } from "svelte";
  import type { NavLink } from "../blocks/nav-bar.types";

  export type NavLinksProps = {
    links: NavLink[];
    current?: string;
    side?: "all" | "left" | "right";
  };
</script>

<script lang="ts">
  import Group from "../compose/Group.svelte";
  import MenuEntry from "../components/menu-entry.svelte";

  let { links, current = "", side = "all" }: NavLinksProps = $props();
  const count = $derived(links?.length ?? 0);
</script>

{#if ((links?.length ?? 0) > 0)}
  <Group gap="4" align="center" class="flex-wrap" data-slot="nav-links">
    {#each links as l, i (l.id)}
      {#if (((side as string) === "all") || (((i * 2) < count) === ((side as string) === "left")))}
        <MenuEntry href={l.href} class="text-sm" current={(l.id === current)} testid="nav-link">
          {l.name}
        </MenuEntry>
      {/if}
    {/each}
  </Group>
{/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-links
components/nav-links.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 a top bar in a row; the current one carries aria-current. side: all, or the first or second half
 * of the list.
 */
import { Fragment, type ReactNode } from "react";
import { Group } from "../compose";
import { MenuEntry } from "../components/menu-entry";
import type { NavLink } from "../blocks/nav-bar.types";

export type NavLinksProps = {
  links: NavLink[];
  current?: string;
  side?: "all" | "left" | "right";
};

export function NavLinks({ links, current = "", side = "all" }: NavLinksProps) {
  const count = links?.length ?? 0;
  return (
    <>
      {((links?.length ?? 0) > 0) ? (
        <Group gap="4" align="center" className="flex-wrap" data-slot="nav-links">
          {(links ?? []).map((l, i) => (
            <Fragment key={l.id}>
              {(((side as string) === "all") || (((i * 2) < count) === ((side as string) === "left"))) ? (
                <MenuEntry href={l.href} className="text-sm" current={(l.id === current)} testid="nav-link">
                  {l.name}
                </MenuEntry>
              ) : null}
            </Fragment>
          ))}
        </Group>
      ) : 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-links
components/nav-links.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 a top bar in a row; the current one carries aria-current. side: all, or the first or second half
  of the list.
-->
<script lang="ts">
import type { NavLink } from "../blocks/nav-bar.types";

export type NavLinksProps = {
  links: NavLink[];
  current?: string;
  side?: "all" | "left" | "right";
};
</script>

<script setup lang="ts">
import { computed } from "vue";
import Group from "../compose/Group.vue";
import MenuEntry from "../components/menu-entry.vue";

const { links, current = "", side = "all" } = defineProps<NavLinksProps>();
const count = computed(() => links?.length ?? 0);
</script>

<template>
  <Group v-if="((links?.length ?? 0) > 0)" gap="4" align="center" class="flex-wrap" data-slot="nav-links">
    <template v-for="(l, i) in links" :key="l.id">
      <MenuEntry
        v-if="(((side as string) === 'all') || (((i * 2) < count) === ((side as string) === 'left')))"
        :href="l.href"
        class="text-sm"
        :current="(l.id === current)"
        testid="nav-link"
      >
        {{ l.name }}
      </MenuEntry>
    </template>
  </Group>
</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-links
components/nav-links.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 a top bar in a row; the current one carries aria-current. side: all, or the first or second half
 * of the list.
 */
import { For, type JSX } from "solid-js";
import { Group } from "../compose";
import { MenuEntry } from "../components/menu-entry";
import type { NavLink } from "../blocks/nav-bar.types";

export type NavLinksProps = {
  links: NavLink[];
  current?: string;
  side?: "all" | "left" | "right";
};

export function NavLinks({ links, current = "", side = "all" }: NavLinksProps) {
  const count = links?.length ?? 0;
  return (
    <>
      {((links?.length ?? 0) > 0) ? (
        <Group gap="4" align="center" class="flex-wrap" data-slot="nav-links">
          <For each={links ?? []}>{(l, iOf) => { const i = iOf(); return (
            <>
              {(((side as string) === "all") || (((i * 2) < count) === ((side as string) === "left"))) ? (
                <MenuEntry href={l.href} class="text-sm" current={(l.id === current)} testid="nav-link">
                  {l.name}
                </MenuEntry>
              ) : null}
            </>
          ); }}</For>
        </Group>
      ) : 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-links
blocks/nav-links.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-links.json

package blocks

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

// NavLinksProps are the props of NavLinks; the values are the JSON shapes of the TypeScript props.
type NavLinksProps struct {
	Links any `json:"links"`
	Current any `json:"current"`
	Side any `json:"side"`
}

// The links of a top bar in a row; the current one carries aria-current. side: all, or the first or second half of the list.
templ NavLinks(p NavLinksProps) {
	{{ vLinks := p.Links }}
	{{ vCurrent := uiutils.Def(p.Current, "") }}
	{{ vSide := uiutils.Def(p.Side, "all") }}
	{{ vCount := any(uiutils.Len(vLinks)) }}
	if uiutils.Gt(uiutils.Len(vLinks), float64(0)) {
		@compose.Group(compose.GroupProps{Gap: "4", Align: "center", BoxProps: box.BoxProps{Class: "flex-wrap", Attrs: uiutils.Attrs("data-slot", "nav-links")}}) {
			for vI, vL := range uiutils.L(vLinks) {
				if uiutils.T(uiutils.Or(uiutils.Eq(vSide, "all"), uiutils.Eq(uiutils.Lt(uiutils.Mul(float64(vI), float64(2)), vCount), uiutils.Eq(vSide, "left")))) {
					@MenuEntry(MenuEntryProps{Href: uiutils.Get(vL, "href"), Class: uiutils.Cnv("text-sm"), Current: uiutils.Eq(uiutils.Get(vL, "id"), vCurrent), Testid: "nav-link"}) {
						{ uiutils.Text(uiutils.Get(vL, "name")) }
					}
				}
			}
		}
	}
}

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-links
blocks/nav-links.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-links.json
    The links of a top bar in a row; the current one carries aria-current. side: all, or the first or second half of the list.
    Props (p): links, current, side. -#}
{%- set v_links = (p.links ?? null) -%}
{%- set v_current = (p.current ?? '') -%}
{%- set v_side = (p.side ?? 'all') -%}
{%- set v_count = og_len(v_links) -%}
{%- if og_t(og_gt(og_len(v_links), 0)) %}
  {%- set c_2 -%}
    {%- for v_l in og_l(v_links) %}
      {%- set v_i = loop.index0 -%}
      {%- if og_t(og_or([og_eq(v_side, 'all'), og_eq(og_lt(og_mul(v_i, 2), v_count), og_eq(v_side, 'left'))])) %}
        {%- set c_1 -%}
          {{ og_text(og_get(v_l, ['name'])) }}
        {%- endset -%}
        {{ include('blocks/menu-entry.html.twig', {'p': {'href': og_get(v_l, ['href']), 'className': og_cnv(['text-sm']), 'current': og_eq(og_get(v_l, ['id']), v_current), 'testid': 'nav-link'}, 'children': og_markup(c_1)}, with_context = false) }}
      {%- endif %}
    {%- endfor %}
  {%- endset -%}
  {{ include('compose/Group.html.twig', {'gap': '4', 'align': 'center', 'class': 'flex-wrap', 'attrs': og_attrs(['data-slot', 'nav-links']), 'children': c_2}, 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-links
blocks/nav-links.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-links.json
    The links of a top bar in a row; the current one carries aria-current. side: all, or the first or second half of the list.
    Props (p): links, current, side. *}
{var $v_links = ($p['links'] ?? null)}
{var $v_current = ($p['current'] ?? '')}
{var $v_side = ($p['side'] ?? 'all')}
{var $v_count = og_len($v_links)}
{if og_t(og_gt(og_len($v_links), 0))}
  {capture $c_2}
    {foreach og_l($v_links) as $v_l}
      {var $v_i = $iterator->counter0}
      {if og_t(og_or([og_eq($v_side, 'all'), og_eq(og_lt(og_mul($v_i, 2), $v_count), og_eq($v_side, 'left'))]))}
        {capture $c_1}
          {=og_text(og_get($v_l, ['name']))}
        {/capture}
        {=og_include('blocks/menu-entry.latte', ['p' => ['href' => og_get($v_l, ['href']), 'className' => og_cnv(['text-sm']), 'current' => og_eq(og_get($v_l, ['id']), $v_current), 'testid' => 'nav-link'], 'children' => og_markup($c_1)])|noescape}
      {/if}
    {/foreach}
  {/capture}
  {=og_include('compose/Group.latte', ['gap' => '4', 'align' => 'center', 'class' => 'flex-wrap', 'attrs' => og_attrs(['data-slot', 'nav-links']), 'children' => (string) $c_2])|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-links
blocks/nav-links.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-links.json
    The links of a top bar in a row; the current one carries aria-current. side: all, or the first or second half of the list.
    Props (p): links, current, side. -#}
{%- set v_links = og_def(p['links'], none) -%}
{%- set v_current = og_def(p['current'], '') -%}
{%- set v_side = og_def(p['side'], 'all') -%}
{%- set v_count = og_len(v_links) -%}
{%- if og_t(og_gt(og_len(v_links), 0)) %}
  {%- set c_2 -%}
    {%- for v_l in og_l(v_links) %}
      {%- set v_i = loop.index0 -%}
      {%- if og_t(og_or([og_eq(v_side, 'all'), og_eq(og_lt(og_mul(v_i, 2), v_count), og_eq(v_side, 'left'))])) %}
        {%- set c_1 -%}
          {{ og_text(og_get(v_l, ['name'])) }}
        {%- endset -%}
        {{ og_include('blocks/menu-entry.html.j2', {'p': {'href': og_get(v_l, ['href']), 'className': og_cnv(['text-sm']), 'current': og_eq(og_get(v_l, ['id']), v_current), 'testid': 'nav-link'}, 'children': og_markup(c_1)}) }}
      {%- endif %}
    {%- endfor %}
  {%- endset -%}
  {{ og_include('compose/group.html.j2', {'p': {'Gap': '4', 'Align': 'center', 'Class': 'flex-wrap', 'Attrs': og_attrs(['data-slot', 'nav-links'])}, 'children': c_2}) }}
{%- 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 a top bar in a row; the current one carries aria-current. side: all, or the first or second half of the list.

Props of NavLinks
PropTypeDefault Description
links (required)NavLink[]-
current string""id of the current link
side "all" | "left" | "right""all"

Used in