Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 44x 44x 44x 44x 44x 44x 44x 44x 44x 44x 44x 1x 1x 1x 44x 44x 44x 136x 136x 55x 44x 44x 44x 44x 44x 44x 44x 44x 44x 44x 44x 44x 44x 44x 44x 44x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 38x 38x 38x 38x 136x 136x 43x 43x 43x 43x 136x 136x 55x 55x 55x 136x 136x 136x 136x 136x 136x 136x 3x 136x 37x 133x 96x 136x 136x 136x 136x 136x 92x 92x 92x 92x 92x 92x 92x 92x 92x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 136x 131x 131x 131x 131x 131x 131x 131x 131x 131x 131x 136x 136x 136x 136x 136x 44x 44x 44x 44x 1x 1x 1x 1x 1x | /**
* Stepper Component
*
* A component that displays progress through a sequence of logical steps.
* Useful for multi-step processes like checkout, onboarding, forms, etc.
*
* Features:
* - Numbered steps with labels
* - Optional descriptions for each step
* - Visual indication of current, completed, and upcoming steps
* - Horizontal and vertical orientations
* - Clickable steps (optional)
* - Responsive design
* - Accessible with ARIA labels
*
* @example
* ```tsx
* const steps = [
* { label: 'Shipping', description: 'Enter delivery address' },
* { label: 'Payment', description: 'Choose payment method' },
* { label: 'Review', description: 'Confirm your order' },
* ];
*
* <Stepper
* steps={steps}
* currentStep={1}
* onStepClick={(index) => goToStep(index)}
* />
* ```
*/
import React from 'react';
import { CheckIcon } from '@/components/ui/icons';
import { cn } from '@/lib/core';
import { StepperProps } from '@/types/ui';
/**
* Stepper component for displaying multi-step progress
*/
const Stepper = React.forwardRef<HTMLDivElement, StepperProps>(
(
{
steps,
currentStep,
onStepClick,
clickable = false,
orientation = 'horizontal',
showDescription = true,
className},
ref
) => {
const handleStepClick = (index: number) => {
if (clickable && index < currentStep && onStepClick) {
onStepClick(index);
}
};
const getStepStatus = (index: number): 'completed' | 'current' | 'upcoming' => {
if (index < currentStep) return 'completed';
if (index === currentStep) return 'current';
return 'upcoming';
};
const isHorizontal = orientation === 'horizontal';
return (
<div
ref={ref}
className={cn(
'stepper',
isHorizontal ? 'flex items-start' : 'flex flex-col',
className
)}
role="navigation"
aria-label="Progress"
>
{steps.map((step, index) => {
const status = getStepStatus(index);
const isCompleted = status === 'completed';
const isCurrent = status === 'current';
const isClickable = clickable && isCompleted;
const isLast = index === steps.length - 1;
return (
<div
key={index}
className={cn(
'stepper-item',
isHorizontal ? 'flex-1' : 'flex',
isHorizontal && !isLast && 'pb-0',
!isHorizontal && !isLast && 'pb-8'
)}
>
<div className={cn(isHorizontal ? 'flex flex-col items-center' : 'flex items-start', 'w-full')}>
{/* Step indicator container */}
<div className={cn('flex items-center', isHorizontal ? 'w-full' : 'flex-shrink-0')}>
{/* Step circle */}
<button
type="button"
onClick={() => handleStepClick(index)}
disabled={!isClickable}
className={cn(
'stepper-circle',
'relative flex items-center justify-center',
'w-10 h-10 rounded-full',
'font-medium text-sm',
'transition-all duration-200',
'focus:outline-none focus:ring-2 focus:ring-offset-2',
// Completed state
isCompleted && [
'bg-primary text-white',
isClickable && 'cursor-pointer hover:bg-primary-700',
!isClickable && 'cursor-default',
],
// Current state
isCurrent && [
'bg-primary text-white',
'ring-4 ring-primary-100',
'cursor-default',
],
// Upcoming state
!isCompleted && !isCurrent && [
'bg-gray-200 text-gray-500',
'cursor-default',
],
// Focus ring color
'focus:ring-primary-200'
)}
aria-current={isCurrent ? 'step' : undefined}
aria-label={`${isCompleted ? 'Completed: ' : isCurrent ? 'Current: ' : ''}${step.label}`}
>
{step.icon ? (
step.icon
) : isCompleted ? (
<CheckIcon className="w-5 h-5" aria-hidden="true" />
) : (
<span>{index + 1}</span>
)}
</button>
{/* Connector line */}
{!isLast && (
<div
className={cn(
'stepper-connector',
isHorizontal ? 'flex-1 h-0.5 mx-2' : 'w-0.5 ml-5 flex-1',
isCompleted ? 'bg-primary' : 'bg-gray-200',
'transition-colors duration-200'
)}
aria-hidden="true"
/>
)}
</div>
{/* Step content */}
<div
className={cn(
'stepper-content',
isHorizontal ? 'mt-3 text-center' : 'ml-4 pb-8'
)}
>
<div
className={cn(
'text-sm font-medium',
isCurrent && 'text-primary',
isCompleted && 'text-gray-900',
!isCurrent && !isCompleted && 'text-gray-500'
)}
>
{step.label}
</div>
{showDescription && step.description && (
<div
className={cn(
'mt-1 text-xs',
isCurrent && 'text-gray-600',
isCompleted && 'text-gray-500',
!isCurrent && !isCompleted && 'text-gray-400'
)}
>
{step.description}
</div>
)}
</div>
</div>
</div>
);
})}
</div>
);
}
);
Stepper.displayName = 'Stepper';
export default Stepper;
|