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:
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 { motion, AnimatePresence } from 'motion/react';
|
||||||
import { useRouterState } from '@tanstack/react-router';
|
import { useRouterState } from '@tanstack/react-router';
|
||||||
import { Minimize2 } from 'lucide-react';
|
import { Minimize2 } from 'lucide-react';
|
||||||
@@ -21,14 +21,6 @@ interface MainLayoutProps {
|
|||||||
export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
||||||
const isMobile = !useMediaQuery('(min-width: 768px)');
|
const isMobile = !useMediaQuery('(min-width: 768px)');
|
||||||
const { appearance } = useTheme();
|
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';
|
const customBg = appearance.background.type !== 'none';
|
||||||
// Framer's reducedMotion only suppresses transforms, so the always-present
|
// Framer's reducedMotion only suppresses transforms, so the always-present
|
||||||
// width + page-transition animations need an explicit opt-out to make the
|
// 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 reduce = appearance.reduceMotion || appearance.disableMotion;
|
||||||
const { editing } = useLayout();
|
const { editing } = useLayout();
|
||||||
const { kiosk, exit: exitKiosk } = useKiosk();
|
const { kiosk, exit: exitKiosk } = useKiosk();
|
||||||
// Force the sidebar open while editing layout so its drag-to-reorder list
|
// The sidebar rests as a slim icon rail and auto-expands on hover/focus (the
|
||||||
// has room (it returns to the user's collapsed pref on 完成).
|
// peek logic below) — there's no collapse button. Layout-edit mode force-
|
||||||
const effectiveCollapsed = collapsed && !editing;
|
// 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 [mobileOpen, setMobileOpen] = useState(false);
|
||||||
const pathname = useRouterState({ select: (s) => s.location.pathname });
|
const pathname = useRouterState({ select: (s) => s.location.pathname });
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
localStorage.setItem('snowluma_sidebar_collapsed', collapsed ? '1' : '0');
|
|
||||||
}, [collapsed]);
|
|
||||||
|
|
||||||
return (
|
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) */}
|
{/* Desktop sidebar (hidden in kiosk) */}
|
||||||
{!isMobile && !kiosk && (
|
{!isMobile && !kiosk && (
|
||||||
<motion.aside
|
<motion.aside
|
||||||
initial={false}
|
initial={false}
|
||||||
animate={{ width: effectiveCollapsed ? 64 : 248 }}
|
animate={{ width: showCollapsed ? 64 : 248 }}
|
||||||
transition={reduce ? { duration: 0 } : { type: 'spring', stiffness: 280, damping: 32 }}
|
transition={reduce ? { duration: 0 } : { duration: 0.26, ease: [0.4, 0, 0.1, 1] }}
|
||||||
className="relative h-full shrink-0 border-r overflow-hidden"
|
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>
|
</motion.aside>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -87,17 +96,23 @@ export function MainLayout({ status, onLogout, children }: MainLayoutProps) {
|
|||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Main column */}
|
{/* Main column — a content "canvas" nested into the chrome with a rounded
|
||||||
<div className="flex min-w-0 flex-1 flex-col">
|
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 && (
|
{!kiosk && (
|
||||||
<TopBar
|
<TopBar
|
||||||
status={status}
|
status={status}
|
||||||
collapsed={effectiveCollapsed}
|
|
||||||
onToggleCollapse={() => setCollapsed((v) => !v)}
|
|
||||||
onOpenMobile={() => setMobileOpen(true)}
|
onOpenMobile={() => setMobileOpen(true)}
|
||||||
onLogout={onLogout}
|
onLogout={onLogout}
|
||||||
isMobile={isMobile}
|
isMobile={isMobile}
|
||||||
editing={editing}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Bug, Check, Eye, EyeOff, GripVertical, LayoutDashboard, Lock, PlugZap,
|
|||||||
import { motion, Reorder } from 'motion/react';
|
import { motion, Reorder } from 'motion/react';
|
||||||
import { Link, useRouterState } from '@tanstack/react-router';
|
import { Link, useRouterState } from '@tanstack/react-router';
|
||||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
import { Separator } from '@/components/ui/separator';
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { APP_NAME, APP_VERSION } from '@/types';
|
import { APP_NAME, APP_VERSION } from '@/types';
|
||||||
import { useAppState } from '@/contexts/AppStateContext';
|
import { useAppState } from '@/contexts/AppStateContext';
|
||||||
@@ -59,7 +58,7 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
|
|||||||
return (
|
return (
|
||||||
<div className="flex h-full w-full flex-col bg-sidebar text-sidebar-foreground">
|
<div className="flex h-full w-full flex-col bg-sidebar text-sidebar-foreground">
|
||||||
{/* Brand */}
|
{/* Brand */}
|
||||||
<div className={cn('flex h-16 items-center gap-3 border-b px-4', collapsed && 'justify-center px-2')}>
|
<div className={cn('flex h-16 items-center gap-3 px-4', collapsed && 'justify-center px-2')}>
|
||||||
<div className="relative flex size-9 shrink-0 items-center justify-center overflow-hidden rounded-xl bg-primary/10 ring-1 ring-primary/20">
|
<div className="relative flex size-9 shrink-0 items-center justify-center overflow-hidden rounded-xl bg-primary/10 ring-1 ring-primary/20">
|
||||||
<img src="/logo.png" alt="SnowLuma" className="size-7 object-contain" />
|
<img src="/logo.png" alt="SnowLuma" className="size-7 object-contain" />
|
||||||
</div>
|
</div>
|
||||||
@@ -83,7 +82,7 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onClick={() => setEditing(false)}
|
onClick={() => setEditing(false)}
|
||||||
className="inline-flex items-center gap-1 rounded-md border border-primary/40 bg-primary/10 px-2 py-0.5 text-[11px] text-primary transition-colors hover:bg-primary/15 cursor-pointer"
|
className="inline-flex items-center gap-1 rounded-md bg-primary/15 px-2 py-0.5 text-[11px] text-primary transition-colors hover:bg-primary/20 cursor-pointer"
|
||||||
>
|
>
|
||||||
<Check className="size-3" /> 完成
|
<Check className="size-3" /> 完成
|
||||||
</button>
|
</button>
|
||||||
@@ -99,7 +98,7 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
|
|||||||
key={item.id}
|
key={item.id}
|
||||||
value={item.id}
|
value={item.id}
|
||||||
className={cn(
|
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',
|
!item.visible && 'opacity-50',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -146,11 +145,18 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{isActive && (
|
{isActive && (
|
||||||
<motion.span
|
<>
|
||||||
layoutId="sidebar-active-pill"
|
<motion.span
|
||||||
className="absolute inset-0 rounded-lg bg-sidebar-accent ring-1 ring-primary/20"
|
layoutId="sidebar-active-pill"
|
||||||
transition={{ type: 'spring', stiffness: 380, damping: 32 }}
|
className="absolute inset-0 rounded-lg bg-sidebar-accent"
|
||||||
/>
|
transition={{ type: 'spring', stiffness: 380, damping: 32 }}
|
||||||
|
/>
|
||||||
|
<motion.span
|
||||||
|
layoutId="sidebar-active-bar"
|
||||||
|
className="absolute left-0 top-1/2 h-5 w-0.5 -translate-y-1/2 rounded-full bg-primary"
|
||||||
|
transition={{ type: 'spring', stiffness: 380, damping: 32 }}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
<Icon className={cn('relative z-10 size-4 shrink-0', isActive && 'text-primary')} />
|
<Icon className={cn('relative z-10 size-4 shrink-0', isActive && 'text-primary')} />
|
||||||
{!collapsed && (
|
{!collapsed && (
|
||||||
@@ -166,7 +172,6 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
|
|||||||
)}
|
)}
|
||||||
</ScrollArea>
|
</ScrollArea>
|
||||||
|
|
||||||
<Separator />
|
|
||||||
{updateInfo?.hasUpdate && (
|
{updateInfo?.hasUpdate && (
|
||||||
<div className={cn('px-2 pt-2', collapsed && 'px-0')}>
|
<div className={cn('px-2 pt-2', collapsed && 'px-0')}>
|
||||||
<Link
|
<Link
|
||||||
@@ -176,7 +181,7 @@ export function Sidebar({ collapsed = false, onItemClick }: SidebarProps) {
|
|||||||
title={updateInfo.latest ? `有新版本 v${updateInfo.latest} · 点击查看` : '有可用更新'}
|
title={updateInfo.latest ? `有新版本 v${updateInfo.latest} · 点击查看` : '有可用更新'}
|
||||||
aria-label="有可用更新"
|
aria-label="有可用更新"
|
||||||
className={cn(
|
className={cn(
|
||||||
'group relative flex items-center gap-2.5 rounded-lg border border-primary/30 bg-primary/[0.07] px-3 py-2 text-left transition-colors hover:bg-primary/10',
|
'group relative flex items-center gap-2.5 rounded-lg bg-primary/[0.1] px-3 py-2 text-left transition-colors hover:bg-primary/15',
|
||||||
collapsed && 'mx-auto w-10 justify-center px-0',
|
collapsed && 'mx-auto w-10 justify-center px-0',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useState } from 'react';
|
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 { motion, AnimatePresence } from 'motion/react';
|
||||||
import { useRouterState } from '@tanstack/react-router';
|
import { useRouterState } from '@tanstack/react-router';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
@@ -20,23 +20,16 @@ export const TOPBAR_CATALOGUE: { id: string; label: string }[] = [
|
|||||||
|
|
||||||
interface TopBarProps {
|
interface TopBarProps {
|
||||||
status: string;
|
status: string;
|
||||||
collapsed: boolean;
|
|
||||||
onToggleCollapse: () => void;
|
|
||||||
onOpenMobile: () => void;
|
onOpenMobile: () => void;
|
||||||
onLogout: () => void;
|
onLogout: () => void;
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
/** Layout edit mode force-expands the sidebar, so collapsing is disabled. */
|
|
||||||
editing?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TopBar({
|
export function TopBar({
|
||||||
status,
|
status,
|
||||||
collapsed,
|
|
||||||
onToggleCollapse,
|
|
||||||
onOpenMobile,
|
onOpenMobile,
|
||||||
onLogout,
|
onLogout,
|
||||||
isMobile,
|
isMobile,
|
||||||
editing = false,
|
|
||||||
}: TopBarProps) {
|
}: TopBarProps) {
|
||||||
const [confirmLogout, setConfirmLogout] = useState(false);
|
const [confirmLogout, setConfirmLogout] = useState(false);
|
||||||
const pathname = useRouterState({ select: (s) => s.location.pathname });
|
const pathname = useRouterState({ select: (s) => s.location.pathname });
|
||||||
@@ -55,27 +48,16 @@ export function TopBar({
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<header className="sticky top-0 z-30 flex h-16 shrink-0 items-center gap-2 border-b bg-background/55 px-3 backdrop-blur-xl backdrop-saturate-150 supports-[backdrop-filter]:bg-background/45 sm:px-4">
|
<header className="sticky top-0 z-30 flex h-16 shrink-0 items-center gap-2 bg-background/55 px-3 backdrop-blur-xl backdrop-saturate-150 supports-[backdrop-filter]:bg-background/45 sm:px-4">
|
||||||
{/* Collapse toggle (desktop) / menu (mobile) */}
|
{/* Mobile-only menu trigger. On desktop there's no collapse button — the
|
||||||
{isMobile ? (
|
sidebar auto-expands on hover/focus, and its boundary with the content
|
||||||
|
is a soft surface-tone shift, not a hard border. */}
|
||||||
|
{isMobile && (
|
||||||
<Button variant="ghost" size="icon-sm" onClick={onOpenMobile} aria-label="打开菜单">
|
<Button variant="ghost" size="icon-sm" onClick={onOpenMobile} aria-label="打开菜单">
|
||||||
<Menu className="size-4" />
|
<Menu className="size-4" />
|
||||||
</Button>
|
</Button>
|
||||||
) : (
|
|
||||||
<Button
|
|
||||||
variant="ghost"
|
|
||||||
size="icon-sm"
|
|
||||||
onClick={onToggleCollapse}
|
|
||||||
disabled={editing}
|
|
||||||
aria-label={collapsed ? '展开侧边栏' : '收起侧边栏'}
|
|
||||||
title={editing ? '编辑布局时侧栏保持展开' : collapsed ? '展开侧边栏' : '收起侧边栏'}
|
|
||||||
>
|
|
||||||
{collapsed ? <PanelLeftOpen className="size-4" /> : <PanelLeftClose className="size-4" />}
|
|
||||||
</Button>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="mx-1 h-6 w-px bg-border" />
|
|
||||||
|
|
||||||
{/* Page title */}
|
{/* Page title */}
|
||||||
<AnimatePresence mode="wait">
|
<AnimatePresence mode="wait">
|
||||||
<motion.div
|
<motion.div
|
||||||
|
|||||||
Reference in new issue
Block a user