feat(webui): top-bar element show/hide (B2)
The top-bar's optional right-side elements (connection-status badge, theme toggle) are now toggleable via `topbarItems`. Essential controls — the menu/collapse button, page title, and logout — always render and aren't listed. - A TOPBAR_CATALOGUE (id+label) drives both the render gating and the settings toggles; TopBar reconciles `topbarItems` against it so a new element defaults to shown. - A 顶栏 group in settings → 外观 exposes one switch per catalogue element.
This commit is contained in:
2 files changed
+53
-12
No files matched your search
@@ -7,6 +7,14 @@ import { Badge } from '@/components/ui/badge';
|
||||
import { ThemeToggle } from '@/components/theme-toggle';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { NAV_ITEMS } from '@/components/layout/sidebar';
|
||||
import { reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext';
|
||||
|
||||
// Toggleable top-bar elements (the menu/title/logout are essential and always
|
||||
// render). Labels drive the settings toggles; ids match `topbarItems`.
|
||||
export const TOPBAR_CATALOGUE: { id: string; label: string }[] = [
|
||||
{ id: 'status', label: '连接状态徽章' },
|
||||
{ id: 'theme', label: '主题切换按钮' },
|
||||
];
|
||||
|
||||
interface TopBarProps {
|
||||
status: string;
|
||||
@@ -34,6 +42,15 @@ export function TopBar({
|
||||
const PageIcon = meta?.icon;
|
||||
const online = status === '已连接';
|
||||
|
||||
// Which optional top-bar elements the operator has kept (reconciled against
|
||||
// the live catalogue, so a new element defaults to shown).
|
||||
const { topbarItems } = useLayout();
|
||||
const shown = new Set(
|
||||
reconcileLayoutItems(topbarItems, TOPBAR_CATALOGUE.map((t) => t.id))
|
||||
.filter((i) => i.visible)
|
||||
.map((i) => i.id),
|
||||
);
|
||||
|
||||
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">
|
||||
{/* Collapse toggle (desktop) / menu (mobile) */}
|
||||
@@ -73,17 +90,19 @@ export function TopBar({
|
||||
</AnimatePresence>
|
||||
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
<Badge
|
||||
variant={online ? 'success' : 'destructive'}
|
||||
className="hidden sm:inline-flex gap-1.5"
|
||||
>
|
||||
<span
|
||||
className={`size-1.5 rounded-full ${online ? 'bg-success' : 'bg-destructive'} ${online ? 'animate-pulse' : ''}`}
|
||||
/>
|
||||
{status}
|
||||
</Badge>
|
||||
{shown.has('status') && (
|
||||
<Badge
|
||||
variant={online ? 'success' : 'destructive'}
|
||||
className="hidden sm:inline-flex gap-1.5"
|
||||
>
|
||||
<span
|
||||
className={`size-1.5 rounded-full ${online ? 'bg-success' : 'bg-destructive'} ${online ? 'animate-pulse' : ''}`}
|
||||
/>
|
||||
{status}
|
||||
</Badge>
|
||||
)}
|
||||
|
||||
<ThemeToggle />
|
||||
{shown.has('theme') && <ThemeToggle />}
|
||||
|
||||
<Button
|
||||
variant="ghost"
|
||||
|
||||
@@ -2,7 +2,7 @@ import { createContext, useContext, useId, useRef, useState, type ReactNode } fr
|
||||
import { motion } from 'motion/react';
|
||||
import {
|
||||
Accessibility, AlertTriangle, Bug, Check, Clock, Code2, Download, ExternalLink, Github, Image as ImageIcon,
|
||||
Info, KeyRound, Loader2, Monitor, Moon, Palette, Plus, RefreshCw, RotateCcw, ShieldCheck,
|
||||
Info, KeyRound, Loader2, Monitor, Moon, Palette, PanelTop, Plus, RefreshCw, RotateCcw, ShieldCheck,
|
||||
Sparkles, Star, Sun, Tag, Upload, Trash2,
|
||||
} from 'lucide-react';
|
||||
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card';
|
||||
@@ -31,8 +31,9 @@ import {
|
||||
type ThemeMode,
|
||||
type TimeFormat,
|
||||
} from '@/contexts/ThemeContext';
|
||||
import { DEFAULT_LAYOUT, DEFAULT_PAGES, useLayout } from '@/contexts/LayoutContext';
|
||||
import { DEFAULT_LAYOUT, DEFAULT_PAGES, reconcileLayoutItems, useLayout } from '@/contexts/LayoutContext';
|
||||
import { NAV_ITEMS } from '@/components/layout/sidebar';
|
||||
import { TOPBAR_CATALOGUE } from '@/components/layout/top-bar';
|
||||
import { ChangePasswordDialog } from '@/components/change-password-dialog';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import { useApi } from '@/lib/api';
|
||||
@@ -280,6 +281,25 @@ function contrastRatio(a: string, b: string): number | null {
|
||||
return (hi + 0.05) / (lo + 0.05);
|
||||
}
|
||||
|
||||
// Top-bar element show/hide. Essential controls (menu, page title, logout) are
|
||||
// not listed — they always render.
|
||||
function TopbarPanel() {
|
||||
const { topbarItems, setTopbarItems } = useLayout();
|
||||
const reconciled = reconcileLayoutItems(topbarItems, TOPBAR_CATALOGUE.map((t) => t.id));
|
||||
const shown = new Map(reconciled.map((i) => [i.id, i.visible]));
|
||||
const toggle = (id: string) =>
|
||||
setTopbarItems(reconciled.map((i) => (i.id === id ? { ...i, visible: !i.visible } : i)));
|
||||
return (
|
||||
<Group title="顶栏" icon={PanelTop} description="控制顶栏右侧元素的显示;菜单、页面标题与登出始终保留。">
|
||||
{TOPBAR_CATALOGUE.map((t) => (
|
||||
<SettingRow key={t.id} label={t.label} layout="inline">
|
||||
<ToggleSwitch value={shown.get(t.id) ?? true} onChange={() => toggle(t.id)} ariaLabel={t.label} />
|
||||
</SettingRow>
|
||||
))}
|
||||
</Group>
|
||||
);
|
||||
}
|
||||
|
||||
function AppearancePanel() {
|
||||
const { appearance, setAppearance, uploadBackground, removeBackground, resolved } = useTheme();
|
||||
const a = appearance;
|
||||
@@ -447,6 +467,8 @@ function AppearancePanel() {
|
||||
|
||||
<ThemeVarsPanel cssVars={a.cssVars} onChange={(cssVars) => setAppearance({ cssVars })} />
|
||||
|
||||
<TopbarPanel />
|
||||
|
||||
<Group title="无障碍与侧栏" icon={Accessibility} description="动效、对比度与侧栏默认状态。">
|
||||
<SettingRow label="减弱动效" hint="弱化页面切换、弹簧等装饰性动画(保留轻微淡入),对低端设备与晕动敏感者更友好。" layout="inline">
|
||||
<ToggleSwitch value={a.reduceMotion} onChange={(reduceMotion) => setAppearance({ reduceMotion })} ariaLabel="减弱动效" />
|
||||
|
||||
Reference in new issue
Block a user