hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { For, Show } from "solid-js"; |
| 2 | import { Link } from "@tanstack/solid-router"; |
| 3 | import { useT } from "@/stores/preferences-context"; |
| 4 | |
| 5 | export 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 | */ |
| 17 | export 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 | } |