@@ -7,19 +7,12 @@ import {
7
7
} from '@capgeminiuk/dcx-react-library' ;
8
8
import './stepper.scss' ;
9
9
10
- const StepperDemo : React . FC = ( ) => {
10
+ const StepperDemo = ( ) => {
11
11
const [ activeStepHorizontal , setActiveStepHorizontal ] = useState ( 0 ) ;
12
12
const [ activeStepVertical , setActiveStepVertical ] = useState ( 0 ) ;
13
13
const [ activeStepCustomSeparator , setActiveStepCustomSeparator ] = useState ( 0 ) ;
14
14
const [ activeStepItems , setActiveStepItems ] = useState ( 0 ) ;
15
15
16
- const handleStepChange = (
17
- setter : React . Dispatch < React . SetStateAction < number > > ,
18
- step : number
19
- ) => {
20
- setter ( step ) ;
21
- } ;
22
-
23
16
const steps = [
24
17
{
25
18
header : 'Campaign Settings' ,
@@ -285,8 +278,8 @@ const StepperDemo: React.FC = () => {
285
278
286
279
const renderStepper = (
287
280
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 } [ ] ,
290
283
orientation : 'horizontal' | 'vertical' ,
291
284
customSeparator : JSX . Element | undefined = undefined
292
285
) => (
@@ -295,36 +288,90 @@ const StepperDemo: React.FC = () => {
295
288
selectedStep = { activeStep }
296
289
separator = { customSeparator || < hr className = "separator" /> }
297
290
>
298
- { items . map ( ( item , index ) => (
291
+ { steps . map ( ( step , index ) => (
299
292
< Step
300
293
key = { index }
301
294
className = { `step ${ activeStep === index ? 'active' : '' } ` }
295
+ style = { { display : orientation === 'horizontal' ? 'inline-flex' : 'flex' } }
302
296
>
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 }
306
312
</ div >
307
- { item . header }
313
+ < div style = { { fontSize : '16px' , fontWeight : 'bold' , color : '#333' } } > { step . header } </ div >
308
314
</ 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' } } >
312
318
{ index > 0 && (
313
319
< button
314
- onClick = { ( ) => handleStepChange ( setter , index - 1 ) }
320
+ onClick = { ( ) => setActiveStep ( index - 1 ) }
315
321
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
+ } }
316
333
>
317
334
Prev
318
335
</ button >
319
336
) }
320
- { index < items . length - 1 && (
337
+ { index < steps . length - 1 && (
321
338
< button
322
- onClick = { ( ) => handleStepChange ( setter , index + 1 ) }
339
+ onClick = { ( ) => setActiveStep ( index + 1 ) }
323
340
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
+ } }
324
352
>
325
353
Next
326
354
</ button >
327
355
) }
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
+ ) }
328
375
</ div >
329
376
</ StepContent >
330
377
</ Step >
@@ -333,22 +380,12 @@ const StepperDemo: React.FC = () => {
333
380
) ;
334
381
335
382
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)' } } >
337
384
< h1 > Horizontal Stepper</ h1 >
338
- { renderStepper (
339
- activeStepHorizontal ,
340
- setActiveStepHorizontal ,
341
- steps ,
342
- 'horizontal'
343
- ) }
385
+ { renderStepper ( activeStepHorizontal , setActiveStepHorizontal , steps , 'horizontal' ) }
344
386
345
387
< h1 > Vertical Stepper</ h1 >
346
- { renderStepper (
347
- activeStepVertical ,
348
- setActiveStepVertical ,
349
- steps ,
350
- 'vertical'
351
- ) }
388
+ { renderStepper ( activeStepVertical , setActiveStepVertical , steps , 'vertical' ) }
352
389
353
390
< h1 > Stepper with Custom Separator</ h1 >
354
391
{ renderStepper (
@@ -360,9 +397,14 @@ const StepperDemo: React.FC = () => {
360
397
) }
361
398
362
399
< h1 > Order Process Stepper</ h1 >
363
- { renderStepper ( activeStepItems , setActiveStepItems , items , 'horizontal' ) }
400
+ { renderStepper (
401
+ activeStepItems ,
402
+ setActiveStepItems ,
403
+ items ,
404
+ 'horizontal'
405
+ ) }
364
406
</ div >
365
407
) ;
366
408
} ;
367
409
368
- export default StepperDemo ;
410
+ export default StepperDemo ;
0 commit comments