Files
AIRegulation-DocAnalysis/frontend/src/components/layout/KeepAliveViewport.tsx
ash66 987cc097da feat: implement new layout components and routing structure
- Added HeaderLayout component for the application header.
- Introduced KeepAliveViewport for managing tab states and rendering.
- Created TabNav for tab navigation with animated indicator.
- Removed old Tabs component in favor of new layout structure.
- Updated routing with AppRouter and defined appTabs for navigation.
- Enhanced theme context to manage dark mode styles.
- Added new UI components: Badge, Button, Separator, and Tabs.
- Refactored pages to utilize new layout components and improve responsiveness.
- Updated global styles for better theming and layout consistency.
- Introduced TypeScript path aliases for cleaner imports.
2026-05-25 16:19:18 +08:00

46 lines
1.2 KiB
TypeScript

import { useEffect, useState } from 'react';
import { appTabs, type AppTabConfig } from '../../router/tabs';
interface KeepAliveViewportProps {
activeTab: AppTabConfig;
}
export function KeepAliveViewport({ activeTab }: KeepAliveViewportProps) {
const [mountedTabIds, setMountedTabIds] = useState<string[]>([activeTab.id]);
useEffect(() => {
const timerId = window.setTimeout(() => {
setMountedTabIds((prev) => (prev.includes(activeTab.id) ? prev : [...prev, activeTab.id]));
}, 0);
return () => window.clearTimeout(timerId);
}, [activeTab.id]);
return (
<div className="flex min-h-0 flex-1">
{appTabs.map((tab) => {
const shouldRender = tab.keepAlive ? mountedTabIds.includes(tab.id) : tab.id === activeTab.id;
if (!shouldRender) {
return null;
}
const TabComponent = tab.component;
const isActive = tab.id === activeTab.id;
return (
<div
key={tab.id}
aria-hidden={!isActive}
className={[
'min-h-0 flex-1',
isActive ? 'flex' : 'hidden',
].join(' ')}
>
<TabComponent />
</div>
);
})}
</div>
);
}