forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

breadcrumbs.tsx49 lines, 1.5 KiBHistoryRawDownload
1import { For, Show } from "solid-js";
2import { Link } from "@tanstack/solid-router";
3import { useT } from "@/stores/preferences-context";
4
5export type Crumb = {
6 label: string;
7 /** Route path, e.g. `/exams` or `/courses/$id`. Omit for the current page. */
8 to?: string;
9 params?: Record<string, string>;
10 search?: Record<string, unknown>;
11};
12
13/**
14 * Hub → record trail above a detail page header. The last crumb is the
15 * current page and is not a link.
16 */
17export function Breadcrumbs(props: { items: Crumb[] }) {
18 const t = useT();
19 return (
20 <nav aria-label={t("common.breadcrumb")}>
21 <ol class="detail-breadcrumb">
22 <For each={props.items}>
23 {(item, index) => {
24 const last = () => index() === props.items.length - 1;
25 return (
26 <li class="flex min-w-0 items-center gap-1.5">
27 <Show
28 when={item.to && !last()}
29 fallback={
30 <span class="truncate text-foreground" aria-current={last() ? "page" : undefined}>
31 {item.label}
32 </span>
33 }
34 >
35 <Link to={item.to as never} params={item.params as never} search={(item.search ?? {}) as never} class="truncate">
36 {item.label}
37 </Link>
38 </Show>
39 <Show when={!last()}>
40 <span aria-hidden="true">›</span>
41 </Show>
42 </li>
43 );
44 }}
45 </For>
46 </ol>
47 </nav>
48 );
49}