forked from ant-design/ant-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tsx
225 lines (196 loc) · 6.12 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
import type { CSSObject } from '@ant-design/cssinjs';
import type { FullToken, GenerateStyle } from '../../theme';
import { genComponentStyleHook, mergeToken } from '../../theme';
import genLayoutLightStyle from './light';
export interface ComponentToken {
colorBgHeader: string;
colorBgBody: string;
colorBgTrigger: string;
}
export interface LayoutToken extends FullToken<'Layout'> {
// Layout
layoutHeaderHeight: number;
layoutHeaderPaddingInline: number;
layoutHeaderColor: string;
layoutFooterPadding: string;
layoutTriggerHeight: number;
layoutZeroTriggerSize: number;
}
const genLayoutStyle: GenerateStyle<LayoutToken, CSSObject> = (token) => {
const {
antCls, // .ant
componentCls, // .ant-layout
colorText,
colorTextLightSolid,
colorBgHeader,
colorBgBody,
colorBgTrigger,
layoutHeaderHeight,
layoutHeaderPaddingInline,
layoutHeaderColor,
layoutFooterPadding,
layoutTriggerHeight,
layoutZeroTriggerSize,
motionDurationMid,
motionDurationSlow,
fontSize,
borderRadius,
} = token;
return {
[componentCls]: {
display: 'flex',
flex: 'auto',
flexDirection: 'column',
/* fix firefox can't set height smaller than content on flex item */
minHeight: 0,
background: colorBgBody,
'&, *': {
boxSizing: 'border-box',
},
[`&${componentCls}-has-sider`]: {
flexDirection: 'row',
[`> ${componentCls}, > ${componentCls}-content`]: {
// https://segmentfault.com/a/1190000019498300
width: 0,
},
},
[`${componentCls}-header, &${componentCls}-footer`]: {
flex: '0 0 auto',
},
[`${componentCls}-header`]: {
height: layoutHeaderHeight,
paddingInline: layoutHeaderPaddingInline,
color: layoutHeaderColor,
lineHeight: `${layoutHeaderHeight}px`,
background: colorBgHeader,
// 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,
background: colorBgBody,
},
[`${componentCls}-content`]: {
flex: 'auto',
// fix firefox can't set height smaller than content on flex item
minHeight: 0,
},
[`${componentCls}-sider`]: {
position: 'relative',
// fix firefox can't set width smaller than content on flex item
minWidth: 0,
background: colorBgHeader,
transition: `all ${motionDurationMid}`,
'&-children': {
height: '100%',
// Hack for fixing margin collapse bug
// https://github.com/ant-design/ant-design/issues/7967
// solution from https://stackoverflow.com/a/33132624/3040605
marginTop: -0.1,
paddingTop: 0.1,
[`${antCls}-menu${antCls}-menu-inline-collapsed`]: {
width: 'auto',
},
},
'&-has-trigger': {
paddingBottom: layoutTriggerHeight,
},
'&-right': {
order: 1,
},
'&-trigger': {
position: 'fixed',
bottom: 0,
zIndex: 1,
height: layoutTriggerHeight,
color: colorTextLightSolid,
lineHeight: `${layoutTriggerHeight}px`,
textAlign: 'center',
background: colorBgTrigger,
cursor: 'pointer',
transition: `all ${motionDurationMid}`,
},
'&-zero-width': {
'> *': {
overflow: 'hidden',
},
'&-trigger': {
position: 'absolute',
top: layoutHeaderHeight,
insetInlineEnd: -layoutZeroTriggerSize,
zIndex: 1,
width: layoutZeroTriggerSize,
height: layoutZeroTriggerSize,
color: colorTextLightSolid,
fontSize: token.fontSizeXL,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
background: colorBgHeader,
borderStartStartRadius: 0,
borderStartEndRadius: borderRadius,
borderEndEndRadius: borderRadius,
borderEndStartRadius: 0,
cursor: 'pointer',
transition: `background ${motionDurationSlow} ease`,
'&::after': {
position: 'absolute',
inset: 0,
background: 'transparent',
transition: `all ${motionDurationSlow}`,
content: '""',
},
'&:hover::after': {
// FIXME: Hardcode, but seems no need to create a token for this
background: `rgba(255, 255, 255, 0.2)`,
},
'&-right': {
insetInlineStart: -layoutZeroTriggerSize,
borderStartStartRadius: borderRadius,
borderStartEndRadius: 0,
borderEndEndRadius: 0,
borderEndStartRadius: borderRadius,
},
},
},
},
// Light
...genLayoutLightStyle(token),
// RTL
'&-rtl': {
direction: 'rtl',
},
},
};
};
// ============================== Export ==============================
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)];
},
(token) => {
const { colorBgLayout } = token;
return {
colorBgHeader: '#001529',
colorBgBody: colorBgLayout,
colorBgTrigger: '#002140',
};
},
);