Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(react): use component for map type switcher
Elian Doranad5ff6e41a32
diff --git a/apps/client/src/widgets/note_map/NoteMap.tsx b/apps/client/src/widgets/note_map/NoteMap.tsxindex ce062be203..c9f73f6b99 100644--- a/apps/client/src/widgets/note_map/NoteMap.tsx+++ b/apps/client/src/widgets/note_map/NoteMap.tsx@@ -67,21 +67,8 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {return (<div className="note-map-widget"><div className="btn-group btn-group-sm map-type-switcher content-floating-buttons top-left" role="group">- <ActionButton- icon="bx bx-network-chart"- text={t("note-map.button-link-map")}- disabled={mapType === "link"}- onClick={() => setMapType("link")}- frame- />-- <ActionButton- icon="bx bx-sitemap"- text={t("note-map.button-tree-map")}- disabled={mapType === "tree"}- onClick={() => setMapType("tree")}- frame- />+ <MapTypeSwitcher type="link" icon="bx bx-network-chart" text={t("note-map.button-link-map")} currentMapType={mapType} setMapType={setMapType} />+ <MapTypeSwitcher type="tree" icon="bx bx-sitemap" text={t("note-map.button-tree-map")} currentMapType={mapType} setMapType={setMapType} /></div><div ref={styleResolverRef} class="style-resolver" />@@ -90,6 +77,23 @@ export default function NoteMap({ note, widgetMode, parentRef }: NoteMapProps) {)}+function MapTypeSwitcher({ icon, text, type, currentMapType, setMapType }: {+ icon: string;+ text: string;+ type: MapType;+ currentMapType: MapType;+ setMapType: (type: MapType) => void;+}) {+ return (+ <ActionButton+ icon={icon} text={text}+ disabled={currentMapType === type}+ onClick={() => setMapType(type)}+ frame+ />+ )+}+function getCssData(container: HTMLElement, styleResolver: HTMLElement): CssData {const containerStyle = window.getComputedStyle(container);const styleResolverStyle = window.getComputedStyle(styleResolver);