Nav Links
Nav Links component
Install
npx ui8kit add nav-linksPulls in: compose, group, kit-box, menu-entry, nav-bar, 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-cdnnpx ui8kit add nav-links<!-- 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}
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-cdnnpx ui8kit add nav-links// 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}
</>
);
}
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-cdnnpx ui8kit add nav-links<!-- 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>
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-cdnnpx ui8kit add nav-links// 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}
</>
);
}
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-cdnnpx ui8kit add nav-links// 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")) }
}
}
}
}
}
}
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-cdnnpx ui8kit add nav-links{#- 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 %}
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-cdnnpx ui8kit add nav-links{* 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}
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-cdnnpx ui8kit add nav-links{#- 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 %}
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.
| Prop | Type | Default | Description |
|---|---|---|---|
| links (required) | NavLink[] | - | |
| current | string | "" | id of the current link |
| side | "all" | "left" | "right" | "all" |