|
| 1 | +import { cn } from '@/lib/utils'; |
| 2 | +import { Check } from 'lucide-react'; |
| 3 | +import React from 'react'; |
| 4 | + |
| 5 | +type StepperProps = { |
| 6 | + classname: string; |
| 7 | + currentStep: number; |
| 8 | + steps: string[]; |
| 9 | +}; |
| 10 | + |
| 11 | +export const Stepper: React.FC<StepperProps> = ({ |
| 12 | + classname, |
| 13 | + currentStep, |
| 14 | + steps, |
| 15 | +}) => { |
| 16 | + const stepsNb = steps.length; |
| 17 | + |
| 18 | + return ( |
| 19 | + <div |
| 20 | + className={cn('grid gap-y-4', classname)} |
| 21 | + style={{ |
| 22 | + gridTemplateColumns: `repeat(${stepsNb}, minmax(0, 1fr))`, |
| 23 | + maxWidth: stepsNb * 350, |
| 24 | + }} |
| 25 | + aria-label="Progress indicator" |
| 26 | + > |
| 27 | + {steps.map((step, index) => { |
| 28 | + const isActive = currentStep >= index; |
| 29 | + const isCompleted = currentStep > index; |
| 30 | + |
| 31 | + return ( |
| 32 | + <div key={step} className="flex w-full flex-col items-center"> |
| 33 | + <div className="relative w-full"> |
| 34 | + {index < stepsNb - 1 && ( |
| 35 | + <span |
| 36 | + className={cn( |
| 37 | + 'absolute top-1/2 right-0 h-px w-1/2 translate-x-1/2 -translate-y-1/2 rounded-full', |
| 38 | + isCompleted ? 'bg-white' : 'bg-grey-400' |
| 39 | + )} |
| 40 | + /> |
| 41 | + )} |
| 42 | + <div |
| 43 | + className={cn( |
| 44 | + 'mx-auto flex size-8 items-center justify-center rounded-full', |
| 45 | + isActive ? 'bg-white text-black' : 'bg-grey-700', |
| 46 | + isCompleted && 'bg-primary text-black' |
| 47 | + )} |
| 48 | + aria-label={`Step ${index + 1}`} |
| 49 | + > |
| 50 | + {isCompleted ? ( |
| 51 | + <Check size="16" strokeWidth="2.5" /> |
| 52 | + ) : ( |
| 53 | + index + 1 |
| 54 | + )} |
| 55 | + </div> |
| 56 | + </div> |
| 57 | + <span |
| 58 | + className={cn( |
| 59 | + 'mt-2 text-center', |
| 60 | + isActive ? 'text-white' : 'text-grey-500' |
| 61 | + )} |
| 62 | + > |
| 63 | + {step} |
| 64 | + </span> |
| 65 | + </div> |
| 66 | + ); |
| 67 | + })} |
| 68 | + </div> |
| 69 | + ); |
| 70 | +}; |
0 commit comments