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 | import { cn } from '@/lib/utils'
import { CheckIcon } from '@/shared/icons/check-icon'
export interface Step {
id: string
label: string
}
interface StepIndicatorProps {
steps: Step[]
currentStepId: string
accentClassName?: string
className?: string
}
export function StepIndicator({ steps, currentStepId, accentClassName = 'bg-primary', className }: StepIndicatorProps) {
const currentIndex = steps.findIndex((step) => step.id === currentStepId)
return (
<div className={cn('flex items-center', className)}>
{steps.map((step, index) => {
const isCompleted = index < currentIndex
const isActive = index === currentIndex
return (
<div key={step.id} className="flex items-center">
<div className="flex items-center gap-2">
<span
className={cn(
'flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-full text-[11px] font-bold transition-colors duration-200',
isCompleted || isActive ? cn(accentClassName, 'text-white') : 'bg-muted text-ink-faint',
)}
>
{isCompleted ? <CheckIcon className="h-3 w-3" /> : index + 1}
</span>
{/* Rótulo escondido só visualmente abaixo de `sm`, nunca
removido. Os três rótulos somados dão ~420px de min-content, e
como DialogContent é um grid cujo item não encolhe abaixo
disso (`min-width: auto`), o painel inteiro era arrastado para
420 dentro de uma tela de 390 — rolagem horizontal dentro do
diálogo. `sr-only` preserva o texto para leitor de tela, e o
passo atual continua nomeado no corpo do diálogo. */}
<span
className={cn(
'sr-only text-xs font-semibold sm:not-sr-only',
isActive ? 'text-ink' : 'text-ink-faint',
)}
>
{step.label}
</span>
</div>
{index < steps.length - 1 && (
<div
className={cn(
'mx-2 h-0.5 w-7 flex-shrink-0 rounded-full transition-colors duration-200',
isCompleted ? accentClassName : 'bg-muted',
)}
/>
)}
</div>
)
})}
</div>
)
}
|