1- import { ReactNode } from 'react'
1+ import { ReactNode , useState } from 'react'
22
33interface Step {
44 title : string
@@ -12,20 +12,35 @@ interface StepWizardProps {
1212}
1313
1414export default function StepWizard ( { steps, activeStep } : StepWizardProps ) {
15+ const [ expandedSteps , setExpandedSteps ] = useState < Set < number > > ( new Set ( ) )
16+
17+ const toggleStep = ( index : number ) => {
18+ setExpandedSteps ( prev => {
19+ const next = new Set ( prev )
20+ if ( next . has ( index ) ) next . delete ( index )
21+ else next . add ( index )
22+ return next
23+ } )
24+ }
25+
1526 return (
1627 < div className = "space-y-4" >
1728 { steps . map ( ( step , i ) => {
1829 const isCompleted = i < activeStep
1930 const isActive = i === activeStep
2031 const isFuture = i > activeStep
32+ const isExpanded = expandedSteps . has ( i )
2133
2234 return (
2335 < div key = { i } className = { `rounded-lg border ${
2436 isActive ? 'border-blue-600 bg-gray-900' :
2537 isCompleted ? 'border-green-800 bg-gray-900/50' :
2638 'border-gray-800 bg-gray-900/30 opacity-50'
2739 } `} >
28- < div className = "flex items-center gap-3 p-4" >
40+ < div
41+ className = { `flex items-center gap-3 p-4 ${ isCompleted ? 'cursor-pointer select-none' : '' } ` }
42+ onClick = { ( ) => isCompleted && toggleStep ( i ) }
43+ >
2944 < div className = { `flex items-center justify-center w-7 h-7 rounded-full text-sm font-bold ${
3045 isCompleted ? 'bg-green-700 text-green-200' :
3146 isActive ? 'bg-blue-600 text-white' :
@@ -41,9 +56,14 @@ export default function StepWizard({ steps, activeStep }: StepWizardProps) {
4156 { step . summary }
4257 </ span >
4358 ) }
59+ { isCompleted && (
60+ < span className = { `text-xs text-gray-500 ${ step . summary ? 'ml-2' : 'ml-auto' } ` } >
61+ { isExpanded ? '\u25BC' : '\u25B6' }
62+ </ span >
63+ ) }
4464 </ div >
45- { isActive && (
46- < div className = " px-4 pb-4" >
65+ { ( isActive || isCompleted ) && (
66+ < div className = { ` px-4 pb-4 ${ isCompleted && ! isExpanded ? 'hidden' : '' } ` } >
4767 { step . content }
4868 </ div >
4969 ) }
0 commit comments