medkit/src/kit/stepper.tsx

59 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { CheckIcon } from "lucide-react"
import { cn } from "@/lib/utils"
export interface StepItem {
readonly label: string
/** Подпись под шагом: выбранный слот, пациент… */
readonly hint?: string
}
/** Шаги мастера: пройденные — с галочкой и кликабельны, будущие — недоступны. */
export function Stepper({
steps,
current,
onStepClick,
className,
}: {
steps: readonly StepItem[]
current: number
onStepClick?: (index: number) => void
className?: string
}) {
return (
<ol className={cn("flex items-center gap-2", className)}>
{steps.map((step, i) => {
const done = i < current
const active = i === current
const clickable = Boolean(onStepClick) && done
return (
<li key={step.label} className="flex min-w-0 items-center gap-2">
{i > 0 && <span className={cn("h-px w-6 shrink-0 sm:w-10", done || active ? "bg-primary/50" : "bg-border")} />}
<button
type="button"
disabled={!clickable}
onClick={() => onStepClick?.(i)}
className={cn("flex min-w-0 items-center gap-2 rounded-lg px-1.5 py-1 text-left transition", clickable && "hover:bg-muted")}
>
<span
className={cn(
"grid size-6 shrink-0 place-items-center rounded-full text-xs font-semibold",
done && "bg-primary text-primary-foreground",
active && "bg-primary/15 text-primary ring-2 ring-primary/40",
!done && !active && "bg-muted text-muted-foreground",
)}
>
{done ? <CheckIcon className="size-3.5" /> : i + 1}
</span>
<span className="min-w-0 leading-tight">
<span className={cn("block text-sm font-medium", !done && !active && "text-muted-foreground")}>{step.label}</span>
{step.hint && <span className="block truncate text-[11px] text-muted-foreground">{step.hint}</span>}
</span>
</button>
</li>
)
})}
</ol>
)
}