@@ -7,19 +7,12 @@ import {
77} from '@capgeminiuk/dcx-react-library' ;
88import './stepper.scss' ;
99
10- const StepperDemo : React . FC = ( ) => {
10+ const StepperDemo = ( ) => {
1111 const [ activeStepHorizontal , setActiveStepHorizontal ] = useState ( 0 ) ;
1212 const [ activeStepVertical , setActiveStepVertical ] = useState ( 0 ) ;
1313 const [ activeStepCustomSeparator , setActiveStepCustomSeparator ] = useState ( 0 ) ;
1414 const [ activeStepItems , setActiveStepItems ] = useState ( 0 ) ;
1515
16- const handleStepChange = (
17- setter : React . Dispatch < React . SetStateAction < number > > ,
18- step : number
19- ) => {
20- setter ( step ) ;
21- } ;
22-
2316 const steps = [
2417 {
2518 header : 'Campaign Settings' ,
@@ -285,8 +278,8 @@ const StepperDemo: React.FC = () => {
285278
286279 const renderStepper = (
287280 activeStep : number ,
288- setter : React . Dispatch < React . SetStateAction < number > > ,
289- items : any [ ] ,
281+ setActiveStep : React . Dispatch < React . SetStateAction < number > > ,
282+ steps : { header : string ; content : React . ReactNode } [ ] ,
290283 orientation : 'horizontal' | 'vertical' ,
291284 customSeparator : JSX . Element | undefined = undefined
292285 ) => (
@@ -295,36 +288,90 @@ const StepperDemo: React.FC = () => {
295288 selectedStep = { activeStep }
296289 separator = { customSeparator || < hr className = "separator" /> }
297290 >
298- { items . map ( ( item , index ) => (
291+ { steps . map ( ( step , index ) => (
299292 < Step
300293 key = { index }
301294 className = { `step ${ activeStep === index ? 'active' : '' } ` }
295+ style = { { display : orientation === 'horizontal' ? 'inline-flex' : 'flex' } }
302296 >
303- < StepHeader className = "step-header" >
304- < div className = "step-number" aria-label = { `Step ${ index + 1 } ` } >
305- { activeStep > index ? '✔️' : index + 1 }
297+ < StepHeader onClick = { ( ) => setActiveStep ( index ) } style = { { cursor : 'pointer' , display : 'flex' , alignItems : 'center' } } >
298+ < div style = { {
299+ width : '30px' ,
300+ height : '30px' ,
301+ borderRadius : '50%' ,
302+ backgroundColor : activeStep >= index ? '#1976d2' : '#D1D0CE' ,
303+ color : 'white' ,
304+ display : 'flex' ,
305+ alignItems : 'center' ,
306+ justifyContent : 'center' ,
307+ marginRight : '10px' ,
308+ fontSize : '14px' ,
309+ fontWeight : 'bold'
310+ } } >
311+ { activeStep > index ? '✓' : index + 1 }
306312 </ div >
307- { item . header }
313+ < div style = { { fontSize : '16px' , fontWeight : 'bold' , color : '#333' } } > { step . header } </ div >
308314 </ StepHeader >
309- < StepContent className = "step-content" >
310- < div > { item . content } </ div >
311- < div className = "button-container" >
315+ < StepContent >
316+ < div > { step . content } </ div >
317+ < div className = "button-container" style = { { display : 'flex' , justifyContent : 'center' , marginTop : '20px' } } >
312318 { index > 0 && (
313319 < button
314- onClick = { ( ) => handleStepChange ( setter , index - 1 ) }
320+ onClick = { ( ) => setActiveStep ( index - 1 ) }
315321 aria-label = "Previous Step"
322+ style = { {
323+ padding : '10px 20px' ,
324+ fontSize : '14px' ,
325+ backgroundColor : '#1976d2' ,
326+ color : 'white' ,
327+ border : 'none' ,
328+ borderRadius : '4px' ,
329+ cursor : 'pointer' ,
330+ margin : '0 5px' ,
331+ boxShadow : '0 2px 4px rgba(0, 0, 0, 0.1)' ,
332+ } }
316333 >
317334 Prev
318335 </ button >
319336 ) }
320- { index < items . length - 1 && (
337+ { index < steps . length - 1 && (
321338 < button
322- onClick = { ( ) => handleStepChange ( setter , index + 1 ) }
339+ onClick = { ( ) => setActiveStep ( index + 1 ) }
323340 aria-label = "Next Step"
341+ style = { {
342+ padding : '10px 20px' ,
343+ fontSize : '14px' ,
344+ backgroundColor : '#1976d2' ,
345+ color : 'white' ,
346+ border : 'none' ,
347+ borderRadius : '4px' ,
348+ cursor : 'pointer' ,
349+ margin : '0 5px' ,
350+ boxShadow : '0 2px 4px rgba(0, 0, 0, 0.1)' ,
351+ } }
324352 >
325353 Next
326354 </ button >
327355 ) }
356+ { index === steps . length - 1 && (
357+ < button
358+ onClick = { ( ) => alert ( 'Form Submitted' ) }
359+ aria-label = "Submit Form"
360+ style = { {
361+ padding : '10px 20px' ,
362+ fontSize : '14px' ,
363+ backgroundColor : '#28a745' ,
364+ color : 'white' ,
365+ border : 'none' ,
366+ borderRadius : '4px' ,
367+ cursor : 'pointer' ,
368+ margin : '0 5px' ,
369+ boxShadow : '0 2px 4px rgba(0, 0, 0, 0.1)' ,
370+ } }
371+ >
372+ Submit
373+ </ button >
374+ ) }
328375 </ div >
329376 </ StepContent >
330377 </ Step >
@@ -333,22 +380,12 @@ const StepperDemo: React.FC = () => {
333380 ) ;
334381
335382 return (
336- < div className = "stepper-demo" >
383+ < div style = { { padding : '20px' , backgroundColor : '#f9f9f9' , borderRadius : '8px' , boxShadow : '0 2px 10px rgba(0, 0, 0, 0.1)' } } >
337384 < h1 > Horizontal Stepper</ h1 >
338- { renderStepper (
339- activeStepHorizontal ,
340- setActiveStepHorizontal ,
341- steps ,
342- 'horizontal'
343- ) }
385+ { renderStepper ( activeStepHorizontal , setActiveStepHorizontal , steps , 'horizontal' ) }
344386
345387 < h1 > Vertical Stepper</ h1 >
346- { renderStepper (
347- activeStepVertical ,
348- setActiveStepVertical ,
349- steps ,
350- 'vertical'
351- ) }
388+ { renderStepper ( activeStepVertical , setActiveStepVertical , steps , 'vertical' ) }
352389
353390 < h1 > Stepper with Custom Separator</ h1 >
354391 { renderStepper (
@@ -360,9 +397,14 @@ const StepperDemo: React.FC = () => {
360397 ) }
361398
362399 < h1 > Order Process Stepper</ h1 >
363- { renderStepper ( activeStepItems , setActiveStepItems , items , 'horizontal' ) }
400+ { renderStepper (
401+ activeStepItems ,
402+ setActiveStepItems ,
403+ items ,
404+ 'horizontal'
405+ ) }
364406 </ div >
365407 ) ;
366408} ;
367409
368- export default StepperDemo ;
410+ export default StepperDemo ;
0 commit comments