Skip to content

Commit 3715ded

Browse files
authored
refactor:steps (#6264)
* refactor:steps * fix ...attrs * fix StepsToken error * docs:update & refactor: steps type
1 parent 04e3819 commit 3715ded

25 files changed

+1193
-1028
lines changed

components/steps/demo/progress.vue

+5
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,9 @@ Steps with progress.
2222
<a-step title="In Progress" sub-title="Left 00:00:08" description="This is a description." />
2323
<a-step title="Waiting" description="This is a description." />
2424
</a-steps>
25+
<a-steps :percent="60" :current="1" size="small">
26+
<a-step title="Finished" description="This is a description." />
27+
<a-step title="In Progress" sub-title="Left 00:00:08" description="This is a description." />
28+
<a-step title="Waiting" description="This is a description." />
29+
</a-steps>
2530
</template>

components/steps/index.en-US.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ category: Components
33
type: Navigation
44
cols: 1
55
title: Steps
6-
cover: https://gw.alipayobjects.com/zos/antfincdn/UZYqMizXHaj/Steps.svg
6+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*677sTqCpE3wAAAAAAAAAAAAADrJ8AQ/original
77
---
88

99
`Steps` is a navigation bar that guides users through the steps of a task.

components/steps/index.tsx

+34-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { App, ExtractPropTypes, PropType } from 'vue';
1+
import type { App, ExtractPropTypes } from 'vue';
22
import { computed, defineComponent } from 'vue';
33
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
44
import CheckOutlined from '@ant-design/icons-vue/CheckOutlined';
@@ -13,35 +13,40 @@ import omit from '../_util/omit';
1313
import { VcStepProps } from '../vc-steps/Step';
1414
import type { ProgressDotRender } from '../vc-steps/Steps';
1515
import type { MouseEventHandler } from '../_util/EventInterface';
16+
import { booleanType, stringType, functionType, someType } from '../_util/type';
17+
18+
// CSSINJS
19+
import useStyle from './style';
20+
import { useToken } from '../theme/internal';
1621

1722
export const stepsProps = () => ({
1823
prefixCls: String,
1924
iconPrefix: String,
2025
current: Number,
2126
initial: Number,
2227
percent: Number,
23-
responsive: { type: Boolean, default: undefined },
24-
labelPlacement: String as PropType<'horizontal' | 'vertical'>,
25-
status: String as PropType<'wait' | 'process' | 'finish' | 'error'>,
26-
size: String as PropType<'default' | 'small'>,
27-
direction: String as PropType<'horizontal' | 'vertical'>,
28-
progressDot: {
29-
type: [Boolean, Function] as PropType<boolean | ProgressDotRender>,
30-
default: undefined as boolean | ProgressDotRender,
31-
},
32-
type: String as PropType<'default' | 'navigation'>,
33-
onChange: Function as PropType<(current: number) => void>,
34-
'onUpdate:current': Function as PropType<(current: number) => void>,
28+
responsive: booleanType(),
29+
labelPlacement: stringType<'horizontal' | 'vertical'>(),
30+
status: stringType<'wait' | 'process' | 'finish' | 'error'>(),
31+
size: stringType<'default' | 'small'>(),
32+
direction: stringType<'horizontal' | 'vertical'>(),
33+
progressDot: someType<boolean | ProgressDotRender>(
34+
[Boolean, Function],
35+
undefined as boolean | ProgressDotRender,
36+
),
37+
type: stringType<'default' | 'navigation'>(),
38+
onChange: functionType<(current: number) => void>(),
39+
'onUpdate:current': functionType<(current: number) => void>(),
3540
});
3641

3742
export const stepProps = () => ({
3843
description: PropTypes.any,
3944
icon: PropTypes.any,
40-
status: String as PropType<'wait' | 'process' | 'finish' | 'error'>,
41-
disabled: { type: Boolean, default: undefined },
45+
status: stringType<'wait' | 'process' | 'finish' | 'error'>(),
46+
disabled: booleanType(),
4247
title: PropTypes.any,
4348
subTitle: PropTypes.any,
44-
onClick: Function as PropType<MouseEventHandler>,
49+
onClick: functionType<MouseEventHandler>(),
4550
});
4651

4752
export type StepsProps = Partial<ExtractPropTypes<ReturnType<typeof stepsProps>>>;
@@ -61,6 +66,13 @@ const Steps = defineComponent({
6166
// emits: ['update:current', 'change'],
6267
setup(props, { attrs, slots, emit }) {
6368
const { prefixCls, direction: rtlDirection, configProvider } = useConfigInject('steps', props);
69+
70+
// 接入换肤
71+
const [, token] = useToken();
72+
73+
// style
74+
const [wrapSSR, hashId] = useStyle(prefixCls);
75+
6476
const screens = useBreakpoint();
6577
const direction = computed(() =>
6678
props.responsive && screens.value.xs ? 'vertical' : props.direction,
@@ -84,11 +96,12 @@ const Steps = defineComponent({
8496
// currently it's hard-coded, since we can't easily read the actually width of icon
8597
const progressWidth = props.size === 'small' ? 32 : 40;
8698
const iconWithProgress = (
87-
<div class={`${prefixCls}-progress-icon`}>
99+
<div class={`${prefixCls.value}-progress-icon`}>
88100
<Progress
89101
type="circle"
90102
percent={props.percent}
91103
width={progressWidth}
104+
strokeColor={token.value.colorPrimary}
92105
strokeWidth={4}
93106
format={() => null}
94107
/>
@@ -106,22 +119,24 @@ const Steps = defineComponent({
106119
[`${prefixCls.value}-with-progress`]: props.percent !== undefined,
107120
},
108121
attrs.class,
122+
hashId.value,
109123
);
110124
const icons = {
111125
finish: <CheckOutlined class={`${prefixCls}-finish-icon`} />,
112126
error: <CloseOutlined class={`${prefixCls}-error-icon`} />,
113127
};
114-
return (
128+
return wrapSSR(
115129
<VcSteps
116130
icons={icons}
131+
{...attrs}
117132
{...omit(props, ['percent', 'responsive'])}
118133
direction={direction.value}
119134
prefixCls={prefixCls.value}
120135
iconPrefix={iconPrefix.value}
121136
class={stepsClassName}
122137
onChange={handleChange}
123138
v-slots={{ ...slots, stepIcon: stepIconRender }}
124-
/>
139+
/>,
125140
);
126141
};
127142
},

components/steps/index.zh-CN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ subtitle: 步骤条
44
type: 导航
55
cols: 1
66
title: Steps
7-
cover: https://gw.alipayobjects.com/zos/antfincdn/UZYqMizXHaj/Steps.svg
7+
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*677sTqCpE3wAAAAAAAAAAAAADrJ8AQ/original
88
---
99

1010
引导用户按照流程完成任务的导航条。

components/steps/style/custom-icon.less

-32
This file was deleted.

components/steps/style/custom-icon.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { CSSObject } from '../../_util/cssinjs';
2+
import type { StepsToken } from '.';
3+
import type { GenerateStyle } from '../../theme/internal';
4+
5+
const genStepsCustomIconStyle: GenerateStyle<StepsToken, CSSObject> = token => {
6+
const { componentCls, stepsIconCustomTop, stepsIconCustomSize, stepsIconCustomFontSize } = token;
7+
8+
return {
9+
[`${componentCls}-item-custom`]: {
10+
[`> ${componentCls}-item-container > ${componentCls}-item-icon`]: {
11+
height: 'auto',
12+
background: 'none',
13+
border: 0,
14+
[`> ${componentCls}-icon`]: {
15+
top: stepsIconCustomTop,
16+
width: stepsIconCustomSize,
17+
height: stepsIconCustomSize,
18+
fontSize: stepsIconCustomFontSize,
19+
lineHeight: `${stepsIconCustomSize}px`,
20+
},
21+
},
22+
},
23+
24+
// Only adjust horizontal customize icon width
25+
[`&:not(${componentCls}-vertical)`]: {
26+
[`${componentCls}-item-custom`]: {
27+
[`${componentCls}-item-icon`]: {
28+
width: 'auto',
29+
background: 'none',
30+
},
31+
},
32+
},
33+
};
34+
};
35+
36+
export default genStepsCustomIconStyle;

0 commit comments

Comments
 (0)