-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
/
Copy pathindex.tsx
159 lines (149 loc) · 4.98 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
import type { App, ExtractPropTypes } from 'vue';
import { computed, defineComponent } from 'vue';
import CloseOutlined from '@ant-design/icons-vue/CloseOutlined';
import CheckOutlined from '@ant-design/icons-vue/CheckOutlined';
import PropTypes from '../_util/vue-types';
import initDefaultProps from '../_util/props-util/initDefaultProps';
import VcSteps, { Step as VcStep } from '../vc-steps';
import useConfigInject from '../config-provider/hooks/useConfigInject';
import useBreakpoint from '../_util/hooks/useBreakpoint';
import classNames from '../_util/classNames';
import Progress from '../progress';
import omit from '../_util/omit';
import { VcStepProps } from '../vc-steps/Step';
import type { ProgressDotRender } from '../vc-steps/Steps';
import type { MouseEventHandler } from '../_util/EventInterface';
import { booleanType, stringType, functionType, someType } from '../_util/type';
// CSSINJS
import useStyle from './style';
import { useToken } from '../theme/internal';
export const stepsProps = () => ({
prefixCls: String,
iconPrefix: String,
current: Number,
initial: Number,
percent: Number,
responsive: booleanType(),
labelPlacement: stringType<'horizontal' | 'vertical'>(),
status: stringType<'wait' | 'process' | 'finish' | 'error'>(),
size: stringType<'default' | 'small'>(),
direction: stringType<'horizontal' | 'vertical'>(),
progressDot: someType<boolean | ProgressDotRender>(
[Boolean, Function],
undefined as boolean | ProgressDotRender,
),
type: stringType<'default' | 'navigation'>(),
onChange: functionType<(current: number) => void>(),
'onUpdate:current': functionType<(current: number) => void>(),
});
export const stepProps = () => ({
description: PropTypes.any,
icon: PropTypes.any,
status: stringType<'wait' | 'process' | 'finish' | 'error'>(),
disabled: booleanType(),
title: PropTypes.any,
subTitle: PropTypes.any,
onClick: functionType<MouseEventHandler>(),
});
export type StepsProps = Partial<ExtractPropTypes<ReturnType<typeof stepsProps>>>;
export type StepProps = Partial<ExtractPropTypes<ReturnType<typeof stepProps>>>;
const Steps = defineComponent({
compatConfig: { MODE: 3 },
name: 'ASteps',
inheritAttrs: false,
props: initDefaultProps(stepsProps(), {
current: 0,
responsive: true,
labelPlacement: 'horizontal',
}),
slots: ['progressDot'],
// emits: ['update:current', 'change'],
setup(props, { attrs, slots, emit }) {
const { prefixCls, direction: rtlDirection, configProvider } = useConfigInject('steps', props);
// 接入换肤
const [, token] = useToken();
// style
const [wrapSSR, hashId] = useStyle(prefixCls);
const screens = useBreakpoint();
const direction = computed(() =>
props.responsive && screens.value.xs ? 'vertical' : props.direction,
);
const iconPrefix = computed(() => configProvider.getPrefixCls('', props.iconPrefix));
const handleChange = (current: number) => {
emit('update:current', current);
emit('change', current);
};
const stepIconRender = ({
node,
status,
}: {
node: any;
index: number;
status: string;
title: any;
description: any;
}) => {
if (status === 'process' && props.percent !== undefined) {
// currently it's hard-coded, since we can't easily read the actually width of icon
const progressWidth = props.size === 'small' ? 32 : 40;
const iconWithProgress = (
<div class={`${prefixCls.value}-progress-icon`}>
<Progress
type="circle"
percent={props.percent}
width={progressWidth}
strokeColor={token.value.colorPrimary}
strokeWidth={4}
format={() => null}
/>
{node}
</div>
);
return iconWithProgress;
}
return node;
};
return () => {
const stepsClassName = classNames(
{
[`${prefixCls.value}-rtl`]: rtlDirection.value === 'rtl',
[`${prefixCls.value}-with-progress`]: props.percent !== undefined,
},
attrs.class,
hashId.value,
);
const icons = {
finish: <CheckOutlined class={`${prefixCls}-finish-icon`} />,
error: <CloseOutlined class={`${prefixCls}-error-icon`} />,
};
return wrapSSR(
<VcSteps
icons={icons}
{...attrs}
{...omit(props, ['percent', 'responsive'])}
direction={direction.value}
prefixCls={prefixCls.value}
iconPrefix={iconPrefix.value}
class={stepsClassName}
onChange={handleChange}
v-slots={{ ...slots, stepIcon: stepIconRender }}
/>,
);
};
},
});
/* istanbul ignore next */
export const Step = defineComponent({
compatConfig: { MODE: 3 },
...VcStep,
name: 'AStep',
props: VcStepProps(),
});
export default Object.assign(Steps, {
Step,
install: (app: App) => {
app.component(Steps.name, Steps);
app.component(Step.name, Step);
return app;
},
});