@@ -12,18 +12,14 @@ function isString(str: any): str is string {
12
12
export interface StepProps {
13
13
// style
14
14
prefixCls ?: string ;
15
- className ?: string ;
16
- style ?: React . CSSProperties ;
17
15
classNames : StepsProps [ 'classNames' ] ;
18
16
styles : StepsProps [ 'styles' ] ;
19
17
20
18
// data
21
19
data : StepItem ;
22
- status : Status ;
23
20
prevStatus ?: Status ;
24
21
25
22
active ?: boolean ;
26
- disabled ?: boolean ;
27
23
index : number ;
28
24
29
25
// stepIndex?: number;
@@ -36,7 +32,7 @@ export interface StepProps {
36
32
iconRender ?: StepsProps [ 'iconRender' ] ;
37
33
icon ?: React . ReactNode ;
38
34
progressDot ?: ProgressDotRender | boolean ;
39
- render ?: ( stepItem : React . ReactElement ) => React . ReactNode ;
35
+ itemRender ?: ( stepItem : React . ReactElement ) => React . ReactNode ;
40
36
41
37
// Event
42
38
onClick ?: ( index : number ) => void ;
@@ -46,33 +42,40 @@ export default function Step(props: StepProps) {
46
42
const {
47
43
// style
48
44
prefixCls,
49
- className,
50
- style,
51
45
classNames,
52
46
styles,
53
47
54
48
// data
55
49
data,
56
- status,
57
50
prevStatus,
58
51
59
52
active,
60
- disabled,
61
53
index,
62
54
63
55
// render
64
- icon,
65
56
progressDot,
66
- render,
57
+ itemRender,
58
+ iconRender,
67
59
68
60
// events
69
61
onClick,
70
-
71
- ...restProps
72
62
} = props ;
73
63
74
64
// ========================== Data ==========================
75
- const { onClick : onItemClick , title, subTitle, content, description } = data ;
65
+ const {
66
+ onClick : onItemClick ,
67
+ title,
68
+ subTitle,
69
+ content,
70
+ description,
71
+ disabled,
72
+ icon,
73
+ status,
74
+
75
+ className,
76
+ style,
77
+ ...restItemProps
78
+ } = data ;
76
79
const mergedContent = content ?? description ;
77
80
78
81
// ========================= Click ==========================
@@ -102,74 +105,37 @@ export default function Step(props: StepProps) {
102
105
}
103
106
104
107
// ========================= Render =========================
105
- const renderIconNode = ( ) => {
106
- let iconNode : React . ReactNode ;
107
- const iconClassName = cls ( `${ prefixCls } -icon` , `${ iconPrefix } icon` , {
108
- [ `${ iconPrefix } icon-${ icon } ` ] : icon && isString ( icon ) ,
109
- [ `${ iconPrefix } icon-check` ] :
110
- ! icon && status === 'finish' && ( ( icons && ! icons . finish ) || ! icons ) ,
111
- [ `${ iconPrefix } icon-cross` ] :
112
- ! icon && status === 'error' && ( ( icons && ! icons . error ) || ! icons ) ,
113
- } ) ;
114
- const iconDot = < span className = { `${ prefixCls } -icon-dot` } /> ;
115
- // `progressDot` enjoy the highest priority
116
- if ( progressDot ) {
117
- if ( typeof progressDot === 'function' ) {
118
- iconNode = (
119
- < span className = { `${ prefixCls } -icon` } >
120
- { progressDot ( iconDot , {
121
- index : stepNumber - 1 ,
122
- status,
123
- title,
124
- description,
125
- content : mergedContent ,
126
- } ) }
127
- </ span >
128
- ) ;
129
- } else {
130
- iconNode = < span className = { `${ prefixCls } -icon` } > { iconDot } </ span > ;
131
- }
132
- } else if ( icon && ! isString ( icon ) ) {
133
- iconNode = < span className = { `${ prefixCls } -icon` } > { icon } </ span > ;
134
- } else if ( icons && icons . finish && status === 'finish' ) {
135
- iconNode = < span className = { `${ prefixCls } -icon` } > { icons . finish } </ span > ;
136
- } else if ( icons && icons . error && status === 'error' ) {
137
- iconNode = < span className = { `${ prefixCls } -icon` } > { icons . error } </ span > ;
138
- } else if ( icon || status === 'finish' || status === 'error' ) {
139
- iconNode = < span className = { iconClassName } /> ;
140
- } else {
141
- iconNode = < span className = { `${ prefixCls } -icon` } > { stepNumber } </ span > ;
142
- }
143
-
144
- if ( stepIcon ) {
145
- iconNode = stepIcon ( {
146
- index,
147
- status,
148
- title,
149
- description,
150
- content : mergedContent ,
151
- node : iconNode ,
152
- } ) ;
153
- }
154
-
155
- return iconNode ;
156
- } ;
157
-
158
108
const mergedStatus = status || 'wait' ;
159
109
160
- const classString = cls ( `${ prefixCls } -item` , `${ prefixCls } -item-${ mergedStatus } ` , className , {
161
- [ `${ prefixCls } -item-custom` ] : icon ,
162
- [ `${ prefixCls } -item-active` ] : active ,
163
- [ `${ prefixCls } -item-disabled` ] : disabled === true ,
164
- } ) ;
165
-
166
- const stepItemStyle : React . CSSProperties = { ...style } ;
110
+ const classString = cls (
111
+ `${ prefixCls } -item` ,
112
+ `${ prefixCls } -item-${ mergedStatus } ` ,
113
+ {
114
+ [ `${ prefixCls } -item-custom` ] : icon ,
115
+ [ `${ prefixCls } -item-active` ] : active ,
116
+ [ `${ prefixCls } -item-disabled` ] : disabled === true ,
117
+ } ,
118
+ className ,
119
+ classNames . item ,
120
+ ) ;
167
121
168
122
let stepNode : React . ReactNode = (
169
- < div { ...restProps } className = { classString } style = { stepItemStyle } >
170
- < div onClick = { onClick } { ...accessibilityProps } className = { `${ prefixCls } -item-container` } >
123
+ < div
124
+ { ...restItemProps }
125
+ className = { classString }
126
+ style = { {
127
+ ...styles . item ,
128
+ ...style ,
129
+ } }
130
+ >
131
+ < div { ...accessibilityProps } className = { `${ prefixCls } -item-container` } >
171
132
< div className = { `${ prefixCls } -item-tail` } />
172
- < div className = { `${ prefixCls } -item-icon` } > { renderIconNode ( ) } </ div >
133
+ < div className = { `${ prefixCls } -item-icon` } >
134
+ { iconRender ( data , {
135
+ index,
136
+ active,
137
+ } ) }
138
+ </ div >
173
139
< div className = { `${ prefixCls } -item-content` } >
174
140
< div className = { `${ prefixCls } -item-title` } >
175
141
{ title }
@@ -188,8 +154,8 @@ export default function Step(props: StepProps) {
188
154
</ div >
189
155
) ;
190
156
191
- if ( render ) {
192
- stepNode = ( render ( stepNode ) || null ) as React . ReactElement ;
157
+ if ( itemRender ) {
158
+ stepNode = ( itemRender ( stepNode ) || null ) as React . ReactElement ;
193
159
}
194
160
195
161
return stepNode ;
0 commit comments