@@ -4,6 +4,12 @@ import cls from 'classnames';
4
4
import KeyCode from '@rc-component/util/lib/KeyCode' ;
5
5
import type { Status , StepItem , StepsProps } from './Steps' ;
6
6
import Rail from './Rail' ;
7
+ import { UnstableContext } from './UnstableContext' ;
8
+ import StepIcon , { StepIconSemanticContext } from './StepIcon' ;
9
+
10
+ function hasContent < T > ( value : T ) {
11
+ return value !== undefined && value !== null ;
12
+ }
7
13
8
14
export interface StepProps {
9
15
// style
@@ -18,12 +24,6 @@ export interface StepProps {
18
24
index : number ;
19
25
last : boolean ;
20
26
21
- // stepIndex?: number;
22
- // stepNumber?: number;
23
- // title?: React.ReactNode;
24
- // subTitle?: React.ReactNode;
25
- // description?: React.ReactNode;
26
-
27
27
// render
28
28
iconRender ?: StepsProps [ 'iconRender' ] ;
29
29
icon ?: React . ReactNode ;
@@ -59,6 +59,9 @@ export default function Step(props: StepProps) {
59
59
60
60
const itemCls = `${ prefixCls } -item` ;
61
61
62
+ // ==================== Internal Context ====================
63
+ const { railFollowPrevStatus } = React . useContext ( UnstableContext ) ;
64
+
62
65
// ========================== Data ==========================
63
66
const {
64
67
onClick : onItemClick ,
@@ -72,6 +75,9 @@ export default function Step(props: StepProps) {
72
75
73
76
className,
74
77
style,
78
+ classNames : itemClassNames = { } ,
79
+ styles : itemStyles = { } ,
80
+
75
81
...restItemProps
76
82
} = data ;
77
83
@@ -92,8 +98,8 @@ export default function Step(props: StepProps) {
92
98
const accessibilityProps : {
93
99
role ?: string ;
94
100
tabIndex ?: number ;
95
- onClick ?: React . MouseEventHandler < HTMLDivElement > ;
96
- onKeyDown ?: React . KeyboardEventHandler < HTMLDivElement > ;
101
+ onClick ?: React . MouseEventHandler < HTMLLIElement > ;
102
+ onKeyDown ?: React . KeyboardEventHandler < HTMLLIElement > ;
97
103
} = { } ;
98
104
99
105
if ( clickable ) {
@@ -115,46 +121,109 @@ export default function Step(props: StepProps) {
115
121
// ========================= Render =========================
116
122
const mergedStatus = status || 'wait' ;
117
123
124
+ const hasTitle = hasContent ( title ) ;
125
+ const hasSubTitle = hasContent ( subTitle ) ;
126
+
118
127
const classString = cls (
119
128
itemCls ,
120
129
`${ itemCls } -${ mergedStatus } ` ,
121
130
{
122
131
[ `${ itemCls } -custom` ] : icon ,
123
132
[ `${ itemCls } -active` ] : active ,
124
133
[ `${ itemCls } -disabled` ] : disabled === true ,
134
+ [ `${ itemCls } -empty-header` ] : ! hasTitle && ! hasSubTitle ,
125
135
} ,
126
136
className ,
127
137
classNames . item ,
138
+ itemClassNames . root ,
128
139
) ;
129
140
141
+ let iconNode = < StepIcon /> ;
142
+ if ( iconRender ) {
143
+ iconNode = iconRender ( iconNode , {
144
+ ...renderInfo ,
145
+ components : {
146
+ Icon : StepIcon ,
147
+ } ,
148
+ } ) as React . ReactElement ;
149
+ }
150
+
130
151
const wrapperNode = (
131
- < div className = { cls ( `${ itemCls } -wrapper` , classNames . itemWrapper ) } style = { styles . itemWrapper } >
132
- < div className = { cls ( `${ itemCls } -icon` , classNames . itemIcon ) } style = { styles . itemIcon } >
133
- { iconRender ?.( renderInfo ) }
134
- </ div >
135
- < div className = { cls ( `${ itemCls } -section` , classNames . itemSection ) } style = { styles . itemSection } >
136
- < div className = { cls ( `${ itemCls } -header` , classNames . itemHeader ) } style = { styles . itemHeader } >
137
- < div className = { cls ( `${ itemCls } -title` , classNames . itemTitle ) } style = { styles . itemTitle } >
138
- { title }
139
- </ div >
140
- { subTitle && (
152
+ < div
153
+ className = { cls ( `${ itemCls } -wrapper` , classNames . itemWrapper , itemClassNames . wrapper ) }
154
+ style = { {
155
+ ...styles . itemWrapper ,
156
+ ...itemStyles . wrapper ,
157
+ } }
158
+ >
159
+ { /* Icon */ }
160
+ < StepIconSemanticContext . Provider
161
+ value = { {
162
+ className : itemClassNames . icon ,
163
+ style : itemStyles . icon ,
164
+ } }
165
+ >
166
+ { iconNode }
167
+ </ StepIconSemanticContext . Provider >
168
+
169
+ < div
170
+ className = { cls ( `${ itemCls } -section` , classNames . itemSection , itemClassNames . section ) }
171
+ style = { {
172
+ ...styles . itemSection ,
173
+ ...itemStyles . section ,
174
+ } }
175
+ >
176
+ < div
177
+ className = { cls ( `${ itemCls } -header` , classNames . itemHeader , itemClassNames . header ) }
178
+ style = { {
179
+ ...styles . itemHeader ,
180
+ ...itemStyles . header ,
181
+ } }
182
+ >
183
+ { hasTitle && (
184
+ < div
185
+ className = { cls ( `${ itemCls } -title` , classNames . itemTitle , itemClassNames . title ) }
186
+ style = { {
187
+ ...styles . itemTitle ,
188
+ ...itemStyles . title ,
189
+ } }
190
+ >
191
+ { title }
192
+ </ div >
193
+ ) }
194
+ { hasSubTitle && (
141
195
< div
142
196
title = { typeof subTitle === 'string' ? subTitle : undefined }
143
- className = { cls ( `${ itemCls } -subtitle` , classNames . itemSubtitle ) }
144
- style = { styles . itemSubtitle }
197
+ className = { cls (
198
+ `${ itemCls } -subtitle` ,
199
+ classNames . itemSubtitle ,
200
+ itemClassNames . subtitle ,
201
+ ) }
202
+ style = { {
203
+ ...styles . itemSubtitle ,
204
+ ...itemStyles . subtitle ,
205
+ } }
145
206
>
146
207
{ subTitle }
147
208
</ div >
148
209
) }
149
210
150
211
{ ! last && (
151
- < Rail prefixCls = { itemCls } classNames = { classNames } styles = { styles } status = { nextStatus } />
212
+ < Rail
213
+ prefixCls = { itemCls }
214
+ className = { cls ( classNames . itemRail , itemClassNames . rail ) }
215
+ style = { {
216
+ ...styles . itemRail ,
217
+ ...itemStyles . rail ,
218
+ } }
219
+ status = { railFollowPrevStatus ? status : nextStatus }
220
+ />
152
221
) }
153
222
</ div >
154
- { mergedContent && (
223
+ { hasContent ( mergedContent ) && (
155
224
< div
156
- className = { cls ( `${ itemCls } -content` , classNames . itemContent ) }
157
- style = { styles . itemContent }
225
+ className = { cls ( `${ itemCls } -content` , classNames . itemContent , itemClassNames . content ) }
226
+ style = { { ... styles . itemContent , ... itemStyles . content } }
158
227
>
159
228
{ mergedContent }
160
229
</ div >
@@ -164,17 +233,18 @@ export default function Step(props: StepProps) {
164
233
) ;
165
234
166
235
let stepNode : React . ReactNode = (
167
- < div
236
+ < li
168
237
{ ...restItemProps }
169
238
{ ...accessibilityProps }
170
239
className = { classString }
171
240
style = { {
172
241
...styles . item ,
242
+ ...itemStyles . root ,
173
243
...style ,
174
244
} }
175
245
>
176
246
{ itemWrapperRender ? itemWrapperRender ( wrapperNode ) : wrapperNode }
177
- </ div >
247
+ </ li >
178
248
) ;
179
249
180
250
if ( itemRender ) {
0 commit comments