From 5dc3ec88d4f99fe7f34d005f2bcc2e20a0914fb4 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sun, 28 Jun 2026 23:29:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(webui):=20smooth=20sidebar=20collapse=20?= =?UTF-8?q?=E2=80=94=20no=20reflow,=20centered=20icons,=20pin=20button?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The hover-rail flipped its content to a collapsed layout instantly while the width animated, so on every expand/collapse icons jumped toward the top-left and labels flashed in, wrapped super-tall, then settled — and the collapsed rail leaked the first glyph of every label plus hard-clipped highlight bars. Lay the rail content out at a fixed width and let the aside clip it: nothing reflows during the width animation. Icons live in a fixed centered column (never move); labels stay mounted with nowrap and just fade out when collapsed (no wrap, no leak); the active pill and update banner render their background as an absolute layer that becomes a centered squircle on the rail instead of a hard-clipped bar. Adds the promised pin toggle to the sidebar footer (desktop) — mirrors the 「钉住侧栏展开」 appearance setting: pinned keeps the rail open, unpinned returns to hover-to-peek. --- .../src/components/layout/main-layout.tsx | 8 +- .../webui/src/components/layout/sidebar.tsx | 141 +++++++++++------- 2 files changed, 97 insertions(+), 52 deletions(-) diff --git a/packages/webui/src/components/layout/main-layout.tsx b/packages/webui/src/components/layout/main-layout.tsx index 512abe9f..81515f8e 100644 --- a/packages/webui/src/components/layout/main-layout.tsx +++ b/packages/webui/src/components/layout/main-layout.tsx @@ -66,7 +66,13 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) { }} className="relative h-full shrink-0 overflow-hidden" > - + {/* Fixed-width inner: the rail's content is ALWAYS laid out at the + expanded width and the aside simply clips it as `width` animates. + Nothing reflows during the transition, so icons never shift and + labels never wrap — they're revealed/clipped, not re-laid-out. */} +
+ +
)} diff --git a/packages/webui/src/components/layout/sidebar.tsx b/packages/webui/src/components/layout/sidebar.tsx index 7deec9fd..66563353 100644 --- a/packages/webui/src/components/layout/sidebar.tsx +++ b/packages/webui/src/components/layout/sidebar.tsx @@ -1,11 +1,13 @@ -import { Bug, Check, Eye, EyeOff, GripVertical, LayoutDashboard, Lock, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal } from 'lucide-react'; +import { Bug, Check, Eye, EyeOff, GripVertical, LayoutDashboard, Lock, Pin, PinOff, PlugZap, Settings, Sparkles, SlidersHorizontal, Terminal } from 'lucide-react'; import { motion, Reorder } from 'motion/react'; import { Link, useRouterState } from '@tanstack/react-router'; import { ScrollArea } from '@/components/ui/scroll-area'; import { cn } from '@/lib/utils'; import { APP_NAME, APP_VERSION } from '@/types'; import { useAppState } from '@/contexts/AppStateContext'; +import { useTheme } from '@/contexts/ThemeContext'; import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext'; +import { useMediaQuery } from '@/hooks/use-media-query'; import type { AppPath } from '@/router'; export interface NavItem { @@ -39,6 +41,9 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) { const pathname = useRouterState({ select: (s) => s.location.pathname }); const { updateInfo } = useAppState(); const { navItems, setNavItems, editing, setEditing } = useLayout(); + const { appearance, setAppearance } = useTheme(); + const isDesktop = useMediaQuery('(min-width: 768px)'); + const pinned = appearance.sidebarPinned; // Full reconciled nav (incl. hidden) — pinned forced visible, forward-compat. const reconciled = reconcileLayoutItems(navItems, NAV_ITEMS.map((i) => i.to), PINNED_NAV); @@ -56,21 +61,23 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) { setNavItems(reconciled.map((i) => (i.id === id ? { ...i, visible: !i.visible } : i))); return ( -
- {/* Brand */} -
-
- SnowLuma -
- {!collapsed && ( -
-
- {APP_NAME} - v{APP_VERSION} -
- OneBot v11 控制台 +
+ {/* Brand — logo sits in a fixed 48px column centred in the collapsed + rail; the wordmark to its right is clipped (never unmounted) when the + rail narrows. */} +
+
+
+ SnowLuma
- )} +
+
+
+ {APP_NAME} + v{APP_VERSION} +
+ OneBot v11 控制台 +
{/* Nav */} @@ -92,7 +99,7 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) { const meta = NAV_ITEMS.find((n) => n.to === item.id); if (!meta) return null; const Icon = meta.icon; - const pinned = (PINNED_NAV as string[]).includes(item.id); + const itemPinned = (PINNED_NAV as string[]).includes(item.id); return ( {meta.label} - {pinned ? ( + {itemPinned ? ( @@ -126,7 +133,7 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
) : ( -