1
- import { genCollapseMotion } from '../../style/motion' ;
2
- import type { FullToken , GenerateStyle } from '../../theme/internal' ;
3
- import { genComponentStyleHook , mergeToken } from '../../theme/internal' ;
4
- import { resetComponent , resetIcon } from '../../style' ;
1
+ import type { CSSProperties } from 'vue' ;
2
+ import { unit } from '../../_util/cssinjs' ;
5
3
6
- export interface ComponentToken { }
4
+ import { genFocusStyle , resetComponent , resetIcon } from '../../style' ;
5
+ import { genCollapseMotion } from '../../style/motion' ;
6
+ import type { FullToken , GenerateStyle , GetDefaultToken } from '../../theme/internal' ;
7
+ import { genStyleHooks , mergeToken } from '../../theme/internal' ;
8
+
9
+ /** Component only token. Which will handle additional calculation of alias token */
10
+ export interface ComponentToken {
11
+ // Component token here
12
+ /**
13
+ * @desc 折叠面板头部内边距
14
+ * @descEN Padding of header
15
+ */
16
+ headerPadding : CSSProperties [ 'padding' ] ;
17
+ /**
18
+ * @desc 折叠面板头部背景
19
+ * @descEN Background of header
20
+ */
21
+ headerBg : string ;
22
+ /**
23
+ * @desc 折叠面板内容内边距
24
+ * @descEN Padding of content
25
+ */
26
+ contentPadding : CSSProperties [ 'padding' ] ;
27
+ /**
28
+ * @desc 折叠面板内容背景
29
+ * @descEN Background of content
30
+ */
31
+ contentBg : string ;
32
+ }
7
33
8
34
type CollapseToken = FullToken < 'Collapse' > & {
9
- collapseContentBg : string ;
10
- collapseHeaderBg : string ;
11
- collapseHeaderPadding : string ;
35
+ /**
36
+ * @desc 小号折叠面板头部内边距
37
+ * @descEN Padding of small header
38
+ */
39
+ collapseHeaderPaddingSM : string ;
40
+ /**
41
+ * @desc 大号折叠面板头部内边距
42
+ * @descEN Padding of large header
43
+ */
44
+ collapseHeaderPaddingLG : string ;
45
+ /**
46
+ * @desc 折叠面板边框圆角
47
+ * @descEN Border radius of collapse panel
48
+ */
12
49
collapsePanelBorderRadius : number ;
13
- collapseContentPaddingHorizontal : number ;
14
50
} ;
15
51
16
52
export const genBaseStyle : GenerateStyle < CollapseToken > = token => {
17
53
const {
18
54
componentCls,
19
- collapseContentBg ,
55
+ contentBg ,
20
56
padding,
21
- collapseContentPaddingHorizontal,
22
- collapseHeaderBg,
23
- collapseHeaderPadding,
57
+ headerBg,
58
+ headerPadding,
59
+ collapseHeaderPaddingSM,
60
+ collapseHeaderPaddingLG,
24
61
collapsePanelBorderRadius,
25
62
26
63
lineWidth,
@@ -29,35 +66,52 @@ export const genBaseStyle: GenerateStyle<CollapseToken> = token => {
29
66
colorText,
30
67
colorTextHeading,
31
68
colorTextDisabled,
32
- fontSize ,
69
+ fontSizeLG ,
33
70
lineHeight,
71
+ lineHeightLG,
34
72
marginSM,
35
73
paddingSM,
74
+ paddingLG,
75
+ paddingXS,
36
76
motionDurationSlow,
37
77
fontSizeIcon,
78
+ contentPadding,
79
+ fontHeight,
80
+ fontHeightLG,
38
81
} = token ;
39
82
40
- const borderBase = `${ lineWidth } px ${ lineType } ${ colorBorder } ` ;
83
+ const borderBase = `${ unit ( lineWidth ) } ${ lineType } ${ colorBorder } ` ;
41
84
42
85
return {
43
86
[ componentCls ] : {
44
87
...resetComponent ( token ) ,
45
- backgroundColor : collapseHeaderBg ,
88
+ backgroundColor : headerBg ,
46
89
border : borderBase ,
47
- borderBottom : 0 ,
48
- borderRadius : `${ collapsePanelBorderRadius } px` ,
90
+ borderRadius : collapsePanelBorderRadius ,
49
91
50
- [ ` &-rtl` ] : {
92
+ ' &-rtl' : {
51
93
direction : 'rtl' ,
52
94
} ,
53
95
54
96
[ `& > ${ componentCls } -item` ] : {
55
97
borderBottom : borderBase ,
56
- [ `&:last-child` ] : {
98
+ '&:first-child' : {
99
+ [ `
100
+ &,
101
+ & > ${ componentCls } -header` ] : {
102
+ borderRadius : `${ unit ( collapsePanelBorderRadius ) } ${ unit (
103
+ collapsePanelBorderRadius ,
104
+ ) } 0 0`,
105
+ } ,
106
+ } ,
107
+
108
+ '&:last-child' : {
57
109
[ `
58
110
&,
59
111
& > ${ componentCls } -header` ] : {
60
- borderRadius : `0 0 ${ collapsePanelBorderRadius } px ${ collapsePanelBorderRadius } px` ,
112
+ borderRadius : `0 0 ${ unit ( collapsePanelBorderRadius ) } ${ unit (
113
+ collapsePanelBorderRadius ,
114
+ ) } `,
61
115
} ,
62
116
} ,
63
117
@@ -66,23 +120,20 @@ export const genBaseStyle: GenerateStyle<CollapseToken> = token => {
66
120
display : 'flex' ,
67
121
flexWrap : 'nowrap' ,
68
122
alignItems : 'flex-start' ,
69
- padding : collapseHeaderPadding ,
123
+ padding : headerPadding ,
70
124
color : colorTextHeading ,
71
125
lineHeight,
72
126
cursor : 'pointer' ,
73
127
transition : `all ${ motionDurationSlow } , visibility 0s` ,
128
+ ...genFocusStyle ( token ) ,
74
129
75
130
[ `> ${ componentCls } -header-text` ] : {
76
131
flex : 'auto' ,
77
132
} ,
78
133
79
- '&:focus' : {
80
- outline : 'none' ,
81
- } ,
82
-
83
134
// >>>>> Arrow
84
135
[ `${ componentCls } -expand-icon` ] : {
85
- height : fontSize * lineHeight ,
136
+ height : fontHeight ,
86
137
display : 'flex' ,
87
138
alignItems : 'center' ,
88
139
paddingInlineEnd : marginSM ,
@@ -91,7 +142,9 @@ export const genBaseStyle: GenerateStyle<CollapseToken> = token => {
91
142
[ `${ componentCls } -arrow` ] : {
92
143
...resetIcon ( ) ,
93
144
fontSize : fontSizeIcon ,
94
-
145
+ // when `transform: rotate()` is applied to icon's root element
146
+ transition : `transform ${ motionDurationSlow } ` ,
147
+ // when `transform: rotate()` is applied to icon's child element
95
148
svg : {
96
149
transition : `transform ${ motionDurationSlow } ` ,
97
150
} ,
@@ -103,50 +156,79 @@ export const genBaseStyle: GenerateStyle<CollapseToken> = token => {
103
156
} ,
104
157
} ,
105
158
106
- [ `${ componentCls } -header- collapsible-only ` ] : {
159
+ [ `${ componentCls } -collapsible-header ` ] : {
107
160
cursor : 'default' ,
108
-
109
161
[ `${ componentCls } -header-text` ] : {
110
162
flex : 'none' ,
111
163
cursor : 'pointer' ,
112
164
} ,
113
- [ `${ componentCls } -expand-icon` ] : {
114
- cursor : 'pointer' ,
115
- } ,
116
165
} ,
117
166
118
- [ `${ componentCls } -icon- collapsible-only ` ] : {
119
- cursor : 'default ' ,
167
+ [ `${ componentCls } -collapsible-icon ` ] : {
168
+ cursor : 'unset ' ,
120
169
121
170
[ `${ componentCls } -expand-icon` ] : {
122
171
cursor : 'pointer' ,
123
172
} ,
124
173
} ,
125
-
126
- [ `&${ componentCls } -no-arrow` ] : {
127
- [ `> ${ componentCls } -header` ] : {
128
- paddingInlineStart : paddingSM ,
129
- } ,
130
- } ,
131
174
} ,
132
175
133
176
[ `${ componentCls } -content` ] : {
134
177
color : colorText ,
135
- backgroundColor : collapseContentBg ,
178
+ backgroundColor : contentBg ,
136
179
borderTop : borderBase ,
137
180
138
181
[ `& > ${ componentCls } -content-box` ] : {
139
- padding : ` ${ padding } px ${ collapseContentPaddingHorizontal } px` ,
182
+ padding : contentPadding ,
140
183
} ,
141
184
142
- [ ` &-hidden` ] : {
185
+ ' &-hidden' : {
143
186
display : 'none' ,
144
187
} ,
145
188
} ,
146
189
190
+ '&-small' : {
191
+ [ `> ${ componentCls } -item` ] : {
192
+ [ `> ${ componentCls } -header` ] : {
193
+ padding : collapseHeaderPaddingSM ,
194
+ paddingInlineStart : paddingXS ,
195
+
196
+ [ `> ${ componentCls } -expand-icon` ] : {
197
+ // Arrow offset
198
+ marginInlineStart : token . calc ( paddingSM ) . sub ( paddingXS ) . equal ( ) ,
199
+ } ,
200
+ } ,
201
+ [ `> ${ componentCls } -content > ${ componentCls } -content-box` ] : {
202
+ padding : paddingSM ,
203
+ } ,
204
+ } ,
205
+ } ,
206
+
207
+ '&-large' : {
208
+ [ `> ${ componentCls } -item` ] : {
209
+ fontSize : fontSizeLG ,
210
+ lineHeight : lineHeightLG ,
211
+ [ `> ${ componentCls } -header` ] : {
212
+ padding : collapseHeaderPaddingLG ,
213
+ paddingInlineStart : padding ,
214
+
215
+ [ `> ${ componentCls } -expand-icon` ] : {
216
+ height : fontHeightLG ,
217
+ // Arrow offset
218
+ marginInlineStart : token . calc ( paddingLG ) . sub ( padding ) . equal ( ) ,
219
+ } ,
220
+ } ,
221
+ [ `> ${ componentCls } -content > ${ componentCls } -content-box` ] : {
222
+ padding : paddingLG ,
223
+ } ,
224
+ } ,
225
+ } ,
226
+
147
227
[ `${ componentCls } -item:last-child` ] : {
228
+ borderBottom : 0 ,
229
+
148
230
[ `> ${ componentCls } -content` ] : {
149
- borderRadius : `0 0 ${ collapsePanelBorderRadius } px ${ collapsePanelBorderRadius } px ` ,
231
+ borderRadius : `0 0 ${ unit ( collapsePanelBorderRadius ) } ${ unit ( collapsePanelBorderRadius ) } ` ,
150
232
} ,
151
233
} ,
152
234
@@ -179,7 +261,7 @@ export const genBaseStyle: GenerateStyle<CollapseToken> = token => {
179
261
const genArrowStyle : GenerateStyle < CollapseToken > = token => {
180
262
const { componentCls } = token ;
181
263
182
- const fixedSelector = `> ${ componentCls } -item > ${ componentCls } -header ${ componentCls } -arrow svg ` ;
264
+ const fixedSelector = `> ${ componentCls } -item > ${ componentCls } -header ${ componentCls } -arrow` ;
183
265
184
266
return {
185
267
[ `${ componentCls } -rtl` ] : {
@@ -193,15 +275,15 @@ const genArrowStyle: GenerateStyle<CollapseToken> = token => {
193
275
const genBorderlessStyle : GenerateStyle < CollapseToken > = token => {
194
276
const {
195
277
componentCls,
196
- collapseHeaderBg ,
278
+ headerBg ,
197
279
paddingXXS,
198
280
199
281
colorBorder,
200
282
} = token ;
201
283
202
284
return {
203
285
[ `${ componentCls } -borderless` ] : {
204
- backgroundColor : collapseHeaderBg ,
286
+ backgroundColor : headerBg ,
205
287
border : 0 ,
206
288
207
289
[ `> ${ componentCls } -item` ] : {
@@ -252,20 +334,29 @@ const genGhostStyle: GenerateStyle<CollapseToken> = token => {
252
334
} ;
253
335
} ;
254
336
255
- export default genComponentStyleHook ( 'Collapse' , token => {
256
- const collapseToken = mergeToken < CollapseToken > ( token , {
257
- collapseContentBg : token . colorBgContainer ,
258
- collapseHeaderBg : token . colorFillAlter ,
259
- collapseHeaderPadding : `${ token . paddingSM } px ${ token . padding } px` ,
260
- collapsePanelBorderRadius : token . borderRadiusLG ,
261
- collapseContentPaddingHorizontal : 16 , // Fixed value
262
- } ) ;
263
-
264
- return [
265
- genBaseStyle ( collapseToken ) ,
266
- genBorderlessStyle ( collapseToken ) ,
267
- genGhostStyle ( collapseToken ) ,
268
- genArrowStyle ( collapseToken ) ,
269
- genCollapseMotion ( collapseToken ) ,
270
- ] ;
337
+ export const prepareComponentToken : GetDefaultToken < 'Collapse' > = token => ( {
338
+ headerPadding : `${ token . paddingSM } px ${ token . padding } px` ,
339
+ headerBg : token . colorFillAlter ,
340
+ contentPadding : `${ token . padding } px 16px` , // Fixed Value
341
+ contentBg : token . colorBgContainer ,
271
342
} ) ;
343
+
344
+ export default genStyleHooks (
345
+ 'Collapse' ,
346
+ token => {
347
+ const collapseToken = mergeToken < CollapseToken > ( token , {
348
+ collapseHeaderPaddingSM : `${ unit ( token . paddingXS ) } ${ unit ( token . paddingSM ) } ` ,
349
+ collapseHeaderPaddingLG : `${ unit ( token . padding ) } ${ unit ( token . paddingLG ) } ` ,
350
+ collapsePanelBorderRadius : token . borderRadiusLG ,
351
+ } ) ;
352
+
353
+ return [
354
+ genBaseStyle ( collapseToken ) ,
355
+ genBorderlessStyle ( collapseToken ) ,
356
+ genGhostStyle ( collapseToken ) ,
357
+ genArrowStyle ( collapseToken ) ,
358
+ genCollapseMotion ( collapseToken ) ,
359
+ ] ;
360
+ } ,
361
+ prepareComponentToken ,
362
+ ) ;
0 commit comments