From 682c61305c9e850928233993e92526a0c74a06e8 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 18 Dec 2025 14:42:21 +0200 Subject: [PATCH] chore(right_pane): basic collapse support --- .../widgets/sidebar/RightPanelContainer.css | 4 ++ .../widgets/sidebar/RightPanelContainer.tsx | 41 +++++++++++++++++-- .../src/widgets/sidebar/RightPanelWidget.tsx | 26 ++++++++++-- 3 files changed, 63 insertions(+), 8 deletions(-) diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.css b/apps/client/src/widgets/sidebar/RightPanelContainer.css index 631480c1b..d737e9d52 100644 --- a/apps/client/src/widgets/sidebar/RightPanelContainer.css +++ b/apps/client/src/widgets/sidebar/RightPanelContainer.css @@ -13,5 +13,9 @@ body.experimental-feature-new-layout #right-pane { &:last-of-type { border-bottom: 0; } + + &.collapsed .card-header > .bx { + transform: rotate(-90deg); + } } } diff --git a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx index d3ec7e912..ef0af28f0 100644 --- a/apps/client/src/widgets/sidebar/RightPanelContainer.tsx +++ b/apps/client/src/widgets/sidebar/RightPanelContainer.tsx @@ -2,7 +2,8 @@ import "./RightPanelContainer.css"; import Split from "@triliumnext/split.js"; -import { useEffect } from "preact/hooks"; +import { createContext } from "preact"; +import { useEffect, useRef } from "preact/hooks"; import options from "../../services/options"; import { DEFAULT_GUTTER_SIZE } from "../../services/resizer"; @@ -10,6 +11,11 @@ import HighlightsList from "./HighlightsList"; import TableOfContents from "./TableOfContents"; const MIN_WIDTH_PERCENT = 5; +const COLLAPSED_SIZE = 32; + +export const RightPanelContext = createContext({ + setExpanded(cardEl: HTMLElement, expanded: boolean) {} +}); export default function RightPanelContainer() { // Split between right pane and the content pane. @@ -32,19 +38,46 @@ export default function RightPanelContainer() { ]; // Split between items. + const innerSplitRef = useRef(null); useEffect(() => { const rightPaneContainer = document.getElementById("right-pane"); const elements = Array.from(rightPaneContainer?.children ?? []) as HTMLElement[]; - console.log("Got ", elements); const splitInstance = Split(elements, { - direction: "vertical" + direction: "vertical", + minSize: COLLAPSED_SIZE, + gutterSize: 1 }); + innerSplitRef.current = splitInstance; return () => splitInstance.destroy(); }, [ items ]); return (
- {items} + .card") ?? []); + const pos = children.indexOf(cardEl); + if (pos === -1) return; + const sizes = splitInstance.getSizes(); + if (!expanded) { + const sizeBeforeCollapse = sizes[pos]; + sizes[pos] = 0; + const itemToExpand = pos > 0 ? pos - 1 : pos + 1; + + if (sizes[itemToExpand] > COLLAPSED_SIZE) { + sizes[itemToExpand] += sizeBeforeCollapse; + } + } + console.log("Set sizes to ", sizes); + splitInstance.setSizes(sizes); + }, + }}> + {items} +
); } diff --git a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx index 94a5cf04c..7f4391d6c 100644 --- a/apps/client/src/widgets/sidebar/RightPanelWidget.tsx +++ b/apps/client/src/widgets/sidebar/RightPanelWidget.tsx @@ -1,6 +1,10 @@ -import { useContext, useRef } from "preact/hooks"; -import { ParentComponent } from "../react/react_utils"; +import clsx from "clsx"; import { ComponentChildren } from "preact"; +import { useContext, useRef, useState } from "preact/hooks"; + +import Icon from "../react/Icon"; +import { ParentComponent } from "../react/react_utils"; +import { RightPanelContext } from "./RightPanelContainer"; interface RightPanelWidgetProps { title: string; @@ -9,6 +13,8 @@ interface RightPanelWidgetProps { } export default function RightPanelWidget({ title, buttons, children }: RightPanelWidgetProps) { + const rightPanelContext = useContext(RightPanelContext); + const [ expanded, setExpanded ] = useState(true); const containerRef = useRef(null); const parentComponent = useContext(ParentComponent); @@ -17,15 +23,27 @@ export default function RightPanelWidget({ title, buttons, children }: RightPane } return ( -
+
+ { + if (containerRef.current) { + rightPanelContext.setExpanded(containerRef.current, !expanded); + } + setExpanded(!expanded); + }} + />
{title}
{buttons}
- {children} + {expanded && children}