nex_animation/frontend/src/app/layout/SideNav.tsx

72 lines
3.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* 左侧导航:全局模块 + 当前项目的 7 个环节。
*
* · 折叠轨道(≤900px)只留图标:中文标签放不下一行,两行换行会把 nav 撑到
* 比视口还高,看起来像「按钮消失」,因此标签交给 title / aria-label。
* · 折叠宽度沿用旧样式表里真正生效的那一档(68px / ≤560 66px),
* 主内容区宽度是 calc(100% - 同一个数),两处必须一起改。
* · sticky top 取 --nex-bar:旧样式表尾部又写了一遍 top:0,
* 会把第一个图标藏到顶栏底下,这里统一按顶栏高度让开。
*/
import type { ReactNode } from 'react'
import { NavLink, useLocation } from 'react-router-dom'
import { cn } from '../../lib/cn'
import { modules } from './nav'
import { useCurrentStageNote } from './PipelineConsole'
const NAV_ITEM = cn(
'flex items-center gap-2.5 rounded-tile px-[9px] py-[10px] text-body font-medium text-ink-3 no-underline',
'hover:bg-hover hover:text-ink max-nav:justify-center max-nav:gap-0 max-nav:min-h-[38px] max-nav:px-[2px] max-nav:py-[9px] max-nav:text-center'
)
const NAV_ICON = 'w-[18px] flex-none text-center text-ui text-muted max-nav:w-auto max-nav:text-md'
const NAV_LABEL = 'max-nav:hidden'
function NavItem({ to, icon, label, hint, chosen }: {
to: string; icon: ReactNode; label: string; hint?: string; chosen: boolean
}) {
const text = hint ? `${label}:${hint}` : label
return (
<NavLink to={to} aria-label={text} title={text}
className={cn(NAV_ITEM, chosen && 'bg-active text-accent shadow-[inset_2px_0_0_var(--c-accent)] [&_.navicon]:text-accent')}>
<span className={cn(NAV_ICON, 'navicon')}>{icon}</span>
<span className={NAV_LABEL}>{label}</span>
</NavLink>
)
}
export function SideNav({ projectId, projectTitle }: { projectId: string; projectTitle: string }) {
const { pathname } = useLocation()
const stageNote = projectId ? useCurrentStageNote(projectId) : ''
return (
<aside className={cn(
'sticky top-(--nex-bar) flex h-[calc(100vh-var(--nex-bar))] w-[230px] flex-none flex-col overflow-y-auto',
'border-r border-emphasis bg-shell px-[14px] py-6 scrollbar-none',
'max-nav:w-[68px] max-nav:px-[6px] max-nav:py-4 max-narrow:w-[66px] max-narrow:px-[5px] max-narrow:py-3'
)}>
<nav className="mb-[18px] flex flex-col gap-[3px] flex-none max-nav:mb-3 max-nav:gap-1.5">
<NavItem to="/" icon="⌂" label="项目总览" chosen={pathname === '/'} />
<NavItem to="/assets" icon="✧" label="平台资产库" hint="人物 / 场景 / 声线母版" chosen={pathname === '/assets'} />
<NavItem to="/models" icon="◫" label="模型管理中心" hint="大模型 / 视频 / 图像 / 声音" chosen={pathname === '/models'} />
</nav>
{projectId && (
<>
<div className="mt-1.5 border-t border-line-soft px-2 pb-2 pt-4 text-tiny font-bold tracking-[1.2px] text-faint max-nav:hidden">
<span className="block truncate">{projectTitle}</span>
{stageNote && <small className="mt-[5px] block normal-case tracking-normal font-normal text-dim">{stageNote}</small>}
</div>
<nav className="flex flex-col gap-[3px] flex-none max-nav:gap-1.5">
{modules.map((m) => {
const to = m.to(projectId)
return <NavItem key={m.label} to={to} icon={m.icon} label={m.label} hint={m.hint} chosen={pathname === to} />
})}
</nav>
</>
)}
</aside>
)
}
export default SideNav