Page Crumbs
Page Crumbs component
Install
npx ui8kit add page-crumbsPulls in: block, compose, inline, kit-box, kit-link, kit-text, link, list, list-item, lucide-icon, 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 page-crumbs<!-- 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 breadcrumbs of an inner page: the parent pages (links where they have an href) separated by chevrons; the
last entry is the current page and is not a link.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
import type { NavLink } from "../blocks/nav-bar.types";
export type PageCrumbsProps = {
label: string;
crumbs: NavLink[];
landmarkLabel?: string;
};
</script>
<script lang="ts">
import Block from "../compose/Block.svelte";
import Inline from "../compose/Inline.svelte";
import Link from "../compose/Link.svelte";
import List from "../compose/List.svelte";
import ListItem from "../compose/ListItem.svelte";
import LucideIcon from "../icons/LucideIcon.svelte";
import { urlOf } from "../utils";
let { label, crumbs, landmarkLabel }: PageCrumbsProps = $props();
const last = $derived((crumbs?.length ?? 0) - 1);
</script>
<Block tag="nav" aria-label={(landmarkLabel ?? label)} data-slot="crumbs">
<List class="m-0 flex list-none flex-wrap items-center gap-2 p-0 text-sm text-muted-foreground">
{#each crumbs as c, i (c.id)}
<ListItem class="flex items-center gap-2" data-slot="crumbs-row">
{#if (i < last)}
{#if c.href}
<Link href={urlOf(c.href)} variant="muted" size="sm" data-slot="crumb">
{c.name}
</Link>
{:else}
<Inline data-slot="crumb">
{c.name}
</Inline>
{/if}
<LucideIcon name="chevron-right" size={16} />
{:else}
<Inline class="font-medium text-foreground" aria-current="page">
{c.name}
</Inline>
{/if}
</ListItem>
{/each}
</List>
</Block>
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 page-crumbs// 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 breadcrumbs of an inner page: the parent pages (links where they have an href) separated by chevrons; the
* last entry is the current page and is not a link.
*/
import { type ReactNode } from "react";
import { Block, Inline, Link, List, ListItem } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { urlOf } from "../utils";
import type { NavLink } from "../blocks/nav-bar.types";
export type PageCrumbsProps = {
label: string;
crumbs: NavLink[];
landmarkLabel?: string;
};
export function PageCrumbs({ label, crumbs, landmarkLabel }: PageCrumbsProps) {
const last = (crumbs?.length ?? 0) - 1;
return (
<Block tag="nav" aria-label={(landmarkLabel ?? label)} data-slot="crumbs">
<List className="m-0 flex list-none flex-wrap items-center gap-2 p-0 text-sm text-muted-foreground">
{(crumbs ?? []).map((c, i) => (
<ListItem key={c.id} className="flex items-center gap-2" data-slot="crumbs-row">
{(i < last) ? (
<>
{c.href ? (
<Link href={urlOf(c.href)} variant="muted" size="sm" data-slot="crumb">
{c.name}
</Link>
) : (
<Inline data-slot="crumb">
{c.name}
</Inline>
)}
<LucideIcon name="chevron-right" size={16} />
</>
) : (
<Inline className="font-medium text-foreground" aria-current="page">
{c.name}
</Inline>
)}
</ListItem>
))}
</List>
</Block>
);
}
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 page-crumbs<!-- 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 breadcrumbs of an inner page: the parent pages (links where they have an href) separated by chevrons; the
last entry is the current page and is not a link.
-->
<script lang="ts">
import type { NavLink } from "../blocks/nav-bar.types";
export type PageCrumbsProps = {
label: string;
crumbs: NavLink[];
landmarkLabel?: string;
};
</script>
<script setup lang="ts">
import { computed } from "vue";
import Block from "../compose/Block.vue";
import Inline from "../compose/Inline.vue";
import Link from "../compose/Link.vue";
import List from "../compose/List.vue";
import ListItem from "../compose/ListItem.vue";
import LucideIcon from "../icons/LucideIcon.vue";
import { urlOf } from "../utils";
const { label, crumbs, landmarkLabel } = defineProps<PageCrumbsProps>();
const last = computed(() => (crumbs?.length ?? 0) - 1);
</script>
<template>
<Block tag="nav" :aria-label="(landmarkLabel ?? label)" data-slot="crumbs">
<List class="m-0 flex list-none flex-wrap items-center gap-2 p-0 text-sm text-muted-foreground">
<ListItem v-for="(c, i) in crumbs" :key="c.id" class="flex items-center gap-2" data-slot="crumbs-row">
<template v-if="(i < last)">
<Link v-if="c.href" :href="urlOf(c.href)" variant="muted" size="sm" data-slot="crumb">
{{ c.name }}
</Link>
<Inline v-else data-slot="crumb">
{{ c.name }}
</Inline>
<LucideIcon name="chevron-right" :size="16" />
</template>
<Inline v-else class="font-medium text-foreground" aria-current="page">
{{ c.name }}
</Inline>
</ListItem>
</List>
</Block>
</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 page-crumbs// 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 breadcrumbs of an inner page: the parent pages (links where they have an href) separated by chevrons; the
* last entry is the current page and is not a link.
*/
import { For, type JSX } from "solid-js";
import { Block, Inline, Link, List, ListItem } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { urlOf } from "../utils";
import type { NavLink } from "../blocks/nav-bar.types";
export type PageCrumbsProps = {
label: string;
crumbs: NavLink[];
landmarkLabel?: string;
};
export function PageCrumbs({ label, crumbs, landmarkLabel }: PageCrumbsProps) {
const last = (crumbs?.length ?? 0) - 1;
return (
<Block tag="nav" aria-label={(landmarkLabel ?? label)} data-slot="crumbs">
<List class="m-0 flex list-none flex-wrap items-center gap-2 p-0 text-sm text-muted-foreground">
<For each={crumbs ?? []}>{(c, iOf) => { const i = iOf(); return (
<ListItem class="flex items-center gap-2" data-slot="crumbs-row">
{(i < last) ? (
<>
{c.href ? (
<Link href={urlOf(c.href)} variant="muted" size="sm" data-slot="crumb">
{c.name}
</Link>
) : (
<Inline data-slot="crumb">
{c.name}
</Inline>
)}
<LucideIcon name="chevron-right" size={16} />
</>
) : (
<Inline class="font-medium text-foreground" aria-current="page">
{c.name}
</Inline>
)}
</ListItem>
); }}</For>
</List>
</Block>
);
}
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 page-crumbs// 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/page-crumbs.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/icons"
"github.com/ui8kit/codegen/generated/templ/ui/link"
"github.com/ui8kit/codegen/generated/templ/ui/text"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// PageCrumbsProps are the props of PageCrumbs; the values are the JSON shapes of the TypeScript props.
type PageCrumbsProps struct {
Label any `json:"label"`
Crumbs any `json:"crumbs"`
LandmarkLabel any `json:"landmarkLabel"`
}
// The breadcrumbs of an inner page: the parent pages (links where they have an href) separated by chevrons; the last entry is the current page and is not a link.
templ PageCrumbs(p PageCrumbsProps) {
{{ vLabel := p.Label }}
{{ vCrumbs := p.Crumbs }}
{{ vLandmarkLabel := p.LandmarkLabel }}
{{ vLast := any(uiutils.Sub(uiutils.Len(vCrumbs), float64(1))) }}
@compose.Block(compose.BlockProps{BoxProps: box.BoxProps{Tag: "nav", Attrs: uiutils.Attrs("aria-label", uiutils.Coalesce(vLandmarkLabel, vLabel), "data-slot", "crumbs")}}) {
@compose.List(compose.ListProps{BoxProps: box.BoxProps{Class: "m-0 flex list-none flex-wrap items-center gap-2 p-0 text-sm text-muted-foreground"}}) {
for vI, vC := range uiutils.L(vCrumbs) {
@compose.ListItem(compose.ListItemProps{BoxProps: box.BoxProps{Class: "flex items-center gap-2", Attrs: uiutils.Attrs("data-slot", "crumbs-row")}}) {
if uiutils.Lt(float64(vI), vLast) {
if uiutils.T(uiutils.Get(vC, "href")) {
@compose.Link(compose.LinkProps{Variant: "muted", Size: "sm", LinkProps: link.LinkProps{Href: uiutils.URL(uiutils.Get(vC, "href"), false), Attrs: uiutils.Attrs("data-slot", "crumb")}}) {
{ uiutils.Text(uiutils.Get(vC, "name")) }
}
} else {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Attrs: uiutils.Attrs("data-slot", "crumb")}}) {
{ uiutils.Text(uiutils.Get(vC, "name")) }
}
}
@icons.LucideIcon(icons.LucideIconProps{Name: "chevron-right", Size: 16})
} else {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "font-medium text-foreground", Attrs: uiutils.Attrs("aria-current", "page")}}) {
{ uiutils.Text(uiutils.Get(vC, "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 page-crumbs{#- 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/page-crumbs.json
The breadcrumbs of an inner page: the parent pages (links where they have an href) separated by chevrons; the last entry is the current page and is not a link.
Props (p): label, crumbs, landmarkLabel. -#}
{%- set v_label = (p.label ?? null) -%}
{%- set v_crumbs = (p.crumbs ?? null) -%}
{%- set v_landmarkLabel = (p.landmarkLabel ?? null) -%}
{%- set v_last = og_sub(og_len(v_crumbs), 1) -%}
{%- set c_6 -%}
{%- set c_5 -%}
{%- for v_c in og_l(v_crumbs) %}
{%- set v_i = loop.index0 -%}
{%- set c_4 -%}
{%- if og_t(og_lt(v_i, v_last)) %}
{%- if og_t(og_get(v_c, ['href'])) %}
{%- set c_1 -%}
{{ og_text(og_get(v_c, ['name'])) }}
{%- endset -%}
{{ include('compose/Link.html.twig', {'href': og_url(og_s(og_get(v_c, ['href']))), 'variant': 'muted', 'size': 'sm', 'attrs': og_attrs(['data-slot', 'crumb']), 'children': c_1}, with_context = false) }}
{%- else %}
{%- set c_2 -%}
{{ og_text(og_get(v_c, ['name'])) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'attrs': og_attrs(['data-slot', 'crumb']), 'children': c_2}, with_context = false) }}
{%- endif %}
{{ include('icons/LucideIcon.html.twig', {'name': 'chevron-right', 'size': 16}, with_context = false) }}
{%- else %}
{%- set c_3 -%}
{{ og_text(og_get(v_c, ['name'])) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'font-medium text-foreground', 'attrs': og_attrs(['aria-current', 'page']), 'children': c_3}, with_context = false) }}
{%- endif %}
{%- endset -%}
{{ include('compose/ListItem.html.twig', {'class': 'flex items-center gap-2', 'attrs': og_attrs(['data-slot', 'crumbs-row']), 'children': c_4}, with_context = false) }}
{%- endfor %}
{%- endset -%}
{{ include('compose/List.html.twig', {'class': 'm-0 flex list-none flex-wrap items-center gap-2 p-0 text-sm text-muted-foreground', 'children': c_5}, with_context = false) }}
{%- endset -%}
{{ include('compose/Block.html.twig', {'tag': 'nav', 'attrs': og_attrs(['aria-label', og_coalesce([v_landmarkLabel, v_label]), 'data-slot', 'crumbs']), 'children': c_6}, with_context = false) }}
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 page-crumbs{* 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/page-crumbs.json
The breadcrumbs of an inner page: the parent pages (links where they have an href) separated by chevrons; the last entry is the current page and is not a link.
Props (p): label, crumbs, landmarkLabel. *}
{var $v_label = ($p['label'] ?? null)}
{var $v_crumbs = ($p['crumbs'] ?? null)}
{var $v_landmarkLabel = ($p['landmarkLabel'] ?? null)}
{var $v_last = og_sub(og_len($v_crumbs), 1)}
{capture $c_6}
{capture $c_5}
{foreach og_l($v_crumbs) as $v_c}
{var $v_i = $iterator->counter0}
{capture $c_4}
{if og_t(og_lt($v_i, $v_last))}
{if og_t(og_get($v_c, ['href']))}
{capture $c_1}
{=og_text(og_get($v_c, ['name']))}
{/capture}
{=og_include('compose/Link.latte', ['href' => og_url(og_s(og_get($v_c, ['href']))), 'variant' => 'muted', 'size' => 'sm', 'attrs' => og_attrs(['data-slot', 'crumb']), 'children' => (string) $c_1])|noescape}
{else}
{capture $c_2}
{=og_text(og_get($v_c, ['name']))}
{/capture}
{=og_include('compose/Inline.latte', ['attrs' => og_attrs(['data-slot', 'crumb']), 'children' => (string) $c_2])|noescape}
{/if}
{=og_include('icons/LucideIcon.latte', ['name' => 'chevron-right', 'size' => 16])|noescape}
{else}
{capture $c_3}
{=og_text(og_get($v_c, ['name']))}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'font-medium text-foreground', 'attrs' => og_attrs(['aria-current', 'page']), 'children' => (string) $c_3])|noescape}
{/if}
{/capture}
{=og_include('compose/ListItem.latte', ['class' => 'flex items-center gap-2', 'attrs' => og_attrs(['data-slot', 'crumbs-row']), 'children' => (string) $c_4])|noescape}
{/foreach}
{/capture}
{=og_include('compose/List.latte', ['class' => 'm-0 flex list-none flex-wrap items-center gap-2 p-0 text-sm text-muted-foreground', 'children' => (string) $c_5])|noescape}
{/capture}
{=og_include('compose/Block.latte', ['tag' => 'nav', 'attrs' => og_attrs(['aria-label', og_coalesce([$v_landmarkLabel, $v_label]), 'data-slot', 'crumbs']), 'children' => (string) $c_6])|noescape}
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 page-crumbs{#- 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/page-crumbs.json
The breadcrumbs of an inner page: the parent pages (links where they have an href) separated by chevrons; the last entry is the current page and is not a link.
Props (p): label, crumbs, landmarkLabel. -#}
{%- set v_label = og_def(p['label'], none) -%}
{%- set v_crumbs = og_def(p['crumbs'], none) -%}
{%- set v_landmarkLabel = og_def(p['landmarkLabel'], none) -%}
{%- set v_last = og_sub(og_len(v_crumbs), 1) -%}
{%- set c_6 -%}
{%- set c_5 -%}
{%- for v_c in og_l(v_crumbs) %}
{%- set v_i = loop.index0 -%}
{%- set c_4 -%}
{%- if og_t(og_lt(v_i, v_last)) %}
{%- if og_t(og_get(v_c, ['href'])) %}
{%- set c_1 -%}
{{ og_text(og_get(v_c, ['name'])) }}
{%- endset -%}
{{ og_include('compose/link.html.j2', {'p': {'Href': og_url(og_s(og_get(v_c, ['href']))), 'Variant': 'muted', 'Size': 'sm', 'Attrs': og_attrs(['data-slot', 'crumb'])}, 'children': c_1}) }}
{%- else %}
{%- set c_2 -%}
{{ og_text(og_get(v_c, ['name'])) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Attrs': og_attrs(['data-slot', 'crumb'])}, 'children': c_2}) }}
{%- endif %}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'chevron-right', 'Size': 16}}) }}
{%- else %}
{%- set c_3 -%}
{{ og_text(og_get(v_c, ['name'])) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'font-medium text-foreground', 'Attrs': og_attrs(['aria-current', 'page'])}, 'children': c_3}) }}
{%- endif %}
{%- endset -%}
{{ og_include('compose/list-item.html.j2', {'p': {'Class': 'flex items-center gap-2', 'Attrs': og_attrs(['data-slot', 'crumbs-row'])}, 'children': c_4}) }}
{%- endfor %}
{%- endset -%}
{{ og_include('compose/list.html.j2', {'p': {'Class': 'm-0 flex list-none flex-wrap items-center gap-2 p-0 text-sm text-muted-foreground'}, 'children': c_5}) }}
{%- endset -%}
{{ og_include('compose/block.html.j2', {'p': {'Tag': 'nav', 'Attrs': og_attrs(['aria-label', og_coalesce([v_landmarkLabel, v_label]), 'data-slot', 'crumbs'])}, 'children': c_6}) }}
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 breadcrumbs of an inner page: the parent pages (links where they have an href) separated by chevrons; the last entry is the current page and is not a link.
| Prop | Type | Default | Description |
|---|---|---|---|
| label (required) | string | - | accessible name of the breadcrumbs |
| crumbs (required) | NavLink[] | - | |
| 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 |