fix(webui): align settings sidebar footer rows

This commit is contained in:
chengyongru authored and chengyongru committed 2026-11-20 23:35:48 +08:00
1 parent 6057ce59e5
commit bc690f0394
3 files changed
+15 -12

No files matched your search

+3 -3
View File
@@ -1,4 +1,4 @@
import { useContext, useEffect, useState } from "react"; import { useContext, useEffect, useState, type ComponentProps } from "react";
import { useClient } from "@/providers/ClientProvider"; import { useClient } from "@/providers/ClientProvider";
import type { ConnectionStatus } from "@/lib/types"; import type { ConnectionStatus } from "@/lib/types";
@@ -8,10 +8,10 @@ import { HostSwitcherView } from "./HostSwitcherView";
export { HostNavigationContext, type HostPicker } from "./host-navigation"; export { HostNavigationContext, type HostPicker } from "./host-navigation";
export { RemoteHostMenu } from "./HostSwitcherView"; export { RemoteHostMenu } from "./HostSwitcherView";
export function HostSwitcher({ collapsed = false, portalContainer }: { collapsed?: boolean; portalContainer?: HTMLElement | null }) { export function HostSwitcher(props: Omit<ComponentProps<typeof HostSwitcherView>, "picker" | "status">) {
const picker = useContext(HostNavigationContext); const picker = useContext(HostNavigationContext);
const { client } = useClient(); const { client } = useClient();
const [status, setStatus] = useState<ConnectionStatus>(client.status); const [status, setStatus] = useState<ConnectionStatus>(client.status);
useEffect(() => client.onStatus(setStatus), [client]); useEffect(() => client.onStatus(setStatus), [client]);
return <HostSwitcherView picker={picker} status={status} collapsed={collapsed} portalContainer={portalContainer} />; return <HostSwitcherView {...props} picker={picker} status={status} />;
} }
@@ -101,11 +101,12 @@ function HostMenuItems({ picker }: { picker: HostPicker }) {
} }
/** Shared sidebar control. Remote frames can only open the trusted shell's menu. */ /** Shared sidebar control. Remote frames can only open the trusted shell's menu. */
export function HostSwitcherView({ picker, status, collapsed = false, portalContainer }: { export function HostSwitcherView({ picker, status, collapsed = false, portalContainer, className }: {
picker: HostPicker | EmbeddedPicker | null; picker: HostPicker | EmbeddedPicker | null;
status: ConnectionStatus; status: ConnectionStatus;
collapsed?: boolean; collapsed?: boolean;
portalContainer?: HTMLElement | null; portalContainer?: HTMLElement | null;
className?: string;
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const buttonRef = useRef<HTMLButtonElement>(null); const buttonRef = useRef<HTMLButtonElement>(null);
@@ -128,7 +129,7 @@ export function HostSwitcherView({ picker, status, collapsed = false, portalCont
const detail = pendingName ? `${current}. ${t("remote.preparing", { name: pendingName })}` : current; const detail = pendingName ? `${current}. ${t("remote.preparing", { name: pendingName })}` : current;
const button = <Button ref={buttonRef} variant="ghost" size="sm" aria-label={t("remote.switchHost")} const button = <Button ref={buttonRef} variant="ghost" size="sm" aria-label={t("remote.switchHost")}
data-host-switcher data-theme-surface data-theme-ink className={cn("host-no-drag touch-target h-8 min-w-0 gap-2 rounded-xl px-2 text-xs font-normal text-sidebar-content/75 hover:text-sidebar-content", data-host-switcher data-theme-surface data-theme-ink className={cn("host-no-drag touch-target h-8 min-w-0 gap-2 rounded-xl px-2 text-xs font-normal text-sidebar-content/75 hover:text-sidebar-content",
collapsed ? "w-8 justify-center px-0" : "max-w-full flex-1 justify-start")} collapsed ? "w-8 justify-center px-0" : "max-w-full flex-1 justify-start", className)}
onClick={picker.kind === "embedded" ? () => { onClick={picker.kind === "embedded" ? () => {
const rect = buttonRef.current?.getBoundingClientRect(); const rect = buttonRef.current?.getBoundingClientRect();
if (rect) picker.open({ left: rect.left, top: rect.top, width: rect.width, height: rect.height }); if (rect) picker.open({ left: rect.left, top: rect.top, width: rect.width, height: rect.height });
@@ -29,6 +29,8 @@ import {
import { useMediaQuery } from "@/hooks/useMediaQuery"; import { useMediaQuery } from "@/hooks/useMediaQuery";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
const SIDEBAR_ROW = "touch-target flex h-9 w-full items-center justify-start gap-2 rounded-xl px-2.5 text-left text-ui font-normal";
const SETTINGS_NAV_ITEMS: Array<{ key: SettingsSectionKey; icon: LucideIcon; fallback: string }> = [ const SETTINGS_NAV_ITEMS: Array<{ key: SettingsSectionKey; icon: LucideIcon; fallback: string }> = [
{ key: "overview", icon: OverviewIcon, fallback: "Overview" }, { key: "overview", icon: OverviewIcon, fallback: "Overview" },
{ key: "appearance", icon: AppearanceIcon, fallback: "Appearance" }, { key: "appearance", icon: AppearanceIcon, fallback: "Appearance" },
@@ -130,7 +132,7 @@ export function SettingsSidebar(props: SettingsSidebarProps) {
aria-current={active ? "page" : undefined} aria-current={active ? "page" : undefined}
onClick={() => onSelectSection(key)} onClick={() => onSelectSection(key)}
className={cn( className={cn(
"touch-target flex h-9 w-full items-center gap-2 rounded-xl px-2.5 text-left text-ui", SIDEBAR_ROW,
SIDEBAR_SELECTION_ITEM_CLASS, SIDEBAR_SELECTION_ITEM_CLASS,
active active
? "text-sidebar-accent-foreground" ? "text-sidebar-accent-foreground"
@@ -147,9 +149,9 @@ export function SettingsSidebar(props: SettingsSidebarProps) {
</SidebarSelectionHighlight> </SidebarSelectionHighlight>
</nav> </nav>
<div className="pt-2 lg:mt-auto lg:pt-4"> <div className="mt-auto grid gap-1 pt-4">
{onRestart ? ( {onRestart ? (
<div> <>
{restartPending ? ( {restartPending ? (
<p id="settings-restart-status" role="status" className="sr-only"> <p id="settings-restart-status" role="status" className="sr-only">
{t("settings.status.savedRestartApply")} {t("settings.status.savedRestartApply")}
@@ -161,7 +163,7 @@ export function SettingsSidebar(props: SettingsSidebarProps) {
onClick={onRestart} onClick={onRestart}
disabled={isRestarting} disabled={isRestarting}
aria-describedby={restartPending ? "settings-restart-status" : undefined} aria-describedby={restartPending ? "settings-restart-status" : undefined}
className={cn("h-9 w-full justify-start gap-2 rounded-control px-2.5 text-ui settings-hover", className={cn(SIDEBAR_ROW, "settings-hover",
restartPending && !isRestarting restartPending && !isRestarting
? "settings-restart-pending text-orange-600 hover:text-orange-700 dark:text-orange-400 dark:hover:text-orange-300" ? "settings-restart-pending text-orange-600 hover:text-orange-700 dark:text-orange-400 dark:hover:text-orange-300"
: "text-sidebar-content hover:text-foreground")} : "text-sidebar-content hover:text-foreground")}
@@ -170,20 +172,20 @@ export function SettingsSidebar(props: SettingsSidebarProps) {
: <RestartIcon className="h-4 w-4" aria-hidden />} : <RestartIcon className="h-4 w-4" aria-hidden />}
<span>{restartLabel}</span> <span>{restartLabel}</span>
</Button> </Button>
</div> </>
) : null} ) : null}
{onLogout && !hostChromeInset ? ( {onLogout && !hostChromeInset ? (
<Button <Button
type="button" type="button"
variant="ghost" variant="ghost"
onClick={onLogout} onClick={onLogout}
className="hidden h-9 w-full justify-start gap-2 rounded-control px-2.5 text-ui text-sidebar-content hover:bg-destructive/8 hover:text-destructive lg:flex" className={cn(SIDEBAR_ROW, "text-sidebar-content hover:bg-destructive/8 hover:text-destructive")}
> >
<LogOut className="h-4 w-4" aria-hidden /> <LogOut className="h-4 w-4" aria-hidden />
<span>{t("app.account.logout")}</span> <span>{t("app.account.logout")}</span>
</Button> </Button>
) : null} ) : null}
{hostNavigation && <div className="mt-2 flex min-w-0"><HostSwitcher /></div>} {hostNavigation && <HostSwitcher className={SIDEBAR_ROW} />}
</div> </div>
</aside> </aside>
); );