Skip to content

Commit 1a789f1

Browse files
authored
refactor(cssinjs): simplify transition style generation (ant-design#56826)
* chore: code optimization * update
1 parent 45d8f9a commit 1a789f1

24 files changed

Lines changed: 138 additions & 97 deletions

File tree

components/_util/wave/style.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ export interface ComponentToken {}
88
export interface WaveToken extends FullToken<'Wave'> {}
99

1010
const genWaveStyle: GenerateStyle<WaveToken> = (token) => {
11-
const { componentCls, colorPrimary, antCls } = token;
11+
const {
12+
componentCls,
13+
colorPrimary,
14+
motionDurationSlow,
15+
motionEaseInOut,
16+
motionEaseOutCirc,
17+
antCls,
18+
} = token;
1219
const [, varRef] = genCssVar(antCls, 'wave');
1320
return {
1421
[componentCls]: {
@@ -22,20 +29,18 @@ const genWaveStyle: GenerateStyle<WaveToken> = (token) => {
2229

2330
// =================== Motion ===================
2431
'&.wave-motion-appear': {
25-
transition: [
26-
`box-shadow 0.4s ${token.motionEaseOutCirc}`,
27-
`opacity 2s ${token.motionEaseOutCirc}`,
28-
].join(','),
32+
transition: [`box-shadow 0.4s`, `opacity 2s`]
33+
.map((prop) => `${prop} ${motionEaseOutCirc}`)
34+
.join(','),
2935

3036
'&-active': {
3137
boxShadow: `0 0 0 6px currentcolor`,
3238
opacity: 0,
3339
},
3440
'&.wave-quick': {
35-
transition: [
36-
`box-shadow ${token.motionDurationSlow} ${token.motionEaseInOut}`,
37-
`opacity ${token.motionDurationSlow} ${token.motionEaseInOut}`,
38-
].join(','),
41+
transition: [`box-shadow`, `opacity`]
42+
.map((prop) => `${prop} ${motionDurationSlow} ${motionEaseInOut}`)
43+
.join(','),
3944
},
4045
},
4146
},

components/alert/style/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ export const genBaseStyle: GenerateStyle<AlertToken> = (token: AlertToken): CSSO
9898
[`&${componentCls}-motion-leave`]: {
9999
overflow: 'hidden',
100100
opacity: 1,
101-
transition: `max-height ${duration} ${motionEaseInOutCirc}, opacity ${duration} ${motionEaseInOutCirc},
102-
padding-top ${duration} ${motionEaseInOutCirc}, padding-bottom ${duration} ${motionEaseInOutCirc},
103-
margin-bottom ${duration} ${motionEaseInOutCirc}`,
101+
transition: [`max-height`, `opacity`, `padding-top`, `padding-bottom`, `margin-bottom`]
102+
.map((prop) => `${prop} ${duration} ${motionEaseInOutCirc}`)
103+
.join(', '),
104104
},
105105

106106
[`&${componentCls}-motion-leave-active`]: {

components/anchor/style/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ const genSharedAnchorHorizontalStyle: GenerateStyle<AnchorToken> = (token) => {
170170
[`${componentCls}-ink`]: {
171171
position: 'absolute',
172172
bottom: 0,
173-
transition: `left ${motionDurationSlow} ease-in-out, width ${motionDurationSlow} ease-in-out`,
173+
transition: [`left`, `width`]
174+
.map((prop) => `${prop} ${motionDurationSlow} ease-in-out`)
175+
.join(', '),
174176
height: lineWidthBold,
175177
backgroundColor: colorPrimary,
176178
},

components/card/style/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ const genCardStyle: GenerateStyle<CardToken> = (token): CSSObject => {
315315
boxShadowTertiary,
316316
bodyPadding,
317317
extraColor,
318+
motionDurationMid,
318319
} = token;
319320

320321
return {
@@ -379,7 +380,9 @@ const genCardStyle: GenerateStyle<CardToken> = (token): CSSObject => {
379380

380381
[`${componentCls}-hoverable`]: {
381382
cursor: 'pointer',
382-
transition: `box-shadow ${token.motionDurationMid}, border-color ${token.motionDurationMid}`,
383+
transition: [`box-shadow`, `border-color`]
384+
.map((prop) => `${prop} ${motionDurationMid}`)
385+
.join(', '),
383386

384387
'&:hover': {
385388
borderColor: 'transparent',

components/date-picker/style/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ const genPickerStyle: GenerateStyle<PickerToken> = (token) => {
101101
alignItems: 'center',
102102
lineHeight: 1,
103103
borderRadius,
104-
transition: `border ${motionDurationMid}, box-shadow ${motionDurationMid}, background ${motionDurationMid}`,
104+
transition: [`border`, `box-shadow`, `background-color`]
105+
.map((prop) => `${prop} ${motionDurationMid}`)
106+
.join(', '),
105107

106108
[`${componentCls}-prefix`]: {
107109
flex: '0 0 auto',

components/date-picker/style/util.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ export const genOverflowStyle = (
116116
marginBlock: INTERNAL_FIXED_ITEM_MARGIN,
117117
borderRadius: borderRadiusSM,
118118
cursor: 'default',
119-
transition: `font-size ${motionDurationSlow}, line-height ${motionDurationSlow}, height ${motionDurationSlow}`,
119+
transition: [`font-size`, `line-height`, `height`]
120+
.map((prop) => `${prop} ${motionDurationSlow}`)
121+
.join(', '),
120122
marginInlineEnd: token.calc(INTERNAL_FIXED_ITEM_MARGIN).mul(2).equal(),
121123
paddingInlineStart: paddingXS,
122124
paddingInlineEnd: token.calc(paddingXS).div(2).equal(),

components/form/style/explain.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import type { FormToken } from '.';
22
import type { GenerateStyle } from '../../theme/internal';
33

44
const genFormValidateMotionStyle: GenerateStyle<FormToken> = (token) => {
5-
const { componentCls } = token;
5+
const { componentCls, motionDurationFast, motionEaseInOut } = token;
66

77
const helpCls = `${componentCls}-show-help`;
88
const helpItemCls = `${componentCls}-show-help-item`;
99

1010
return {
1111
[helpCls]: {
1212
// Explain holder
13-
transition: `opacity ${token.motionDurationFast} ${token.motionEaseInOut}`,
13+
transition: `opacity ${motionDurationFast} ${motionEaseInOut}`,
1414

1515
'&-appear, &-enter': {
1616
opacity: 0,
@@ -31,9 +31,9 @@ const genFormValidateMotionStyle: GenerateStyle<FormToken> = (token) => {
3131
// Explain
3232
[helpItemCls]: {
3333
overflow: 'hidden',
34-
transition: `height ${token.motionDurationFast} ${token.motionEaseInOut},
35-
opacity ${token.motionDurationFast} ${token.motionEaseInOut},
36-
transform ${token.motionDurationFast} ${token.motionEaseInOut} !important`,
34+
transition: `${['height', 'opacity', 'transform']
35+
.map((prop) => `${prop} ${motionDurationFast} ${motionEaseInOut}`)
36+
.join(', ')} !important`,
3737

3838
[`&${helpItemCls}-appear, &${helpItemCls}-enter`]: {
3939
transform: `translateY(-5px)`,

components/menu/style/horizontal.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ const getHorizontalStyle: GenerateStyle<MenuToken> = (token) => {
4343
},
4444

4545
[`${componentCls}-item, ${componentCls}-submenu-title`]: {
46-
transition: [
47-
`border-color ${motionDurationSlow}`,
48-
`background-color ${motionDurationSlow}`,
49-
].join(','),
46+
transition: [`border-color`, `background-color`]
47+
.map((prop) => `${prop} ${motionDurationSlow}`)
48+
.join(','),
5049
},
5150

5251
// ===================== Sub Menu =====================

components/menu/style/index.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,9 @@ const genSubMenuArrowStyle = (token: MenuToken): CSSObject => {
516516
height: token.calc(menuArrowSize).mul(0.15).equal(),
517517
backgroundColor: 'currentcolor',
518518
borderRadius,
519-
transition: [
520-
`background-color ${motionDurationSlow} ${motionEaseInOut}`,
521-
`transform ${motionDurationSlow} ${motionEaseInOut}`,
522-
`top ${motionDurationSlow} ${motionEaseInOut}`,
523-
`color ${motionDurationSlow} ${motionEaseInOut}`,
524-
].join(','),
519+
transition: [`background-color`, `transform`, `top`, `color`]
520+
.map((prop) => `${prop} ${motionDurationSlow} ${motionEaseInOut}`)
521+
.join(','),
525522
content: '""',
526523
},
527524

@@ -619,10 +616,9 @@ const getBaseStyle: GenerateStyle<MenuToken> = (token) => {
619616
},
620617

621618
[`&-horizontal ${componentCls}-submenu`]: {
622-
transition: [
623-
`border-color ${motionDurationSlow} ${motionEaseInOut}`,
624-
`background-color ${motionDurationSlow} ${motionEaseInOut}`,
625-
].join(','),
619+
transition: [`border-color`, `background-color`]
620+
.map((prop) => `${prop} ${motionDurationSlow} ${motionEaseInOut}`)
621+
.join(','),
626622
},
627623

628624
[`${componentCls}-submenu, ${componentCls}-submenu-inline`]: {
@@ -635,10 +631,9 @@ const getBaseStyle: GenerateStyle<MenuToken> = (token) => {
635631

636632
[`${componentCls}-submenu ${componentCls}-sub`]: {
637633
cursor: 'initial',
638-
transition: [
639-
`background-color ${motionDurationSlow} ${motionEaseInOut}`,
640-
`padding ${motionDurationSlow} ${motionEaseInOut}`,
641-
].join(','),
634+
transition: [`background-color`, `padding`]
635+
.map((prop) => `${prop} ${motionDurationSlow} ${motionEaseInOut}`)
636+
.join(','),
642637
},
643638

644639
[`${componentCls}-title-content`]: {

components/menu/style/theme.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,9 @@ const getThemeStyle = (token: MenuToken, themeSuffix: string): CSSInterpolation
239239
borderInlineEnd: `${unit(activeBarWidth)} solid ${itemSelectedColor}`,
240240
transform: 'scaleY(0.0001)',
241241
opacity: 0,
242-
transition: [
243-
`transform ${motionDurationMid} ${motionEaseOut}`,
244-
`opacity ${motionDurationMid} ${motionEaseOut}`,
245-
].join(','),
242+
transition: [`transform`, `opacity`]
243+
.map((prop) => `${prop} ${motionDurationMid} ${motionEaseOut}`)
244+
.join(','),
246245
content: '""',
247246
},
248247

@@ -258,10 +257,9 @@ const getThemeStyle = (token: MenuToken, themeSuffix: string): CSSInterpolation
258257
'&::after': {
259258
transform: 'scaleY(1)',
260259
opacity: 1,
261-
transition: [
262-
`transform ${motionDurationMid} ${motionEaseInOut}`,
263-
`opacity ${motionDurationMid} ${motionEaseInOut}`,
264-
].join(','),
260+
transition: [`transform`, `opacity`]
261+
.map((prop) => `${prop} ${motionDurationMid} ${motionEaseInOut}`)
262+
.join(','),
265263
},
266264
},
267265
},

0 commit comments

Comments
 (0)