返回 DeepSeek-Reasonix
useTopicbarHeightVar.ts
根目录 / desktop / frontend / src / lib / useTopicbarHeightVar.ts
1 // Publishes the shell bar's measured height as --app-bar-height on the document
2 // root. The bar is the layout's first grid row and sizes to its own content, so
3 // the two consumers that position themselves against its bottom edge — the
4 // sidebar resizer and the overlay dock — cannot read the height from CSS. It is
5 // not a constant: it differs per layout style, theme skin and platform caption.
6 import { useEffect } from "react";
7
8 const VAR = "--app-bar-height";
9
10 export function useTopicbarHeightVar(): void {
11 useEffect(() => {
12 const publish = () => {
13 const bar = document.querySelector<HTMLElement>(".topicbar");
14 if (!bar) return;
15 const height = Math.round(bar.getBoundingClientRect().height);
16 if (height > 0) document.documentElement.style.setProperty(VAR, `${height}px`);
17 };
18 publish();
19 const bar = document.querySelector<HTMLElement>(".topicbar");
20 if (!bar || typeof ResizeObserver === "undefined") {
21 window.addEventListener("resize", publish);
22 return () => window.removeEventListener("resize", publish);
23 }
24 const observer = new ResizeObserver(publish);
25 observer.observe(bar);
26 return () => {
27 observer.disconnect();
28 document.documentElement.style.removeProperty(VAR);
29 };
30 }, []);
31 }
32
32 lines TYPESCRIPT