import classNames from 'clsx'; import { type FC } from 'react'; import type { AdminLayoutProps } from '../../types'; import style from './index.module.css'; import { LAYOUT_MAX_Z_INDEX, LAYOUT_SCROLL_EL_ID, createLayoutCssVars } from './shared'; // eslint-disable-next-line complexity const AdminLayout: FC = ({ children, commonClass = 'transition-all-300', contentClass, fixedFooter, fixedTop = true, Footer, footerClass, footerHeight = 48, footerVisible = true, fullContent, Header, headerClass, headerHeight = 56, headerVisible = true, isMobile, maxZIndex = LAYOUT_MAX_Z_INDEX, mobileSiderClass, mode = 'vertical', rightFooter = false, scrollElId = LAYOUT_SCROLL_EL_ID, scrollMode = 'content', scrollWrapperClass, Sider, siderClass, siderCollapse = false, siderCollapsedWidth = 64, siderVisible = true, siderWidth = 220, Tab, tabClass, tabHeight = 44, tabVisible = true, updateSiderCollapse }) => { const cssVar = createLayoutCssVars({ footerHeight, headerHeight, isMobile, maxZIndex, mode, siderCollapsedWidth, siderWidth, tabHeight }) as React.CSSProperties; // config visible const showHeader = Boolean(Header) && headerVisible; const showSider = !isMobile && Boolean(Sider) && siderVisible; const showMobileSider = isMobile && Boolean(Sider) && siderVisible; const showTab = Boolean(Tab) && tabVisible; const showFooter = Boolean(Footer) && footerVisible; // scroll mode const isWrapperScroll = scrollMode === 'wrapper'; const isContentScroll = scrollMode === 'content'; // layout direction const isVertical = mode === 'vertical'; const isHorizontal = mode === 'horizontal'; const fixedHeaderAndTab = fixedTop || (isHorizontal && isWrapperScroll); // css const leftGapClass = () => { if (!fullContent && showSider) { return siderCollapse ? style['left-gap_collapsed'] : style['left-gap']; } return ''; }; const headerLeftGapClass = isVertical ? leftGapClass() : ''; const footerLeftGapClass = () => { const condition1 = isVertical; const condition2 = isHorizontal && isWrapperScroll && !fixedFooter; const condition3 = Boolean(isHorizontal && rightFooter); if (condition1 || condition2 || condition3) { return leftGapClass(); } return ''; }; const siderPaddingClass = () => { let cls = ''; if (showHeader && !headerLeftGapClass) { cls += style['sider-padding-top']; } if (showFooter && !footerLeftGapClass()) { cls += ` ${style['sider-padding-bottom']}`; } return cls; }; // display const headerDisplay = !fullContent && fixedHeaderAndTab ? 'block' : 'none'; const siderDisplay = fullContent ? 'none' : 'block'; const mobileSider = siderCollapse ? 'none' : 'block'; const footerDisplay = !fullContent && fixedFooter ? 'block' : 'none'; return (
{/* Header */} {showHeader && ( <>
{Header}
)} {/* Tab */} {showTab && ( <>
{Tab}
)} {/* Sider */} {showSider && ( )} {/* Mobile Sider */} {showMobileSider && ( <>
updateSiderCollapse()} /> )} {/* Main Content */}
{children}
{/* Footer */} {showFooter && ( <>
{Footer}
)}
); }; export default AdminLayout;