From bba9b82ce95748b98bb1d6536846a9c9a8a47c94 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sat, 20 Jun 2026 23:30:08 +0800 Subject: [PATCH] feat(webui): hover-expand sidebar rail + borderless nested-canvas chrome MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reshape the desktop shell to feel less "boxed-in", keeping the original visual design — boundaries now read via depth/tone, not hard borders. - Sidebar rests as a 64px icon rail and auto-expands on hover (or keyboard focus-visible), pushing the content rather than overlaying it. Removes the explicit collapse button; resting state is the rail (`effectiveCollapsed = !editing`), so it always auto-collapses on mouse-leave. - Drop hard region borders: sidebar border-r and topbar border-b/divider are gone; the rail blends into a sidebar-toned chrome. - Sidebar internal cleanup: brand border, the footer Separator, the update card / edit-item / 完成 button borders removed; active nav indicator is now a soft pill + sliding 2px primary left bar (layoutId). - Content is a nested canvas with a rounded top-left corner at the sidebar/topbar junction, lifted via a soft shadow; the corner slides with the rail since the canvas is its flex sibling. Note: the 「侧栏默认折叠」 appearance toggle (settings-page) is now inert for the main nav sidebar — to be repurposed as "pin open" or removed in a follow-up. --- .../src/components/layout/main-layout.tsx | 67 ++++++++++++------- .../webui/src/components/layout/sidebar.tsx | 27 +++++--- .../webui/src/components/layout/top-bar.tsx | 30 ++------- 3 files changed, 63 insertions(+), 61 deletions(-) diff --git a/packages/webui/src/components/layout/main-layout.tsx b/packages/webui/src/components/layout/main-layout.tsx index 30dfe59e..42e5cceb 100644 --- a/packages/webui/src/components/layout/main-layout.tsx +++ b/packages/webui/src/components/layout/main-layout.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState, type ReactNode } from 'react'; +import { useState, type ReactNode } from 'react'; import { motion, AnimatePresence } from 'motion/react'; import { useRouterState } from '@tanstack/react-router'; import { Minimize2 } from 'lucide-react'; @@ -21,14 +21,6 @@ interface MainLayoutProps { export function MainLayout({ status, onLogout, children }: MainLayoutProps) { const isMobile = !useMediaQuery('(min-width: 768px)'); const { appearance } = useTheme(); - const [collapsed, setCollapsed] = useState(() => { - // An explicit per-browser toggle wins; otherwise fall back to the - // operator's `sidebarDefaultCollapsed` appearance preference. - const explicit = localStorage.getItem('snowluma_sidebar_collapsed'); - if (explicit === '1') return true; - if (explicit === '0') return false; - return appearance.sidebarDefaultCollapsed; - }); const customBg = appearance.background.type !== 'none'; // Framer's reducedMotion only suppresses transforms, so the always-present // width + page-transition animations need an explicit opt-out to make the @@ -36,27 +28,44 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) { const reduce = appearance.reduceMotion || appearance.disableMotion; const { editing } = useLayout(); const { kiosk, exit: exitKiosk } = useKiosk(); - // Force the sidebar open while editing layout so its drag-to-reorder list - // has room (it returns to the user's collapsed pref on 完成). - const effectiveCollapsed = collapsed && !editing; + // The sidebar rests as a slim icon rail and auto-expands on hover/focus (the + // peek logic below) — there's no collapse button. Layout-edit mode force- + // expands it so the drag-to-reorder list has room. + const effectiveCollapsed = !editing; + // Hover/focus peek: while collapsed, hovering (or keyboard-focusing) the rail + // temporarily expands it. The rail lives in the flex flow, so the page + // content is pushed right rather than overlaid. The pinned `collapsed` pref + // (and the TopBar toggle that reflects it) is untouched — this is transient. + const [hovered, setHovered] = useState(false); + const [focused, setFocused] = useState(false); + const peeking = hovered || focused; + const showCollapsed = effectiveCollapsed && !peeking; const [mobileOpen, setMobileOpen] = useState(false); const pathname = useRouterState({ select: (s) => s.location.pathname }); - useEffect(() => { - localStorage.setItem('snowluma_sidebar_collapsed', collapsed ? '1' : '0'); - }, [collapsed]); - return ( -
+
{/* Desktop sidebar (hidden in kiosk) */} {!isMobile && !kiosk && ( setHovered(true)} + onMouseLeave={() => setHovered(false)} + onFocusCapture={(e) => { + // Only *keyboard* focus (focus-visible) peeks the rail open. A mouse + // click on a nav link also focuses it, but must NOT peek — that + // click-focus lingers and never blurs when the pointer moves to the + // content, so the rail would stay stuck open after navigating. + if ((e.target as HTMLElement).matches?.(':focus-visible')) setFocused(true); + }} + onBlur={(e) => { + if (!e.currentTarget.contains(e.relatedTarget as Node)) setFocused(false); + }} + className="relative h-full shrink-0 overflow-hidden" > - + )} @@ -87,17 +96,23 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) { )} - {/* Main column */} -
+ {/* Main column — a content "canvas" nested into the chrome with a rounded + top-left corner at the sidebar/topbar junction. It's a flex sibling of + the rail, so as the rail expands/collapses the whole canvas (and its + rounded corner) is pushed along with it. Depth comes from a soft shadow + + the canvas tone sitting on the (sidebar-toned) chrome, not a border. */} +
{!kiosk && ( setCollapsed((v) => !v)} onOpenMobile={() => setMobileOpen(true)} onLogout={onLogout} isMobile={isMobile} - editing={editing} /> )} diff --git a/packages/webui/src/components/layout/sidebar.tsx b/packages/webui/src/components/layout/sidebar.tsx index 1feb4258..7deec9fd 100644 --- a/packages/webui/src/components/layout/sidebar.tsx +++ b/packages/webui/src/components/layout/sidebar.tsx @@ -2,7 +2,6 @@ import { Bug, Check, Eye, EyeOff, GripVertical, LayoutDashboard, Lock, PlugZap, import { motion, Reorder } from 'motion/react'; import { Link, useRouterState } from '@tanstack/react-router'; import { ScrollArea } from '@/components/ui/scroll-area'; -import { Separator } from '@/components/ui/separator'; import { cn } from '@/lib/utils'; import { APP_NAME, APP_VERSION } from '@/types'; import { useAppState } from '@/contexts/AppStateContext'; @@ -59,7 +58,7 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) { return (
{/* Brand */} -
+
SnowLuma
@@ -83,7 +82,7 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) { @@ -99,7 +98,7 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) { key={item.id} value={item.id} className={cn( - 'flex select-none items-center gap-2 rounded-lg border bg-sidebar-accent/30 px-2 py-2 cursor-grab active:cursor-grabbing', + 'flex select-none items-center gap-2 rounded-lg bg-sidebar-accent/40 px-2 py-2 cursor-grab active:cursor-grabbing', !item.visible && 'opacity-50', )} > @@ -146,11 +145,18 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) { )} > {isActive && ( - + <> + + + )} {!collapsed && ( @@ -166,7 +172,6 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) { )} - {updateInfo?.hasUpdate && (
diff --git a/packages/webui/src/components/layout/top-bar.tsx b/packages/webui/src/components/layout/top-bar.tsx index e5268484..500e6f8d 100644 --- a/packages/webui/src/components/layout/top-bar.tsx +++ b/packages/webui/src/components/layout/top-bar.tsx @@ -1,5 +1,5 @@ import { useState } from 'react'; -import { LogOut, Menu, Monitor, PanelLeftClose, PanelLeftOpen } from 'lucide-react'; +import { LogOut, Menu, Monitor } from 'lucide-react'; import { motion, AnimatePresence } from 'motion/react'; import { useRouterState } from '@tanstack/react-router'; import { Button } from '@/components/ui/button'; @@ -20,23 +20,16 @@ export const TOPBAR_CATALOGUE: { id: string; label: string }[] = [ interface TopBarProps { status: string; - collapsed: boolean; - onToggleCollapse: () => void; onOpenMobile: () => void; onLogout: () => void; isMobile: boolean; - /** Layout edit mode force-expands the sidebar, so collapsing is disabled. */ - editing?: boolean; } export function TopBar({ status, - collapsed, - onToggleCollapse, onOpenMobile, onLogout, isMobile, - editing = false, }: TopBarProps) { const [confirmLogout, setConfirmLogout] = useState(false); const pathname = useRouterState({ select: (s) => s.location.pathname }); @@ -55,27 +48,16 @@ export function TopBar({ ); return ( -
- {/* Collapse toggle (desktop) / menu (mobile) */} - {isMobile ? ( +
+ {/* Mobile-only menu trigger. On desktop there's no collapse button — the + sidebar auto-expands on hover/focus, and its boundary with the content + is a soft surface-tone shift, not a hard border. */} + {isMobile && ( - ) : ( - )} -
- {/* Page title */}