feat(webui): hover-expand sidebar rail + borderless nested-canvas chrome

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.
This commit is contained in:
DrSmoothl committed 2026-06-20 23:30:08 +08:00
1 parent 9d1e39f25f
commit bba9b82ce9
3 files changed
+63 -61

No files matched your search

@@ -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 (
<div className={cn('flex h-screen w-screen overflow-hidden text-foreground', customBg ? 'bg-transparent' : 'bg-background')}>
<div className={cn('flex h-screen w-screen overflow-hidden text-foreground', customBg ? 'bg-transparent' : 'bg-sidebar')}>
{/* Desktop sidebar (hidden in kiosk) */}
{!isMobile && !kiosk && (
<motion.aside
initial={false}
animate={{ width: effectiveCollapsed ? 64 : 248 }}
transition={reduce ? { duration: 0 } : { type: 'spring', stiffness: 280, damping: 32 }}
className="relative h-full shrink-0 border-r overflow-hidden"
animate={{ width: showCollapsed ? 64 : 248 }}
transition={reduce ? { duration: 0 } : { duration: 0.26, ease: [0.4, 0, 0.1, 1] }}
onMouseEnter={() => 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"
>
<Sidebar collapsed={effectiveCollapsed} />
<Sidebar collapsed={showCollapsed} />
</motion.aside>
)}
@@ -87,17 +96,23 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
</button>
)}
{/* Main column */}
<div className="flex min-w-0 flex-1 flex-col">
{/* 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. */}
<div
className={cn(
'flex min-w-0 flex-1 flex-col overflow-hidden rounded-tl-2xl',
!customBg && 'bg-background shadow-[0_0_18px_-6px_rgb(0_0_0/0.14)]',
)}
>
{!kiosk && (
<TopBar
status={status}
collapsed={effectiveCollapsed}
onToggleCollapse={() => setCollapsed((v) => !v)}
onOpenMobile={() => setMobileOpen(true)}
onLogout={onLogout}
isMobile={isMobile}
editing={editing}
/>
)}