Skip to content

Build your personal knowledge base with Trilium Notes

client/right pane: create a toggle handle

Adorian Dorane1a957478f39
diff --git a/apps/client/src/widgets/sidebar/RightPaneToggleHandle.css b/apps/client/src/widgets/sidebar/RightPaneToggleHandle.css
new file mode 100644
index 0000000000..7c833cb8f5
--- /dev/null
+++ b/apps/client/src/widgets/sidebar/RightPaneToggleHandle.css
@@ -0,0 +1,29 @@
+/* Minimal functional styling only — refine visuals later. */
+
+/* Always reserve the 12px handle strip on the left of the pane, even when it is
+ collapsed to no content, and give the handle a positioned ancestor to anchor to. */
+body.experimental-feature-new-layout #right-pane {
+ position: relative;
+ min-width: 12px;
+ padding-inline-start: 12px;
+}
+
+/* Doubled class to win specificity over the shared `.icon-action` button rules. */
+body.experimental-feature-new-layout #right-pane .right-pane-toggle-handle.right-pane-toggle-handle {
+ position: absolute;
+ inset-inline-start: 0; /* Inside the pane's left edge so `overflow: auto` does not clip it. */
+ top: 0;
+ width: 12px;
+ height: 100%;
+ z-index: 10;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ padding: 0;
+ border-radius: 0;
+ cursor: pointer;
+}
+
+body.experimental-feature-new-layout #right-pane .right-pane-toggle-handle.right-pane-toggle-handle:hover {
+ background-color: var(--hover-item-background-color);
+}
diff --git a/apps/client/src/widgets/sidebar/RightPaneToggleHandle.tsx b/apps/client/src/widgets/sidebar/RightPaneToggleHandle.tsx
new file mode 100644
index 0000000000..0447e81318
--- /dev/null
+++ b/apps/client/src/widgets/sidebar/RightPaneToggleHandle.tsx
@@ -0,0 +1,61 @@
+import "./RightPaneToggleHandle.css";
+
+import { Tooltip } from "bootstrap";
+import clsx from "clsx";
+import { useCallback, useMemo, useRef, useState } from "preact/hooks";
+
+import appContext from "../../components/app_context";
+import { t } from "../../services/i18n";
+import options from "../../services/options";
+import { useStaticTooltip, useTriliumEvent } from "../react/hooks";
+
+export default function RightPaneToggleHandle() {
+ const buttonRef = useRef<HTMLButtonElement>(null);
+ // Pointer's vertical position captured once on hover; null until the mouse enters
+ // (e.g. on keyboard focus) so the tooltip falls back to the handle's centre.
+ const pointerY = useRef<number | null>(null);
+ const [ rightPaneVisible, setRightPaneVisible ] = useState(options.is("rightPaneVisible"));
+
+ // Mirror the state so the arrow direction stays in sync; RightPanelContainer owns persistence.
+ useTriliumEvent("toggleRightPane", useCallback(() => {
+ setRightPaneVisible(current => !current);
+ }, []));
+
+ const handleClick = useCallback(() => {
+ appContext.triggerCommand("toggleRightPane");
+ // Reset Bootstrap's hover/focus trigger state. A click otherwise leaves the button
+ // focused, which keeps the tooltip "stuck" and prevents it re-triggering on next hover.
+ const button = buttonRef.current;
+ if (button) {
+ Tooltip.getInstance(button)?.hide();
+ button.blur();
+ }
+ }, []);
+
+ // Anchor the tooltip to the pointer's entry height rather than the centre of the
+ // full-height handle, by shifting it along the cross axis. Not tracked: `pointerY`
+ // is only updated on mouse enter, and the offset is recomputed from it on show.
+ const tooltipConfig = useMemo(() => ({
+ title: t("right_pane.toggle"),
+ placement: "left" as const,
+ offset: () => {
+ const rect = buttonRef.current?.getBoundingClientRect();
+ if (!rect || pointerY.current === null) return [ 0, 0 ] as [number, number];
+ return [ pointerY.current - (rect.top + rect.height / 2), 0 ] as [number, number];
+ }
+ }), []);
+ useStaticTooltip(buttonRef, tooltipConfig);
+
+ return (
+ <button
+ ref={buttonRef}
+ class={clsx(
+ "right-pane-toggle-handle icon-action bx",
+ rightPaneVisible ? "bx-chevron-right" : "bx-chevron-left",
+ rightPaneVisible ? "right-pane-toggle-handle-action-collapse" : "right-pane-toggle-handle-action-expand"
+ )}
+ onMouseEnter={(e) => { pointerY.current = e.clientY; }}
+ onClick={handleClick}
+ />
+ );
+}
diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
index a59d80d6e4..c512e60a4e 100644
--- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
+++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx
@@ -21,6 +21,7 @@ import PdfAnnotations from "./pdf/PdfAnnotations";
import PdfAttachments from "./pdf/PdfAttachments";
import PdfLayers from "./pdf/PdfLayers";
import PdfPages from "./pdf/PdfPages";
+import RightPaneToggleHandle from "./RightPaneToggleHandle";
import RightPanelWidget from "./RightPanelWidget";
import TableOfContents from "./TableOfContents";
@@ -46,6 +47,7 @@ export default function RightPanelContainer({ widgetsByParent }: { widgetsByPare
return (
<div id="right-pane">
+ <RightPaneToggleHandle />
{rightPaneVisible && (
items.length > 0 ? (
items