2022-04-22 15:00:18 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2022-06-27 14:25:59 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme';
|
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme';
|
2022-04-22 15:00:18 +08:00
|
|
|
import genLayoutLightStyle from './light';
|
|
|
|
|
2022-05-19 16:23:12 +08:00
|
|
|
export interface ComponentToken {
|
|
|
|
colorBgHeader: string;
|
|
|
|
colorBgBody: string;
|
|
|
|
colorBgTrigger: string;
|
|
|
|
}
|
|
|
|
|
2022-04-22 15:00:18 +08:00
|
|
|
export interface LayoutToken extends FullToken<'Layout'> {
|
|
|
|
// Layout
|
|
|
|
layoutHeaderHeight: number;
|
2022-05-19 16:23:12 +08:00
|
|
|
layoutHeaderPaddingInline: number;
|
2022-04-22 15:00:18 +08:00
|
|
|
layoutHeaderColor: string;
|
|
|
|
layoutFooterPadding: string;
|
|
|
|
layoutTriggerHeight: number;
|
2022-05-19 16:23:12 +08:00
|
|
|
layoutZeroTriggerSize: number;
|
2022-04-22 15:00:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const genLayoutStyle: GenerateStyle<LayoutToken, CSSObject> = token => {
|
|
|
|
const {
|
|
|
|
antCls, // .ant
|
|
|
|
componentCls, // .ant-layout
|
|
|
|
colorText,
|
2022-05-19 16:23:12 +08:00
|
|
|
colorTextLightSolid,
|
|
|
|
colorBgHeader,
|
|
|
|
colorBgBody,
|
|
|
|
colorBgTrigger,
|
2022-04-22 15:00:18 +08:00
|
|
|
layoutHeaderHeight,
|
2022-05-19 16:23:12 +08:00
|
|
|
layoutHeaderPaddingInline,
|
2022-04-22 15:00:18 +08:00
|
|
|
layoutHeaderColor,
|
|
|
|
layoutFooterPadding,
|
|
|
|
layoutTriggerHeight,
|
2022-05-19 16:23:12 +08:00
|
|
|
layoutZeroTriggerSize,
|
2022-04-22 15:00:18 +08:00
|
|
|
motionDurationMid,
|
|
|
|
motionDurationSlow,
|
|
|
|
fontSizeBase,
|
|
|
|
radiusBase,
|
|
|
|
} = 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,
|
|
|
|
background: colorBgBody,
|
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}-header`]: {
|
|
|
|
height: layoutHeaderHeight,
|
2022-05-19 16:23:12 +08:00
|
|
|
paddingInline: layoutHeaderPaddingInline,
|
2022-04-22 15:00:18 +08:00
|
|
|
color: layoutHeaderColor,
|
|
|
|
lineHeight: `${layoutHeaderHeight}px`,
|
2022-05-19 16:23:12 +08:00
|
|
|
background: colorBgHeader,
|
2022-04-22 15:00:18 +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',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-footer`]: {
|
|
|
|
padding: layoutFooterPadding,
|
|
|
|
color: colorText,
|
|
|
|
fontSize: fontSizeBase,
|
2022-05-19 16:23:12 +08:00
|
|
|
background: colorBgBody,
|
2022-04-22 15:00:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-content`]: {
|
|
|
|
flex: 'auto',
|
|
|
|
|
|
|
|
// fix firefox can't set height smaller than content on flex item
|
2022-05-19 16:23:12 +08:00
|
|
|
minHeight: 0,
|
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,
|
|
|
|
background: colorBgHeader,
|
2022-04-22 15:00:18 +08:00
|
|
|
transition: `all ${motionDurationMid}`,
|
|
|
|
|
|
|
|
'&-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
|
|
|
|
|
|
|
[`${antCls}-menu${antCls}menu-inline-collapsed`]: {
|
|
|
|
width: 'auto',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-has-trigger': {
|
|
|
|
paddingBottom: layoutTriggerHeight,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-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,
|
2022-04-22 15:00:18 +08:00
|
|
|
height: layoutTriggerHeight,
|
2022-05-19 16:23:12 +08:00
|
|
|
color: colorTextLightSolid,
|
2022-04-22 15:00:18 +08:00
|
|
|
lineHeight: `${layoutTriggerHeight}px`,
|
|
|
|
textAlign: 'center',
|
2022-05-19 16:23:12 +08:00
|
|
|
background: colorBgTrigger,
|
2022-04-22 15:00:18 +08:00
|
|
|
cursor: 'pointer',
|
|
|
|
transition: `all ${motionDurationMid}`,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-zero-width': {
|
|
|
|
'> *': {
|
|
|
|
overflow: 'hidden',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-trigger': {
|
|
|
|
position: 'absolute',
|
|
|
|
top: layoutHeaderHeight,
|
2022-05-19 16:23:12 +08:00
|
|
|
insetInlineEnd: -layoutZeroTriggerSize,
|
|
|
|
zIndex: 1,
|
|
|
|
width: layoutZeroTriggerSize,
|
|
|
|
height: layoutZeroTriggerSize,
|
|
|
|
color: colorTextLightSolid,
|
|
|
|
fontSize: token.fontSizeXL,
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
background: colorBgHeader,
|
|
|
|
borderStartStartRadius: 0,
|
2022-04-22 15:00:18 +08:00
|
|
|
borderStartEndRadius: radiusBase,
|
|
|
|
borderEndEndRadius: radiusBase,
|
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
|
|
|
// FIXME: Hardcode, but seems no need to create a token for this
|
|
|
|
background: `rgba(255, 255, 255, 0.2)`,
|
2022-04-22 15:00:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&-right': {
|
2022-05-19 16:23:12 +08:00
|
|
|
insetInlineStart: -layoutZeroTriggerSize,
|
2022-04-22 15:00:18 +08:00
|
|
|
borderStartStartRadius: radiusBase,
|
2022-05-19 16:23:12 +08:00
|
|
|
borderStartEndRadius: 0,
|
|
|
|
borderEndEndRadius: 0,
|
2022-04-22 15:00:18 +08:00
|
|
|
borderEndStartRadius: radiusBase,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// Light
|
|
|
|
...genLayoutLightStyle(token),
|
|
|
|
// RTL
|
|
|
|
'&-rtl': {
|
|
|
|
direction: 'rtl',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2022-05-19 16:23:12 +08:00
|
|
|
export default genComponentStyleHook(
|
|
|
|
'Layout',
|
|
|
|
token => {
|
|
|
|
const { colorText, controlHeightSM, controlHeight, controlHeightLG, marginXXS } = token;
|
|
|
|
const layoutHeaderPaddingInline = controlHeightLG * 1.25;
|
|
|
|
|
|
|
|
const layoutToken = mergeToken<LayoutToken>(token, {
|
|
|
|
// Layout
|
|
|
|
layoutHeaderHeight: controlHeight * 2,
|
|
|
|
layoutHeaderPaddingInline,
|
|
|
|
layoutHeaderColor: colorText,
|
|
|
|
layoutFooterPadding: `${controlHeightSM}px ${layoutHeaderPaddingInline}px`,
|
|
|
|
layoutTriggerHeight: controlHeightLG + marginXXS * 2, // = item height + margin
|
|
|
|
layoutZeroTriggerSize: controlHeightLG,
|
|
|
|
});
|
|
|
|
|
|
|
|
return [genLayoutStyle(layoutToken)];
|
|
|
|
},
|
|
|
|
{
|
|
|
|
colorBgHeader: '#001529',
|
|
|
|
colorBgBody: '#f0f2f5',
|
|
|
|
colorBgTrigger: '#002140',
|
|
|
|
},
|
|
|
|
);
|