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