Breadcrumb
Breadcrumb primitive
Install
npx ui8kit add breadcrumbPulls in: kit-box, kit-link, kit-text, recipes, 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 breadcrumbcompose/Breadcrumb.svelte
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Breadcrumb: Box nav > ol > li, Link (href, not disabled) or Text span; aria-current="page" on the current item. -->
<script lang="ts">
import type { ComponentProps } from "svelte";
import Box from "../kit/ui/box/Box.svelte";
import Link from "../kit/ui/link/Link.svelte";
import Text from "../kit/ui/text/Text.svelte";
import { cn } from "../kit/utils";
type Item = { label?: string; href?: string; current?: boolean; disabled?: boolean };
let { items = [], "aria-label": ariaLabel, class: className, ...rest }: Omit<ComponentProps<typeof Box>, "tag" | "children"> & { items?: Item[]; "aria-label"?: string; class?: string } = $props();
</script>
<Box tag="nav" class={cn("text-sm", className)} aria-label={ariaLabel || "Breadcrumb"} {...rest}><Box tag="ol" class="flex flex-wrap items-center gap-2">{#each items as it, i (i)}<Box tag="li" class="inline-flex items-center">{#if it.href && !it.disabled}<Link href={it.href} class={cn("text-sm", (it.current ? "font-medium" : it.disabled ? "text-muted-foreground" : "text-primary underline-offset-4 hover:underline"))} aria-current={it.current ? "page" : undefined}>{it.label}</Link>{:else}<Text tag="span" class={cn("text-sm", (it.current ? "font-medium" : it.disabled ? "text-muted-foreground" : "text-primary underline-offset-4 hover:underline"))} aria-current={it.current ? "page" : undefined}>{it.label}</Text>{/if}</Box>{/each}</Box></Box>
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 breadcrumbcompose/breadcrumb.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import type { ComponentProps } from "react";
import { Box } from "../kit/ui/box/box";
import { Link } from "../kit/ui/link/link";
import { Text } from "../kit/ui/text/text";
import { cn } from "../kit/utils";
export type BreadcrumbItem = { label?: string; href?: string; current?: boolean; disabled?: boolean };
export type BreadcrumbProps = Omit<ComponentProps<typeof Box>, "tag" | "children"> & { items?: BreadcrumbItem[]; "aria-label"?: string; className?: string };
/** Breadcrumb: Box nav > ol > li, Link (href, not disabled) or Text span; aria-current="page" on the current item. */
export function Breadcrumb({ items, "aria-label": ariaLabel, className, ...rest }: BreadcrumbProps) {
return (
<Box tag="nav" className={cn("text-sm", className)} aria-label={ariaLabel || "Breadcrumb"} {...rest}>
<Box tag="ol" className="flex flex-wrap items-center gap-2">
{(items ?? []).map((it, i) => (
<Box key={i} tag="li" className="inline-flex items-center">
{it.href && !it.disabled
? <Link href={it.href} className={cn("text-sm", (it.current ? "font-medium" : it.disabled ? "text-muted-foreground" : "text-primary underline-offset-4 hover:underline"))} aria-current={it.current ? "page" : undefined}>{it.label}</Link>
: <Text tag="span" className={cn("text-sm", (it.current ? "font-medium" : it.disabled ? "text-muted-foreground" : "text-primary underline-offset-4 hover:underline"))} aria-current={it.current ? "page" : undefined}>{it.label}</Text>}
</Box>
))}
</Box>
</Box>
);
}
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 breadcrumbcompose/Breadcrumb.vue
<!-- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. -->
<!-- Breadcrumb: Box nav > ol > li, Link (href, not disabled) or Text span; aria-current="page" on the current item. -->
<script setup lang="ts">
import { computed, useAttrs } from "vue";
import Box from "../kit/ui/box/Box.vue";
import Link from "../kit/ui/link/Link.vue";
import Text from "../kit/ui/text/Text.vue";
import { cn } from "../kit/utils";
type Item = { label?: string; href?: string; current?: boolean; disabled?: boolean };
defineOptions({ name: "Breadcrumb", inheritAttrs: false });
const props = defineProps<{ items?: Item[]; ariaLabel?: string }>();
const attrs = useAttrs();
const rest = computed(() => {
const { class: _class, ...r } = attrs;
return r;
});
const cls = computed(() => cn("text-sm", attrs.class as string | undefined));
const st = (it: Item) => cn("text-sm", (it.current ? 'font-medium' : it.disabled ? 'text-muted-foreground' : 'text-primary underline-offset-4 hover:underline'));
</script>
<template>
<Box tag="nav" :class="cls" :aria-label="props.ariaLabel || 'Breadcrumb'" v-bind="rest"><Box tag="ol" class="flex flex-wrap items-center gap-2"><Box v-for="(it, i) in props.items ?? []" :key="i" tag="li" class="inline-flex items-center"><Link v-if="it.href && !it.disabled" :href="it.href" :class="st(it)" :aria-current="it.current ? 'page' : undefined">{{ it.label }}</Link><Text v-else tag="span" :class="st(it)" :aria-current="it.current ? 'page' : undefined">{{ it.label }}</Text></Box></Box></Box>
</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 breadcrumbcompose/breadcrumb.solid.tsx
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
import { For, splitProps, type ComponentProps } from "solid-js";
import { Box } from "../kit/ui/box/box.solid";
import { Link } from "../kit/ui/link/link.solid";
import { Text } from "../kit/ui/text/text.solid";
import { cn } from "../kit/utils";
export type BreadcrumbItem = { label?: string; href?: string; current?: boolean; disabled?: boolean };
export type BreadcrumbProps = Omit<ComponentProps<typeof Box>, "tag" | "children" | "class" | "className"> & { items?: BreadcrumbItem[]; "aria-label"?: string; class?: string; className?: string };
/** Breadcrumb: Box nav > ol > li, Link (href, not disabled) or Text span; aria-current="page" on the current item. */
export function Breadcrumb(props: BreadcrumbProps) {
const [local, rest] = splitProps(props, ["items", "aria-label", "class", "className"]);
return (
<Box tag="nav" class={cn("text-sm", local.class ?? local.className)} aria-label={local["aria-label"] || "Breadcrumb"} {...rest}>
<Box tag="ol" class="flex flex-wrap items-center gap-2">
<For each={local.items ?? []}>{(it) => (
<Box tag="li" class="inline-flex items-center">
{it.href && !it.disabled
? <Link href={it.href} class={cn("text-sm", (it.current ? "font-medium" : it.disabled ? "text-muted-foreground" : "text-primary underline-offset-4 hover:underline"))} aria-current={it.current ? "page" : undefined}>{it.label}</Link>
: <Text tag="span" class={cn("text-sm", (it.current ? "font-medium" : it.disabled ? "text-muted-foreground" : "text-primary underline-offset-4 hover:underline"))} aria-current={it.current ? "page" : undefined}>{it.label}</Text>}
</Box>
)}</For>
</Box>
</Box>
);
}
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 breadcrumbcompose/breadcrumb.templ
// Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
package compose
import (
"github.com/ui8kit/codegen/generated/templ/ui/box"
"github.com/ui8kit/codegen/generated/templ/ui/link"
"github.com/ui8kit/codegen/generated/templ/ui/text"
)
// BreadcrumbItem is one step of the trail.
type BreadcrumbItem struct {
Label string
Href string
Current bool
Disabled bool
}
// BreadcrumbProps: Box nav > ol > li, Link (href, not disabled) or Text span.
type BreadcrumbProps struct {
Items []BreadcrumbItem
AriaLabel string
box.BoxProps
}
func breadcrumbItemClass(it BreadcrumbItem) string {
switch {
case it.Current:
return "text-sm font-medium"
case it.Disabled:
return "text-sm text-muted-foreground"
}
return "text-sm text-primary underline-offset-4 hover:underline"
}
func breadcrumbCurrent(it BreadcrumbItem) templ.Attributes {
if it.Current {
return templ.Attributes{"aria-current": "page"}
}
return templ.Attributes{}
}
func breadcrumbNav(p BreadcrumbProps) box.BoxProps {
in := p.BoxProps
in.Tag = "nav"
in.Class = Join("text-sm", p.BoxProps.Class)
in.Attrs = WithAttrs(in.Attrs, map[string]string{"aria-label": Or(p.AriaLabel, "Breadcrumb")})
return in
}
// Breadcrumb renders the trail; aria-current="page" on the current item.
templ Breadcrumb(p BreadcrumbProps) {
@box.Box(breadcrumbNav(p)) {
@box.Box(box.BoxProps{Tag: "ol", Class: "flex flex-wrap items-center gap-2"}) {
for _, it := range p.Items {
@box.Box(box.BoxProps{Tag: "li", Class: "inline-flex items-center"}) {
if it.Href != "" && !it.Disabled {
@link.Link(link.LinkProps{Href: it.Href, Class: breadcrumbItemClass(it), Attrs: breadcrumbCurrent(it)}) {
{ it.Label }
}
} else {
@text.Text(text.TextProps{Tag: "span", Class: breadcrumbItemClass(it), Attrs: breadcrumbCurrent(it)}) {
{ it.Label }
}
}
}
}
}
}
}
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 breadcrumbcompose/Breadcrumb.html.twig
{# Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. #}
{# Breadcrumb: Box nav > ol > li, Link or Text span. Params: items [{label, href, current, disabled}], ariaLabel, class, attrs. #}
{% set lis %}{% for it in items|default([]) %}{% set c = 'text-sm ' ~ (it.current|default(false) ? 'font-medium' : (it.disabled|default(false) ? 'text-muted-foreground' : 'text-primary underline-offset-4 hover:underline')) %}{% set a = it.current|default(false) ? {'aria-current': 'page'} : {} %}{% set inner %}{% if it.href|default('') and not it.disabled|default(false) %}{{ include('ui/link/Link.html.twig', {href: it.href, class: c, attrs: a, children: it.label|default('')|e}, with_context = false)|trim|raw }}{% else %}{{ include('ui/text/Text.html.twig', {tag: 'span', class: c, attrs: a, children: it.label|default('')|e}, with_context = false)|trim|raw }}{% endif %}{% endset %}{{ include('ui/box/Box.html.twig', {tag: 'li', class: 'inline-flex items-center', children: inner}, with_context = false)|trim|raw }}{% endfor %}{% endset %}
{% set ol %}{{ include('ui/box/Box.html.twig', {tag: 'ol', class: 'flex flex-wrap items-center gap-2', children: lis}, with_context = false)|trim|raw }}{% endset %}
{{ include('ui/box/Box.html.twig', {tag: 'nav', class: compose_join(['text-sm', class|default('')]), attrs: {'aria-label': ariaLabel|default('') ?: 'Breadcrumb'}|merge(attrs|default({})), children: ol}, with_context = false)|trim|raw }}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 breadcrumbcompose/Breadcrumb.latte
{* Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT. *}
{* Breadcrumb: Box nav > ol > li, Link or Text span. Includes inherit variables: shadowed params are passed explicitly. *}
{parameters
array $items = [],
string $ariaLabel = '',
string $class = '',
array $attrs = [],
}
{capture $lis}{foreach $items as $it}{var $c = 'text-sm ' . (($it['current'] ?? false) ? 'font-medium' : (($it['disabled'] ?? false) ? 'text-muted-foreground' : 'text-primary underline-offset-4 hover:underline'))}{var $a = ($it['current'] ?? false) ? ['aria-current' => 'page'] : []}{capture $inner}{if ($it['href'] ?? '') !== '' && !($it['disabled'] ?? false)}{include '../ui/link/Link.latte', href: $it['href'], class: $c, ariaLabel: null, attrs: $a, children: htmlspecialchars((string) ($it['label'] ?? ''), \ENT_QUOTES)}{else}{include '../ui/text/Text.latte', tag: 'span', class: $c, attrs: $a, children: htmlspecialchars((string) ($it['label'] ?? ''), \ENT_QUOTES)}{/if}{/capture}{include '../ui/box/Box.latte', tag: 'li', class: 'inline-flex items-center', attrs: [], children: (string) $inner}{/foreach}{/capture}
{capture $ol}{include '../ui/box/Box.latte', tag: 'ol', class: 'flex flex-wrap items-center gap-2', attrs: [], children: (string) $lis}{/capture}
{include '../ui/box/Box.latte', tag: 'nav', class: \CodegenX\Compose\Latte\Compose::join(['text-sm', $class]), attrs: ['aria-label' => $ariaLabel !== '' ? $ariaLabel : 'Breadcrumb', ...$attrs], children: (string) $ol}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 breadcrumbcompose/breadcrumb.html.j2
{#- Code generated by packages/kit-compose/src/build.ts from src/map.ts + variants/. DO NOT EDIT.
Breadcrumb: Box nav > ol > li, Link or Text span. Props (p): Items [{label, href, current, disabled}], AriaLabel, Class, Attrs. -#}
{%- set lis %}{% for it in p['Items'] or [] %}{% set c = compose_join(['text-sm', 'font-medium' if it['current'] else ('text-muted-foreground' if it['disabled'] else 'text-primary underline-offset-4 hover:underline')]) %}{% set a = {'aria-current': 'page'} if it['current'] else {} %}{% set inner %}{% if it['href'] and not it['disabled'] %}{% with p = {'Href': it['href'], 'Class': c, 'Attrs': a}, children = it['label']|e %}{% include 'ui/link/link.html.j2' %}{% endwith %}{% else %}{% with p = {'Tag': 'span', 'Class': c, 'Attrs': a}, children = it['label']|e %}{% include 'ui/text/text.html.j2' %}{% endwith %}{% endif %}{% endset %}{% with p = {'Tag': 'li', 'Class': 'inline-flex items-center'}, children = inner %}{% include 'ui/box/box.html.j2' %}{% endwith %}{% endfor %}{% endset %}
{%- set ol %}{% with p = {'Tag': 'ol', 'Class': 'flex flex-wrap items-center gap-2'}, children = lis %}{% include 'ui/box/box.html.j2' %}{% endwith %}{% endset %}
{%- set a = {'aria-label': p['AriaLabel'] or 'Breadcrumb'} %}{%- set _ = a.update(p['Attrs'] or {}) %}
{%- with p = {'Tag': 'nav', 'Class': compose_join(['text-sm', p['Class']]), 'Attrs': a}, children = ol %}{% include 'ui/box/box.html.j2' %}{% endwith %}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.
No props.