:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { IconCheckCircle } from '@posthog/icons'
import { IconErrorOutline } from 'lib/lemon-ui/icons'
import { cn } from 'lib/utils/css-classes'
import { ExperimentWizardStep, STEP_ORDER } from './experimentWizardLogic'
interface Step {
key: ExperimentWizardStep
label: string
}
const STEPS: Step[] = [
{ key: 'about', label: 'Description' },
{ key: 'variants', label: 'Variant rollout' },
{ key: 'analytics', label: 'Analytics' },
]
interface ExperimentWizardStepperProps {
currentStep: ExperimentWizardStep
onStepClick: (step: ExperimentWizardStep) => void
stepErrors?: Record<ExperimentWizardStep, string[]>
}
export function ExperimentWizardStepper({
currentStep,
onStepClick,
stepErrors,
}: ExperimentWizardStepperProps): JSX.Element {
const currentOrder = STEP_ORDER[currentStep]
return (
<nav className="flex items-center" aria-label="Experiment wizard progress">
{STEPS.map((step, index) => {
const stepOrder = STEP_ORDER[step.key]
const isCompleted = currentOrder > stepOrder
const isCurrent = currentStep === step.key
const hasErrors = (stepErrors?.[step.key]?.length ?? 0) > 0
return (
<div key={step.key} className="flex items-center">
{index > 0 && (
<div
className={cn(
'w-6 h-px transition-colors duration-150',
isCompleted || isCurrent ? 'bg-success' : 'bg-border-primary'
)}
/>
)}
<button
type="button"
onClick={() => onStepClick(step.key)}
className={cn(
'group flex items-center gap-1.5 px-2 py-1 rounded',
'transition-all duration-150',
'focus:outline-none focus-visible:ring-1 focus-visible:ring-accent',
'cursor-pointer hover:bg-fill-button-tertiary-hover active:scale-[0.98]'
)}
aria-current={isCurrent ? 'step' : undefined}
>
{hasErrors ? (
<IconErrorOutline className="size-5 text-danger" />
) : isCompleted ? (
<IconCheckCircle className="size-5 text-success" />
) : (
<span
className={cn(
'flex items-center justify-center size-5 rounded-full text-xs font-semibold',
'transition-all duration-150',
isCurrent && 'bg-accent text-primary-inverse ring-2 ring-accent/25',
!isCurrent && 'bg-surface-secondary text-secondary border border-primary'
)}
>
{index + 1}
</span>
)}
<span
className={cn(
'text-sm transition-colors duration-150',
isCurrent && 'font-semibold text-primary',
isCompleted && !hasErrors && 'font-medium text-primary',
(!isCompleted || hasErrors) && !isCurrent && 'text-secondary'
)}
>
{step.label}
</span>
</button>
</div>
)
})}
</nav>
)
}