Crumbs

tcmts.share.Crumbs · #ev7rzo53 · term · runs anywhere

A dotted name as links up through its namespaces (Trail); the last part is the page itself. A name under a mount the app knows (mountOf) starts from the mount, as the app calls it.

import { codeHref, mountOf, Trail } from "#codebase/tcmts/share";

export function Crumbs({ name }: { name: string }) {
  const m = mountOf.current?.(name);
  const base = m ? m.mount.split(".") : [];
  const parts = name.split(".");
  return (
    <Trail
      items={[
        ...(m ? [{ label: m.label, href: m.href }] : []),
        ...parts
          .map((p, i) => ({ label: p, href: codeHref(parts.slice(0, i + 1).join(".")) }))
          .slice(base.length),
      ]}
    />
  );
}

uses

used by