2023-11-13 11:24:37 +08:00
|
|
|
import { unit, type CSSObject } from '@ant-design/cssinjs';
|
2023-08-11 19:37:44 +08:00
|
|
|
import type { CSSProperties } from 'react';
|
2023-11-13 11:24:37 +08:00
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
|
2023-08-11 19:37:44 +08:00
|
|
|
import { genComponentStyleHook } from '../../theme/internal';
|
2022-04-22 15:00:18 +08:00
|
|
|
import genLayoutLightStyle from './light';
|
|
|
|
|
2022-05-19 16:23:12 +08:00
|
|
|
export interface ComponentToken {
|
2023-08-11 19:37:44 +08:00
|
|
|
/** @deprecated Use headerBg instead */
|
2022-05-19 16:23:12 +08:00
|
|
|
colorBgHeader: string;
|
2023-08-11 19:37:44 +08:00
|
|
|
/** @deprecated Use bodyBg instead */
|
2022-05-19 16:23:12 +08:00
|
|
|
colorBgBody: string;
|
2023-08-11 19:37:44 +08:00
|
|
|
/** @deprecated Use triggerBg instead */
|
2022-05-19 16:23:12 +08:00
|
|
|
colorBgTrigger: string;
|
|
|
|
|
2023-08-11 19:37:44 +08:00
|
|
|
/**
|
|
|
|
* @desc 主体部分背景色
|
|
|
|
* @descEN Background Color of body
|
|
|
|
*/
|
|
|
|
bodyBg: string;
|
|
|
|
/**
|
|
|
|
* @desc 顶部背景色
|
|
|
|
* @descEN Background Color of header
|
|
|
|
*/
|
|
|
|
headerBg: string;
|
|
|
|
/**
|
|
|
|
* @desc 顶部高度
|
|
|
|
* @descEN Height of header
|
|
|
|
*/
|
|
|
|
headerHeight: number;
|
|
|
|
/**
|
|
|
|
* @desc 顶部内边距
|
|
|
|
* @descEN Padding of header
|
|
|
|
*/
|
|
|
|
headerPadding: CSSProperties['padding'];
|
|
|
|
/**
|
|
|
|
* @desc 顶部文字颜色
|
|
|
|
* @descEN Text color of header
|
|
|
|
*/
|
|
|
|
headerColor: string;
|
|
|
|
/**
|
|
|
|
* @desc 页脚内边距
|
|
|
|
* @descEN Padding of footer
|
|
|
|
*/
|
|
|
|
footerPadding: CSSProperties['padding'];
|
|
|
|
/**
|
|
|
|
* @desc 页脚背景色
|
|
|
|
* @descEN Background Color of footer
|
|
|
|
*/
|
|
|
|
footerBg: string;
|
|
|
|
/**
|
|
|
|
* @desc 侧边栏背景色
|
|
|
|
* @descEN Background Color of sider
|
|
|
|
*/
|
|
|
|
siderBg: string;
|
|
|
|
/**
|
|
|
|
* @desc 侧边栏开关高度
|
|
|
|
* @descEN Height of sider trigger
|
|
|
|
*/
|
|
|
|
triggerHeight: number;
|
|
|
|
/**
|
|
|
|
* @desc 侧边栏开关背景色
|
|
|
|
* @descEN Background Color of sider trigger
|
|
|
|
*/
|
|
|
|
triggerBg: string;
|
|
|
|
/**
|
|
|
|
* @desc 侧边栏开关颜色
|
|
|
|
* @descEN Color of sider trigger
|
|
|
|
*/
|
|
|
|
triggerColor: string;
|
|
|
|
/**
|
|
|
|
* @desc collapse 为 0 时侧边栏开关宽度
|
|
|
|
* @descEN Width of sider trigger when collapse is 0
|
|
|
|
*/
|
|
|
|
zeroTriggerWidth: number;
|
|
|
|
/**
|
|
|
|
* @desc collapse 为 0 时侧边栏开关高度
|
|
|
|
* @descEN Height of sider trigger when collapse is 0
|
|
|
|
*/
|
|
|
|
zeroTriggerHeight: number;
|
|
|
|
/**
|
|
|
|
* @desc 亮色主题侧边栏背景色
|
|
|
|
* @descEN Background Color of light theme sider
|
|
|
|
*/
|
|
|
|
lightSiderBg: string;
|
|
|
|
/**
|
|
|
|
* @desc 亮色主题侧边栏开关背景色
|
|
|
|
* @descEN Background Color of light theme sider trigger
|
|
|
|
*/
|
|
|
|
lightTriggerBg: string;
|
|
|
|
/**
|
|
|
|
* @desc 亮色主题侧边栏开关颜色
|
|
|
|
* @descEN Color of light theme sider trigger
|
|
|
|
*/
|
|
|
|
lightTriggerColor: string;
|
2022-04-22 15:00:18 +08:00
|
|
|
}
|
|
|
|
|
2023-08-11 19:37:44 +08:00
|
|
|
export interface LayoutToken extends FullToken<'Layout'> {}
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const genLayoutStyle: GenerateStyle<LayoutToken, CSSObject> = (token) => {
|
2022-04-22 15:00:18 +08:00
|
|
|
const {
|
|
|
|
antCls, // .ant
|
|
|
|
componentCls, // .ant-layout
|
|
|
|
colorText,
|
2023-08-11 19:37:44 +08:00
|
|
|
triggerColor,
|
|
|
|
footerBg,
|
|
|
|
triggerBg,
|
|
|
|
headerHeight,
|
|
|
|
headerPadding,
|
|
|
|
headerColor,
|
|
|
|
footerPadding,
|
|
|
|
triggerHeight,
|
|
|
|
zeroTriggerHeight,
|
|
|
|
zeroTriggerWidth,
|
2022-04-22 15:00:18 +08:00
|
|
|
motionDurationMid,
|
|
|
|
motionDurationSlow,
|
2022-11-01 15:06:38 +08:00
|
|
|
fontSize,
|
|
|
|
borderRadius,
|
2023-08-11 19:37:44 +08:00
|
|
|
bodyBg,
|
|
|
|
headerBg,
|
|
|
|
siderBg,
|
2022-04-22 15:00:18 +08:00
|
|
|
} = token;
|
|
|
|
|
|
|
|
return {
|
|
|
|
[componentCls]: {
|
|
|
|
display: 'flex',
|
|
|
|
flex: 'auto',
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
|
|
|
/* fix firefox can't set height smaller than content on flex item */
|
2022-05-19 16:23:12 +08:00
|
|
|
minHeight: 0,
|
2023-08-11 19:37:44 +08:00
|
|
|
background: bodyBg,
|
2022-04-22 15:00:18 +08:00
|
|
|
|
|
|
|
'&, *': {
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&${componentCls}-has-sider`]: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
[`> ${componentCls}, > ${componentCls}-content`]: {
|
2022-05-19 16:23:12 +08:00
|
|
|
// https://segmentfault.com/a/1190000019498300
|
|
|
|
width: 0,
|
2022-04-22 15:00:18 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-header, &${componentCls}-footer`]: {
|
2022-05-19 16:23:12 +08:00
|
|
|
flex: '0 0 auto',
|
2022-04-22 15:00:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-sider`]: {
|
|
|
|
position: 'relative',
|
|
|
|
|
|
|
|
// fix firefox can't set width smaller than content on flex item
|
2022-05-19 16:23:12 +08:00
|
|
|
minWidth: 0,
|
2023-08-11 19:37:44 +08:00
|
|
|
background: siderBg,
|
2023-04-25 22:53:14 +08:00
|
|
|
transition: `all ${motionDurationMid}, background 0s`,
|
2022-04-22 15:00:18 +08:00
|
|
|
|
|
|
|
'&-children': {
|
2022-05-19 16:23:12 +08:00
|
|
|
height: '100%',
|
|
|
|
// Hack for fixing margin collapse bug
|
2022-04-22 15:00:18 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/7967
|
|
|
|
// solution from https://stackoverflow.com/a/33132624/3040605
|
2022-05-19 16:23:12 +08:00
|
|
|
marginTop: -0.1,
|
|
|
|
paddingTop: 0.1,
|
2022-04-22 15:00:18 +08:00
|
|
|
|
2022-11-21 16:40:59 +08:00
|
|
|
[`${antCls}-menu${antCls}-menu-inline-collapsed`]: {
|
2022-04-22 15:00:18 +08:00
|
|
|
width: 'auto',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-has-trigger': {
|
2023-08-11 19:37:44 +08:00
|
|
|
paddingBottom: triggerHeight,
|
2022-04-22 15:00:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&-right': {
|
2022-05-19 16:23:12 +08:00
|
|
|
order: 1,
|
2022-04-22 15:00:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&-trigger': {
|
|
|
|
position: 'fixed',
|
2022-05-19 16:23:12 +08:00
|
|
|
bottom: 0,
|
|
|
|
zIndex: 1,
|
2023-08-11 19:37:44 +08:00
|
|
|
height: triggerHeight,
|
|
|
|
color: triggerColor,
|
2023-11-13 11:24:37 +08:00
|
|
|
lineHeight: unit(triggerHeight),
|
2022-04-22 15:00:18 +08:00
|
|
|
textAlign: 'center',
|
2023-08-11 19:37:44 +08:00
|
|
|
background: triggerBg,
|
2022-04-22 15:00:18 +08:00
|
|
|
cursor: 'pointer',
|
|
|
|
transition: `all ${motionDurationMid}`,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-zero-width': {
|
|
|
|
'> *': {
|
|
|
|
overflow: 'hidden',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-trigger': {
|
|
|
|
position: 'absolute',
|
2023-08-11 19:37:44 +08:00
|
|
|
top: headerHeight,
|
2023-11-13 11:24:37 +08:00
|
|
|
insetInlineEnd: token.calc(zeroTriggerWidth).mul(-1).equal(),
|
2022-05-19 16:23:12 +08:00
|
|
|
zIndex: 1,
|
2023-08-11 19:37:44 +08:00
|
|
|
width: zeroTriggerWidth,
|
|
|
|
height: zeroTriggerHeight,
|
|
|
|
color: triggerColor,
|
2022-05-19 16:23:12 +08:00
|
|
|
fontSize: token.fontSizeXL,
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
2023-08-11 19:37:44 +08:00
|
|
|
background: siderBg,
|
2022-05-19 16:23:12 +08:00
|
|
|
borderStartStartRadius: 0,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderStartEndRadius: borderRadius,
|
|
|
|
borderEndEndRadius: borderRadius,
|
2022-05-19 16:23:12 +08:00
|
|
|
borderEndStartRadius: 0,
|
2022-04-22 15:00:18 +08:00
|
|
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
transition: `background ${motionDurationSlow} ease`,
|
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
position: 'absolute',
|
2022-05-19 16:23:12 +08:00
|
|
|
inset: 0,
|
2022-04-22 15:00:18 +08:00
|
|
|
background: 'transparent',
|
|
|
|
transition: `all ${motionDurationSlow}`,
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:hover::after': {
|
2022-05-19 16:23:12 +08:00
|
|
|
background: `rgba(255, 255, 255, 0.2)`,
|
2022-04-22 15:00:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&-right': {
|
2023-11-13 11:24:37 +08:00
|
|
|
insetInlineStart: token.calc(zeroTriggerWidth).mul(-1).equal(),
|
2022-11-01 15:06:38 +08:00
|
|
|
borderStartStartRadius: borderRadius,
|
2022-05-19 16:23:12 +08:00
|
|
|
borderStartEndRadius: 0,
|
|
|
|
borderEndEndRadius: 0,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderEndStartRadius: borderRadius,
|
2022-04-22 15:00:18 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Light
|
|
|
|
...genLayoutLightStyle(token),
|
|
|
|
// RTL
|
|
|
|
'&-rtl': {
|
|
|
|
direction: 'rtl',
|
|
|
|
},
|
|
|
|
},
|
2023-02-27 15:35:22 +08:00
|
|
|
|
|
|
|
// ==================== Header ====================
|
|
|
|
[`${componentCls}-header`]: {
|
2023-08-11 19:37:44 +08:00
|
|
|
height: headerHeight,
|
|
|
|
padding: headerPadding,
|
|
|
|
color: headerColor,
|
2023-11-13 11:24:37 +08:00
|
|
|
lineHeight: unit(headerHeight),
|
2023-08-11 19:37:44 +08:00
|
|
|
background: headerBg,
|
2023-02-27 15:35:22 +08:00
|
|
|
|
|
|
|
// Other components/menu/style/index.less line:686
|
|
|
|
// Integration with header element so menu items have the same height
|
|
|
|
[`${antCls}-menu`]: {
|
|
|
|
lineHeight: 'inherit',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ==================== Footer ====================
|
|
|
|
[`${componentCls}-footer`]: {
|
2023-08-11 19:37:44 +08:00
|
|
|
padding: footerPadding,
|
2023-02-27 15:35:22 +08:00
|
|
|
color: colorText,
|
|
|
|
fontSize,
|
2023-08-11 19:37:44 +08:00
|
|
|
background: footerBg,
|
2023-02-27 15:35:22 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
// =================== Content ====================
|
|
|
|
[`${componentCls}-content`]: {
|
|
|
|
flex: 'auto',
|
|
|
|
|
|
|
|
// fix firefox can't set height smaller than content on flex item
|
|
|
|
minHeight: 0,
|
|
|
|
},
|
2022-04-22 15:00:18 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-11-13 11:24:37 +08:00
|
|
|
export const prepareComponentToken: GetDefaultToken<'Layout'> = (token) => {
|
|
|
|
const {
|
|
|
|
colorBgLayout,
|
|
|
|
controlHeight,
|
|
|
|
controlHeightLG,
|
|
|
|
colorText,
|
|
|
|
controlHeightSM,
|
|
|
|
marginXXS,
|
|
|
|
colorTextLightSolid,
|
|
|
|
colorBgContainer,
|
|
|
|
} = token;
|
|
|
|
|
|
|
|
const paddingInline = controlHeightLG * 1.25;
|
|
|
|
|
|
|
|
return {
|
|
|
|
// Deprecated
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-04-22 15:00:18 +08:00
|
|
|
// ============================== Export ==============================
|
2022-05-19 16:23:12 +08:00
|
|
|
export default genComponentStyleHook(
|
|
|
|
'Layout',
|
2023-08-11 19:37:44 +08:00
|
|
|
(token) => [genLayoutStyle(token)],
|
2023-11-13 11:24:37 +08:00
|
|
|
prepareComponentToken,
|
2023-08-11 19:37:44 +08:00
|
|
|
{
|
|
|
|
deprecatedTokens: [
|
|
|
|
['colorBgBody', 'bodyBg'],
|
|
|
|
['colorBgHeader', 'headerBg'],
|
|
|
|
['colorBgTrigger', 'triggerBg'],
|
|
|
|
],
|
|
|
|
},
|
2022-05-19 16:23:12 +08:00
|
|
|
);
|