"use client" import { cn } from "@/lib/utils" import { Check } from "lucide-react" export interface Step { id: number title: string subtitle?: string description?: string } export interface StepIndicatorProps { steps: Step[] currentStep: number variant?: "default" | "circle" | "numbered" | "minimal" orientation?: "horizontal" | "vertical" onStepClick?: (stepId: number) => void className?: string showProgress?: boolean } /** * 统一的步骤指示器组件 * * @param steps 步骤数组 * @param currentStep 当前步骤 * @param variant 样式变体 * @param orientation 方向 * @param onStepClick 步骤点击回调 * @param className 自定义类名 * @param showProgress 是否显示进度条 */ export function StepIndicator({ steps, currentStep, variant = "default", orientation = "horizontal", onStepClick, className, showProgress = true, }: StepIndicatorProps) { // 计算进度百分比 const progressPercentage = steps.length > 1 ? ((currentStep - 1) / (steps.length - 1)) * 100 : 0 // 根据变体渲染不同样式的步骤指示器 if (variant === "circle") { return (
{steps.map((step, index) => { const isCompleted = currentStep > step.id const isCurrent = currentStep === step.id const isClickable = onStepClick && (isCompleted || isCurrent) return (
isClickable && onStepClick(step.id)} >
{isCompleted ? : step.id}
{step.title}
{step.subtitle &&
{step.subtitle}
}
) })} {/* 连接线 */} {showProgress && orientation === "horizontal" && (
)}
) } // 默认样式 return (
{steps.map((step, index) => { const isActive = currentStep >= step.id const isCurrent = currentStep === step.id const isClickable = onStepClick && currentStep > step.id return (
isClickable && onStepClick(step.id)} > {isActive && currentStep !== step.id ? : step.id}
{index < steps.length - 1 && (
)}
{step.title}
) })}
) } export default StepIndicator