|
import type { CSSProperties } from 'react'; |
|
import { unit } from '@ant-design/cssinjs'; |
|
import type { CSSObject } from '@ant-design/cssinjs'; |
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal'; |
|
import { genStyleHooks } from '../../theme/internal'; |
|
|
|
export interface ComponentToken { |
|
|
|
colorBgHeader: string; |
|
|
|
colorBgBody: string; |
|
|
|
colorBgTrigger: string; |
|
|
|
|
|
|
|
|
|
|
|
bodyBg: string; |
|
|
|
|
|
|
|
|
|
headerBg: string; |
|
|
|
|
|
|
|
|
|
headerHeight: number | string; |
|
|
|
|
|
|
|
|
|
headerPadding: CSSProperties['padding']; |
|
|
|
|
|
|
|
|
|
headerColor: string; |
|
|
|
|
|
|
|
|
|
footerPadding: CSSProperties['padding']; |
|
|
|
|
|
|
|
|
|
footerBg: string; |
|
|
|
|
|
|
|
|
|
siderBg: string; |
|
|
|
|
|
|
|
|
|
triggerHeight: number | string; |
|
|
|
|
|
|
|
|
|
triggerBg: string; |
|
|
|
|
|
|
|
|
|
triggerColor: string; |
|
|
|
|
|
|
|
|
|
zeroTriggerWidth: number; |
|
|
|
|
|
|
|
|
|
zeroTriggerHeight: number; |
|
|
|
|
|
|
|
|
|
lightSiderBg: string; |
|
|
|
|
|
|
|
|
|
lightTriggerBg: string; |
|
|
|
|
|
|
|
|
|
lightTriggerColor: string; |
|
} |
|
|
|
export interface LayoutToken extends FullToken<'Layout'> {} |
|
|
|
const genLayoutStyle: GenerateStyle<LayoutToken, CSSObject> = (token) => { |
|
const { |
|
antCls, |
|
componentCls, |
|
colorText, |
|
footerBg, |
|
headerHeight, |
|
headerPadding, |
|
headerColor, |
|
footerPadding, |
|
fontSize, |
|
bodyBg, |
|
headerBg, |
|
} = token; |
|
|
|
return { |
|
[componentCls]: { |
|
display: 'flex', |
|
flex: 'auto', |
|
flexDirection: 'column', |
|
|
|
|
|
minHeight: 0, |
|
background: bodyBg, |
|
|
|
'&, *': { |
|
boxSizing: 'border-box', |
|
}, |
|
|
|
[`&${componentCls}-has-sider`]: { |
|
flexDirection: 'row', |
|
[`> ${componentCls}, > ${componentCls}-content`]: { |
|
|
|
width: 0, |
|
}, |
|
}, |
|
|
|
[`${componentCls}-header, &${componentCls}-footer`]: { |
|
flex: '0 0 auto', |
|
}, |
|
|
|
|
|
'&-rtl': { |
|
direction: 'rtl', |
|
}, |
|
}, |
|
|
|
|
|
[`${componentCls}-header`]: { |
|
height: headerHeight, |
|
padding: headerPadding, |
|
color: headerColor, |
|
lineHeight: unit(headerHeight), |
|
background: headerBg, |
|
|
|
|
|
|
|
[`${antCls}-menu`]: { |
|
lineHeight: 'inherit', |
|
}, |
|
}, |
|
|
|
|
|
[`${componentCls}-footer`]: { |
|
padding: footerPadding, |
|
color: colorText, |
|
fontSize, |
|
background: footerBg, |
|
}, |
|
|
|
|
|
[`${componentCls}-content`]: { |
|
flex: 'auto', |
|
color: colorText, |
|
|
|
|
|
minHeight: 0, |
|
}, |
|
}; |
|
}; |
|
|
|
export const prepareComponentToken: GetDefaultToken<'Layout'> = (token) => { |
|
const { |
|
colorBgLayout, |
|
controlHeight, |
|
controlHeightLG, |
|
colorText, |
|
controlHeightSM, |
|
marginXXS, |
|
colorTextLightSolid, |
|
colorBgContainer, |
|
} = token; |
|
|
|
const paddingInline = controlHeightLG * 1.25; |
|
|
|
return { |
|
|
|
colorBgHeader: '#001529', |
|
colorBgBody: colorBgLayout, |
|
colorBgTrigger: '#002140', |
|
|
|
bodyBg: colorBgLayout, |
|
headerBg: '#001529', |
|
headerHeight: controlHeight * 2, |
|
headerPadding: `0 ${paddingInline}px`, |
|
headerColor: colorText, |
|
footerPadding: `${controlHeightSM}px ${paddingInline}px`, |
|
footerBg: colorBgLayout, |
|
siderBg: '#001529', |
|
triggerHeight: controlHeightLG + marginXXS * 2, |
|
triggerBg: '#002140', |
|
triggerColor: colorTextLightSolid, |
|
zeroTriggerWidth: controlHeightLG, |
|
zeroTriggerHeight: controlHeightLG, |
|
lightSiderBg: colorBgContainer, |
|
lightTriggerBg: colorBgContainer, |
|
lightTriggerColor: colorText, |
|
}; |
|
}; |
|
|
|
|
|
export const DEPRECATED_TOKENS: [keyof ComponentToken, keyof ComponentToken][] = [ |
|
['colorBgBody', 'bodyBg'], |
|
['colorBgHeader', 'headerBg'], |
|
['colorBgTrigger', 'triggerBg'], |
|
]; |
|
|
|
export default genStyleHooks('Layout', (token) => [genLayoutStyle(token)], prepareComponentToken, { |
|
deprecatedTokens: DEPRECATED_TOKENS, |
|
}); |
|
|