fix: align Code return and sidebar collapse in the top row
This commit is contained in:
@@ -3,7 +3,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { AI_MODULE_SELECTION_PATH, aiModules, getAiModuleForPath } from '@/lib/ai-modules';
|
||||
|
||||
export function ModuleSwitcher({ sidebarCollapsed, compact = false }: { sidebarCollapsed: boolean; compact?: boolean }) {
|
||||
export function ModuleSwitcher({ sidebarCollapsed, compact = false, toolbar = false }: { sidebarCollapsed: boolean; compact?: boolean; toolbar?: boolean }) {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const activeModuleId = getAiModuleForPath(location.pathname);
|
||||
@@ -14,7 +14,7 @@ export function ModuleSwitcher({ sidebarCollapsed, compact = false }: { sidebarC
|
||||
const compactTrigger = compact && !sidebarCollapsed;
|
||||
|
||||
return (
|
||||
<div data-testid="sidebar-module-switcher" className="relative">
|
||||
<div data-testid="sidebar-module-switcher" className={cn('relative', toolbar && 'min-w-0 flex-1')}>
|
||||
<button
|
||||
type="button"
|
||||
data-testid="sidebar-module-switcher-trigger"
|
||||
@@ -23,7 +23,9 @@ export function ModuleSwitcher({ sidebarCollapsed, compact = false }: { sidebarC
|
||||
onClick={() => navigate(AI_MODULE_SELECTION_PATH)}
|
||||
className={cn(
|
||||
'motion-press group items-center bg-transparent text-left font-semibold text-foreground transition-colors duration-100 hover:bg-surface-subtle',
|
||||
compactTrigger
|
||||
toolbar
|
||||
? 'no-drag flex h-8 min-w-0 w-full justify-start gap-1 rounded-md px-1 text-xs'
|
||||
: compactTrigger
|
||||
? 'inline-flex min-h-9 w-fit translate-y-2 justify-start gap-1.5 rounded-xl p-2 text-xs'
|
||||
: 'flex min-h-11 w-full justify-between gap-2 rounded-2xl p-3 text-sm',
|
||||
sidebarCollapsed ? 'justify-center px-0' : '',
|
||||
@@ -34,7 +36,7 @@ export function ModuleSwitcher({ sidebarCollapsed, compact = false }: { sidebarC
|
||||
aria-hidden="true"
|
||||
className="h-4 w-4 shrink-0 -translate-y-px text-muted-foreground transition-[color,transform] duration-150 group-hover:-translate-x-0.5 group-hover:text-brand"
|
||||
/>
|
||||
{!sidebarCollapsed ? <span className="min-w-0 whitespace-nowrap leading-4">{activeModuleLabel}</span> : null}
|
||||
{!sidebarCollapsed ? <span className={cn('min-w-0 whitespace-nowrap leading-4', toolbar && 'truncate')}>{activeModuleLabel}</span> : null}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
FolderKanban,
|
||||
Gamepad2,
|
||||
LogOut,
|
||||
PanelLeftClose,
|
||||
Plus,
|
||||
RadioTower,
|
||||
Settings as SettingsIcon,
|
||||
@@ -90,6 +91,7 @@ export function Sidebar({
|
||||
}: SidebarProps = {}) {
|
||||
const { t } = useTranslation('common');
|
||||
const storedSidebarCollapsed = useSettingsStore((state) => state.sidebarCollapsed);
|
||||
const setSidebarCollapsed = useSettingsStore((state) => state.setSidebarCollapsed);
|
||||
const sidebarWidth = useSettingsStore((state) => normalizeClassroomSidebarWidth(state.classroomSidebarWidth));
|
||||
const sidebarPinnedCollapsed = !forceExpanded && storedSidebarCollapsed;
|
||||
const sidebarCollapsed = sidebarPinnedCollapsed && !sidebarPeekOpen;
|
||||
@@ -412,11 +414,23 @@ export function Sidebar({
|
||||
)}
|
||||
>
|
||||
<div className="min-w-0 w-full">
|
||||
{workspaceLayout && <div className="no-drag flex h-10 min-w-0 items-center gap-1" data-testid="classroom-sidebar-navigation">
|
||||
<ModuleSwitcher sidebarCollapsed={sidebarCollapsed} toolbar />
|
||||
{!sidebarPinnedCollapsed && ['darwin', 'win32'].includes(window.electron?.platform ?? '') && <button
|
||||
type="button"
|
||||
data-testid="titlebar-sidebar-toggle"
|
||||
aria-label="折叠侧栏"
|
||||
title="折叠侧栏"
|
||||
aria-expanded="true"
|
||||
onClick={() => setSidebarCollapsed(true)}
|
||||
className="no-drag motion-press flex h-8 w-8 shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-surface-subtle hover:text-foreground"
|
||||
><PanelLeftClose className="h-4 w-4" /></button>}
|
||||
</div>}
|
||||
{workspaceLayout && <button type="button" aria-label="返回首页" title="返回首页" onClick={() => navigate('/module-select')} className="classroom-brand flex w-full items-center gap-2 rounded-lg text-left">
|
||||
<span className="classroom-brand-mark"><img src={classroomMark} alt="" className="h-7 w-7" /></span>
|
||||
<span className="min-w-0"><span className="block text-base font-semibold tracking-tight">麦洛</span><span className="classroom-brand-caption">把脑洞变成作品</span></span>
|
||||
</button>}
|
||||
<ModuleSwitcher sidebarCollapsed={sidebarCollapsed} compact={!sidebarCollapsed} />
|
||||
{!workspaceLayout && <ModuleSwitcher sidebarCollapsed={sidebarCollapsed} compact={!sidebarCollapsed} />}
|
||||
</div>
|
||||
</div>}
|
||||
|
||||
|
||||
@@ -178,7 +178,7 @@ function ProductTitleBar({
|
||||
onPointerEnter={sidebarPreviewTitlebarVisible ? () => handleSidebarPeekEnter('titlebar') : undefined}
|
||||
onPointerLeave={sidebarPreviewTitlebarVisible ? () => handleSidebarPeekLeave('titlebar') : undefined}
|
||||
/>
|
||||
{typeof document !== 'undefined' ? createPortal(sidebarTogglePortal, document.body) : sidebarTogglePortal}
|
||||
{(!workspaceLayout || sidebarCollapsed) && (typeof document !== 'undefined' ? createPortal(sidebarTogglePortal, document.body) : sidebarTogglePortal)}
|
||||
</>
|
||||
) : null}
|
||||
{integrated ? (
|
||||
|
||||
Reference in New Issue
Block a user