Files
Trilium/apps/client/src/widgets/react/NoteLink.tsx

34 lines
967 B
TypeScript
Raw Normal View History

2025-08-22 17:31:06 +03:00
import { useEffect, useMemo, useState } from "preact/hooks";
import link from "../../services/link";
import RawHtml from "./RawHtml";
interface NoteLinkOpts {
notePath: string | string[];
showNotePath?: boolean;
2025-08-22 19:27:58 +03:00
style?: Record<string, string | number>;
noPreview?: boolean;
2025-08-22 17:31:06 +03:00
}
export default function NoteLink({ notePath, showNotePath, style, noPreview }: NoteLinkOpts) {
2025-08-22 17:31:06 +03:00
const stringifiedNotePath = Array.isArray(notePath) ? notePath.join("/") : notePath;
const [ jqueryEl, setJqueryEl ] = useState<JQuery<HTMLElement>>();
useEffect(() => {
2025-08-22 19:27:58 +03:00
link.createLink(stringifiedNotePath, { showNotePath })
2025-08-22 17:31:06 +03:00
.then(setJqueryEl);
2025-08-22 19:27:58 +03:00
}, [ stringifiedNotePath, showNotePath ]);
if (style) {
jqueryEl?.css(style);
}
2025-08-22 17:31:06 +03:00
const $linkEl = jqueryEl?.find("a");
if (noPreview) {
$linkEl?.addClass("no-tooltip-preview");
}
$linkEl?.addClass("tn-link");
2025-08-22 17:31:06 +03:00
return <RawHtml html={jqueryEl} />
}