MCPcopy Create free account
hub / github.com/Qinbf/groundmap / LeftPanel

Function LeftPanel

web/components/LeftPanel.tsx:26–138  ·  view source on GitHub ↗
({
  children,
  initialCollapsed,
  initialWidth,
}: {
  children: ReactNode;
  initialCollapsed: boolean | null;
  initialWidth: number | null;
})

Source from the content-addressed store, hash-verified

24 * 显式存在则尊重用户选择,cookie 不存在才按视口宽度自动决定。
25 */
26export function LeftPanel({
27 children,
28 initialCollapsed,
29 initialWidth,
30}: {
31 children: ReactNode;
32 initialCollapsed: boolean | null;
33 initialWidth: number | null;
34}) {
35 const t = useT();
36 const [collapsed, setCollapsed] = useState<boolean>(initialCollapsed ?? false);
37 const userExplicitRef = useRef<boolean>(initialCollapsed !== null);
38 const { width, dragging, handleProps } = usePanelResize({
39 side: "left",
40 config: LEFT_PANEL,
41 initialWidth,
42 });
43
44 useEffect(() => {
45 if (userExplicitRef.current) return;
46 if (typeof window === "undefined") return;
47 if (window.matchMedia(AUTO_COLLAPSE_QUERY).matches) {
48 setCollapsed(true);
49 }
50 }, []);
51
52 const toggle = () => {
53 userExplicitRef.current = true;
54 setCollapsed((prev) => {
55 const next = !prev;
56 try {
57 document.cookie = `${COOKIE}=${
58 next ? "1" : "0"
59 }; path=/; max-age=${60 * 60 * 24 * 365}; SameSite=Lax`;
60 } catch {
61 // ignore
62 }
63 return next;
64 });
65 };
66
67 const baseButtonClass = cn(
68 "inline-flex h-6 w-6 items-center justify-center",
69 "rounded-full border border-border bg-background text-muted-foreground shadow-sm",
70 "hover:text-foreground hover:border-foreground/40 hover:scale-110",
71 "transition-[transform,color,border-color] duration-150",
72 );
73
74 if (collapsed) {
75 return (
76 <button
77 type="button"
78 onClick={toggle}
79 aria-label={t("panel.expand")}
80 title={t("panel.expand")}
81 className={cn(
82 baseButtonClass,
83 "fixed left-3 top-1/2 z-30 -translate-y-1/2 bg-background/90 backdrop-blur-sm",

Callers

nothing calls this directly

Calls 4

useTFunction · 0.90
usePanelResizeFunction · 0.90
cnFunction · 0.90
tFunction · 0.50

Tested by

no test coverage detected