33import React from 'react' ;
44import clsx from 'clsx' ;
55
6+ import { BoxProps } from '../box/interfaces' ;
7+ import InternalBox from '../box/internal' ;
68import { InternalBaseComponentProps } from '../internal/hooks/use-base-component' ;
79import { SomeRequired } from '../internal/types' ;
810import StatusIndicator from '../status-indicator/internal' ;
@@ -12,45 +14,107 @@ import styles from './styles.css.js';
1214
1315type InternalStepsProps = SomeRequired < StepsProps , 'steps' > & InternalBaseComponentProps ;
1416
15- const InternalStep = ( { status, statusIconAriaLabel, header, details } : StepsProps . Step ) => {
17+ const statusToColor : Record < StepsProps . Status , BoxProps . Color > = {
18+ error : 'text-status-error' ,
19+ warning : 'text-status-warning' ,
20+ success : 'text-status-success' ,
21+ info : 'text-status-info' ,
22+ stopped : 'text-status-inactive' ,
23+ pending : 'text-status-inactive' ,
24+ 'in-progress' : 'text-status-inactive' ,
25+ loading : 'text-status-inactive' ,
26+ } ;
27+
28+ const CustomStep = ( {
29+ step,
30+ orientation,
31+ renderStep,
32+ } : {
33+ step : StepsProps . Step ;
34+ orientation : StepsProps . Orientation ;
35+ renderStep : Required < StepsProps > [ 'renderStep' ] ;
36+ } ) => {
37+ const { status, statusIconAriaLabel } = step ;
38+ const { header, details, icon } = renderStep ( step ) ;
39+ return (
40+ < li className = { styles . container } >
41+ < div className = { styles . header } >
42+ { icon ? icon : < StatusIndicator type = { status } iconAriaLabel = { statusIconAriaLabel } /> }
43+ { orientation === 'vertical' ? header : < hr className = { styles . connector } role = "none" /> }
44+ </ div >
45+ { orientation === 'vertical' ? (
46+ < hr className = { styles . connector } role = "none" />
47+ ) : (
48+ < div className = { styles [ 'horizontal-header' ] } > { header } </ div >
49+ ) }
50+ { details && < div className = { styles . details } > { details } </ div > }
51+ </ li >
52+ ) ;
53+ } ;
54+
55+ const InternalStep = ( {
56+ status,
57+ statusIconAriaLabel,
58+ header,
59+ details,
60+ orientation,
61+ } : StepsProps . Step & { orientation : StepsProps . Orientation } ) => {
1662 return (
1763 < li className = { styles . container } >
1864 < div className = { styles . header } >
1965 < StatusIndicator type = { status } iconAriaLabel = { statusIconAriaLabel } >
20- { header }
66+ { orientation === 'vertical' && header }
2167 </ StatusIndicator >
68+ { orientation === 'horizontal' && < hr className = { styles . connector } role = "none" /> }
2269 </ div >
23- < hr className = { styles . connector } role = "none" />
70+ { orientation === 'vertical' ? (
71+ < hr className = { styles . connector } role = "none" />
72+ ) : (
73+ < div className = { styles [ 'horizontal-header' ] } >
74+ < InternalBox color = { statusToColor [ status ] } > { header } </ InternalBox >
75+ </ div >
76+ ) }
2477 { details && < div className = { styles . details } > { details } </ div > }
2578 </ li >
2679 ) ;
2780} ;
2881
2982const InternalSteps = ( {
3083 steps,
84+ orientation,
85+ renderStep,
3186 ariaLabel,
3287 ariaLabelledby,
3388 ariaDescribedby,
3489 __internalRootRef,
3590 ...props
36- } : InternalStepsProps ) => {
91+ } : SomeRequired < InternalStepsProps , 'orientation' > ) => {
3792 return (
38- < div { ...props } className = { clsx ( styles . root , props . className ) } ref = { __internalRootRef } >
93+ < div
94+ { ...props }
95+ className = { clsx ( styles . root , props . className , orientation === 'horizontal' ? styles . horizontal : styles . vertical ) }
96+ ref = { __internalRootRef }
97+ >
3998 < ol
4099 className = { styles . list }
41100 aria-label = { ariaLabel }
42101 aria-labelledby = { ariaLabelledby }
43102 aria-describedby = { ariaDescribedby }
44103 >
45- { steps . map ( ( step , index ) => (
46- < InternalStep
47- key = { index }
48- status = { step . status }
49- statusIconAriaLabel = { step . statusIconAriaLabel }
50- header = { step . header }
51- details = { step . details }
52- />
53- ) ) }
104+ { steps . map ( ( step , index ) =>
105+ renderStep ? (
106+ < CustomStep key = { index } orientation = { orientation } step = { step } renderStep = { renderStep } />
107+ ) : (
108+ < InternalStep
109+ key = { index }
110+ status = { step . status }
111+ statusIconAriaLabel = { step . statusIconAriaLabel }
112+ header = { step . header }
113+ details = { step . details }
114+ orientation = { orientation }
115+ />
116+ )
117+ ) }
54118 </ ol >
55119 </ div >
56120 ) ;
0 commit comments