Skip to content

Build your personal knowledge base with Trilium Notes

style(mind-map): dress the view controls as the image viewer's

Elian Doran993a2aa468ff
diff --git a/apps/client/src/stylesheets/theme-next/forms.css b/apps/client/src/stylesheets/theme-next/forms.css
index 5ca14c368f..a58044fa1a 100644
--- a/apps/client/src/stylesheets/theme-next/forms.css
+++ b/apps/client/src/stylesheets/theme-next/forms.css
@@ -292,6 +292,19 @@ button.tn-low-profile:hover {
border-radius: var(--_start-border-radius, 0) var(--_end-border-radius, 0) var(--_end-border-radius, 0) var(--_start-border-radius, 0);
}
+ /* A button that would do nothing says as much rather than merely failing to answer. */
+ &:disabled {
+ opacity: .4;
+ pointer-events: none;
+ }
+
+ /* A readout standing among the buttons — a zoom level, a scale — disabled only to stand
+ inert on the group's surface. It is not a refused action, and does not wear the refused
+ look. */
+ &.tn-overlay-readout:disabled {
+ opacity: 1;
+ }
+
}
}
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index ebe76ba37b..31a96c2876 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3595,6 +3595,7 @@
"remove-tag": "Remove this tag",
"zoom-in": "Zoom in",
"zoom-out": "Zoom out",
+ "reset-zoom": "Reset zoom",
"center-map": "Center the map",
"fullscreen": "Fullscreen",
"exit-fullscreen": "Exit fullscreen",
diff --git a/apps/client/src/widgets/collections/geomap/MapToolbar.css b/apps/client/src/widgets/collections/geomap/MapToolbar.css
index 216a2f96af..0f38e81fda 100644
--- a/apps/client/src/widgets/collections/geomap/MapToolbar.css
+++ b/apps/client/src/widgets/collections/geomap/MapToolbar.css
@@ -28,15 +28,3 @@
--opaque-icon-button-hover-color: var(--geo-map-panel-hover-text-color);
}
-/* A button that would do nothing says as much rather than merely failing to answer — the group's
- own styling leaves a disabled button looking ready (see OverlayToolbar.css for the same rule). */
-.geo-map-container .geo-map-toolbar button:disabled {
- opacity: .4;
- pointer-events: none;
-}
-
-/* The readout between the steps is disabled only to stand inert (see MapToolbar.tsx); it is not a
- refused action, and does not wear the refused look. */
-.geo-map-container .geo-map-toolbar .geo-map-zoom-level:disabled {
- opacity: 1;
-}
diff --git a/apps/client/src/widgets/collections/geomap/MapToolbar.tsx b/apps/client/src/widgets/collections/geomap/MapToolbar.tsx
index 668d2f402d..aa5653424c 100644
--- a/apps/client/src/widgets/collections/geomap/MapToolbar.tsx
+++ b/apps/client/src/widgets/collections/geomap/MapToolbar.tsx
@@ -63,10 +63,10 @@ export default function MapToolbar() {
fitted view, but a map has no such view to offer — so it only says where between the
ends the zoom stands, whole levels being all anyone does anything with. Disabled
rather than a plain span so it stays a child the group's styling knows; the refused
- look is taken off it in MapToolbar.css. */}
+ look is taken off it by `tn-overlay-readout` (see theme-next/forms.css). */}
<button
type="button"
- className="tn-overlay-text-button geo-map-zoom-level"
+ className="tn-overlay-text-button tn-overlay-readout geo-map-zoom-level"
disabled
>
{Math.round(current)}
diff --git a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.css b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.css
index 52e8a51285..549df1831d 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.css
+++ b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.css
@@ -1,13 +1,16 @@
/*
- * The bars are dressed as every bar standing over a canvas is (see OverlayToolbar.css), which is the
- * dress the node panel wears too (see NodePanel.css): the same surface, the same border and the same
- * blur, so that everything standing over a map reads as one family rather than as pieces from three
- * places. Left here is only what is the mind map's own — where they stand, and the marks a direction
- * is chosen by. How much room they leave the panel is settled between them in MindMap.css.
+ * The direction bar is dressed as every bar standing over a canvas is (see OverlayToolbar.css),
+ * which is the dress the node panel wears too (see NodePanel.css). The view controls at the foot
+ * are the image viewer's control group instead (see the overlay buttons in theme-next/forms.css),
+ * as the geo map's are. Left here is only what is the mind map's own — where each stands, and the
+ * marks a direction is chosen by. How much room they leave the panel is settled between them in
+ * MindMap.css.
*/
-/* What is done with the view stands at the foot of the map, out of the way of its root. */
+/* What is done with the view stands at the foot of the map, out of the way of its root. The control
+ group brings no place of its own the way the shared bar does, so it is pinned here. */
.mind-map-container .mind-map-view-toolbar {
+ position: absolute;
bottom: var(--mind-map-inset-bottom);
inset-inline-end: var(--mind-map-inset);
}
diff --git a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsx b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsx
index f480b8c936..bbdd75ecd7 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.spec.tsx
@@ -67,11 +67,13 @@ function buildMind({ scaleVal = 1, direction = 1, isFocusMode = false } = {}) {
return mind;
}
-/** The order the view bar lays its buttons out in. */
-const ZOOM_IN = 0;
-const ZOOM_OUT = 1;
-const CENTER = 2;
-const FULLSCREEN = 3;
+/** The order the view group lays its buttons out in, the map showing all it has — while it is
+ * narrowed, the way out of focus mode leads and everything below stands one further along. */
+const ZOOM_OUT = 0;
+const ZOOM_LEVEL = 1;
+const ZOOM_IN = 2;
+const CENTER = 3;
+const FULLSCREEN = 4;
/** The order the direction bar lays its buttons out in. */
const LEFT = 0;
@@ -89,8 +91,12 @@ function renderBar(bar: ComponentChild) {
const renderToolbar = (mind: MindElixirInstance) => renderBar(<MapToolbar mind={mind} />);
const renderDirections = (mind: MindElixirInstance) => renderBar(<DirectionToolbar mind={mind} />);
+/* The view controls stand on the image viewer's control group, the direction bar on the shared
+ overlay bar — one helper serves both describes. */
function buttons(container: HTMLElement) {
- return [ ...container.querySelectorAll<HTMLButtonElement>(".tn-overlay-toolbar button") ];
+ return [ ...container.querySelectorAll<HTMLButtonElement>(
+ ".tn-overlay-control-group button, .tn-overlay-toolbar button"
+ ) ];
}
function press(container: HTMLElement, index: number) {
@@ -109,12 +115,16 @@ beforeEach(() => {
});
describe("MapToolbar", () => {
- it("offers the four things the map's own bar did, in one row", () => {
+ it("offers what the map's own bar did, laid out as the image viewer's group", () => {
const container = renderToolbar(buildMind());
- expect(buttons(container)).toHaveLength(4);
- expect(buttons(container)[CENTER].className).toContain("bx-current-location");
- expect(buttons(container)[FULLSCREEN].className).toContain("bx-fullscreen");
+ expect(buttons(container).map((button) => button.className)).toEqual([
+ expect.stringContaining("bx-minus-circle"),
+ expect.stringContaining("tn-overlay-text-button"),
+ expect.stringContaining("bx-plus-circle"),
+ expect.stringContaining("bx-current-location"),
+ expect.stringContaining("bx-fullscreen")
+ ]);
});
it("keeps the way out of focus mode off the bar while there is nothing to leave", () => {
@@ -127,14 +137,14 @@ describe("MapToolbar", () => {
const mind = buildMind({ isFocusMode: true });
const container = renderToolbar(mind);
- // Leading the bar: it is the one thing there that undoes a state the map is being read in.
- expect(buttons(container)).toHaveLength(5);
+ // Leading the group: it is the one thing there that undoes a state the map is being read in.
+ expect(buttons(container)).toHaveLength(6);
expect(buttons(container)[0].className).toContain("bx-exit");
press(container, 0);
expect(mind.cancelFocus).toHaveBeenCalled();
- expect(buttons(container)).toHaveLength(4);
+ expect(buttons(container)).toHaveLength(5);
});
it("zooms by one step of the map's own sensitivity, in either direction", () => {
@@ -167,6 +177,20 @@ describe("MapToolbar", () => {
expect(buttons(container)[ZOOM_IN].disabled).toBe(true);
});
+ it("says the scale the map is drawn at, and pressed, takes the map back to its own size", () => {
+ const mind = buildMind();
+ const container = renderToolbar(mind);
+ expect(buttons(container)[ZOOM_LEVEL].textContent).toBe("100%");
+
+ act(() => mind.scale(1.35));
+ expect(buttons(container)[ZOOM_LEVEL].textContent).toBe("135%");
+
+ // As the image viewer's readout does — a mind map has a natural size to be reset to.
+ press(container, ZOOM_LEVEL);
+ expect(vi.mocked(mind.scale)).toHaveBeenLastCalledWith(1);
+ expect(buttons(container)[ZOOM_LEVEL].textContent).toBe("100%");
+ });
+
it("centres the map", () => {
const mind = buildMind();
const container = renderToolbar(mind);
diff --git a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsx b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsx
index 2c50246293..e1372af538 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsx
+++ b/apps/client/src/widgets/type_widgets/mind_map/MapToolbar.tsx
@@ -4,7 +4,7 @@ import type { MindElixirInstance } from "mind-elixir";
import { useCallback, useEffect, useRef, useState } from "preact/hooks";
import { t } from "../../../services/i18n";
-import { useFullscreen } from "../../react/hooks";
+import { useFullscreen, useStaticTooltip } from "../../react/hooks";
import OverlayToolbar, { OverlayToolbarButton } from "../../react/OverlayToolbar";
import { centerMapOn, type MapPoint, readMapCenter, stepZoom } from "./viewport";
@@ -13,66 +13,108 @@ interface MapToolbarProps {
}
/**
- * The bar standing in the bottom corner of a mind map: the scale the map is drawn at, where it
+ * The controls standing in the bottom corner of a mind map: the scale the map is drawn at, where it
* stands, and how much of the screen it is given.
*
* Mind Elixir lays two bars of its own over a map — this corner and the one opposite (see
* {@link DirectionToolbar}) — which are left out entirely (`toolBar: false`, see MindMap.tsx). They
* were dressed in neither Trilium's buttons nor Trilium's colors, standing on a surface of their own
* beside the node panel they share the map with. Everything they did is done here, over the same
- * instance.
+ * instance, on the control group the image viewer's zoom buttons stand on
+ * (`tn-overlay-control-group`, see {@link ImageViewer}), as the geo map's controls are. The readout
+ * between the steps says the scale the way the image viewer says it — a hundred being the map drawn
+ * at its own size — and pressed, takes the map back there, as the image viewer's does: unlike a geo
+ * map, a mind map has a natural size to be reset to.
*/
export default function MapToolbar({ mind }: MapToolbarProps) {
const scale = useMapScale(mind);
const isFocused = useMapFocus(mind);
const [ isFullscreen, toggleFullscreen ] = useMapFullscreen(mind);
+ const exitFocusRef = useRef<HTMLButtonElement>(null);
+ const zoomOutRef = useRef<HTMLButtonElement>(null);
+ const zoomLevelRef = useRef<HTMLButtonElement>(null);
+ const zoomInRef = useRef<HTMLButtonElement>(null);
+ const centerRef = useRef<HTMLButtonElement>(null);
+ const fullscreenRef = useRef<HTMLButtonElement>(null);
+
+ // The group stands at the foot of the map, so its tooltips open away from that edge, where
+ // they would otherwise fall off.
+ useStaticTooltip(exitFocusRef, { title: t("mind-map.cancelFocus"), placement: "top" });
+ useStaticTooltip(zoomOutRef, { title: t("mind-map.zoom-out"), placement: "top" });
+ useStaticTooltip(zoomLevelRef, { title: t("mind-map.reset-zoom"), placement: "top" });
+ useStaticTooltip(zoomInRef, { title: t("mind-map.zoom-in"), placement: "top" });
+ useStaticTooltip(centerRef, { title: t("mind-map.center-map"), placement: "top" });
+ useStaticTooltip(fullscreenRef, {
+ title: isFullscreen ? t("mind-map.exit-fullscreen") : t("mind-map.fullscreen"),
+ placement: "top"
+ });
+
const limits = { sensitivity: mind.scaleSensitivity, min: mind.scaleMin, max: mind.scaleMax };
const zoomedIn = stepZoom(scale, 1, limits);
const zoomedOut = stepZoom(scale, -1, limits);
return (
- // The bar stands at the foot of the map, so its tooltips open away from that edge, where
- // they would otherwise fall off.
- <OverlayToolbar className="mind-map-view-toolbar" titlePosition="top">
+ <div
+ className="mind-map-view-toolbar tn-overlay-control-group"
+ /* Keep a press on the controls from reaching the canvas underneath, which would
+ otherwise take it for the start of a drag or a selection. */
+ onMouseDown={(e) => e.stopPropagation()}
+ >
{/* Leaving focus mode is about the map rather than about any one node, so it stands
here rather than in the menu a node is right-clicked for — which is where Mind
Elixir kept it, offered on every node whether the map was narrowed or not. It is
only here while there is something to leave, the map otherwise showing all it has. */}
{isFocused && (
- <OverlayToolbarButton
- icon="bx bx-exit"
- text={t("mind-map.cancelFocus")}
+ <button
+ ref={exitFocusRef}
+ type="button"
+ className="tn-overlay-icon-button bx bx-exit"
+ aria-label={t("mind-map.cancelFocus")}
onClick={() => mind.cancelFocus()}
/>
)}
- <OverlayToolbarButton
- icon="bx bx-zoom-in"
- text={t("mind-map.zoom-in")}
- disabled={zoomedIn === null}
- onClick={() => zoomedIn !== null && mind.scale(zoomedIn)}
- />
-
- <OverlayToolbarButton
- icon="bx bx-zoom-out"
- text={t("mind-map.zoom-out")}
+ <button
+ ref={zoomOutRef}
+ type="button"
+ className="tn-overlay-icon-button bx bx-minus-circle"
+ aria-label={t("mind-map.zoom-out")}
disabled={zoomedOut === null}
onClick={() => zoomedOut !== null && mind.scale(zoomedOut)}
/>
-
- <OverlayToolbarButton
- icon="bx bx-current-location"
- text={t("mind-map.center-map")}
+ <button
+ ref={zoomLevelRef}
+ type="button"
+ className="tn-overlay-text-button mind-map-zoom-level"
+ aria-label={t("mind-map.reset-zoom")}
+ onClick={() => mind.scale(1)}
+ >
+ {Math.round(scale * 100)}%
+ </button>
+ <button
+ ref={zoomInRef}
+ type="button"
+ className="tn-overlay-icon-button bx bx-plus-circle"
+ aria-label={t("mind-map.zoom-in")}
+ disabled={zoomedIn === null}
+ onClick={() => zoomedIn !== null && mind.scale(zoomedIn)}
+ />
+ <button
+ ref={centerRef}
+ type="button"
+ className="tn-overlay-icon-button bx bx-current-location"
+ aria-label={t("mind-map.center-map")}
onClick={() => mind.toCenter()}
/>
-
- <OverlayToolbarButton
- icon={isFullscreen ? "bx bx-exit-fullscreen" : "bx bx-fullscreen"}
- text={isFullscreen ? t("mind-map.exit-fullscreen") : t("mind-map.fullscreen")}
+ <button
+ ref={fullscreenRef}
+ type="button"
+ className={`tn-overlay-icon-button bx ${isFullscreen ? "bx-exit-fullscreen" : "bx-fullscreen"}`}
+ aria-label={isFullscreen ? t("mind-map.exit-fullscreen") : t("mind-map.fullscreen")}
onClick={toggleFullscreen}
/>
- </OverlayToolbar>
+ </div>
);
}
diff --git a/apps/client/src/widgets/type_widgets/mind_map/MindMap.css b/apps/client/src/widgets/type_widgets/mind_map/MindMap.css
index 0a6e742863..09560251da 100644
--- a/apps/client/src/widgets/type_widgets/mind_map/MindMap.css
+++ b/apps/client/src/widgets/type_widgets/mind_map/MindMap.css
@@ -14,12 +14,14 @@
* the map are the edges of the screen and part of them may not be the screen's to draw on.
*/
.mind-map-container {
- --mind-map-inset: 20px;
+ /* The very room the image viewer keeps its controls at, taken from the shared name rather than
+ restated (see the overlay buttons in theme-next/base.css), as the geo map takes it too. */
+ --mind-map-inset: var(--overlay-button-inset, 10px);
--mind-map-inset-top: var(--mind-map-inset);
--mind-map-inset-bottom: var(--mind-map-inset);
- /* What a row of icon buttons, its padding and its border come out at — the room the panel above
- the toolbar has to leave for it. */
- --mind-map-toolbar-height: 42px;
+ /* What the control group at the foot comes out at — the room the panel above it has to leave
+ for it. The image viewer's controls are the same height, being the same group. */
+ --mind-map-toolbar-height: var(--overlay-button-height, 28px);
}
/* Hosts our own floating UI on top of the map, without interfering with the DOM managed by Mind Elixir. */