refactor(react): use component for map type switcher

This commit is contained in:
Elian Doran 2025-10-04 12:58:24 +03:00
parent 20dcbff68f
commit ad5ff6e41a
No known key found for this signature in database

View file

@ -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);