Trilium/apps/client/src/widgets/Breadcrumb.tsx
2025-12-08 15:56:03 +02:00

39 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import "./Breadcrumb.css";
import { useNoteContext } from "./react/hooks";
import NoteLink from "./react/NoteLink";
import { joinElements } from "./react/react_utils";
export default function Breadcrumb() {
const { noteContext } = useNoteContext();
const notePath = buildNotePaths(noteContext?.notePathArray);
return (
<div className="breadcrumb">
{joinElements(notePath.map(item => (
<BreadcrumbItem key={item} notePath={item} />
)), <>&nbsp;&nbsp;</>)}
</div>
)
}
function BreadcrumbItem({ notePath }: { notePath: string }) {
return (
<NoteLink
notePath={notePath}
noPreview
/>
)
}
function buildNotePaths(notePathArray: string[] | undefined) {
if (!notePathArray) return [];
let prefix = "";
const output: string[] = [];
for (const notePath of notePathArray.slice(0, notePathArray.length - 1)) {
output.push(`${prefix}${notePath}`);
prefix += `${notePath}/`;
}
return output;
}