{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stepper",
  "type": "registry:ui",
  "title": "Stepper",
  "description": "Numbered steps across the top or down the side, with done, current, loading and error states. Controlled or uncontrolled, linear or in any order, with arrow-key navigation. For checkouts, form wizards and onboarding.",
  "author": "DressCode UI <https://dresscodeui.com>",
  "dependencies": [
    "lucide-react@^1.73.0"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/dresscode/components/stepper/ui/stepper.tsx",
      "type": "registry:ui",
      "content": "\"use client\"\n\n// Stepper: numbered steps for checkouts, wizards and onboarding, across the top or down the side.\n// Stepper holds the current step (controlled `value` + `onValueChange`, or `defaultValue`) and renders\n// the labelled list. Each StepperItem has a 1-based `step` and can be `completed`, `disabled`,\n// `loading` or `invalid`; with `linear` on the Stepper, a step opens only once every step before it is\n// completed. The step buttons take one Tab stop: arrow keys, Home and End move between them, Enter or\n// Space opens one. The current one carries aria-current=\"step\".\n// Built for shadcn/ui; reads only the theme's variables.\nimport * as React from \"react\"\nimport { CheckIcon, LoaderCircleIcon, TriangleAlertIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\ntype Orientation = \"horizontal\" | \"vertical\"\n/** What a step looks like: the current one wins, then an error, then done. */\ntype StepState = \"active\" | \"invalid\" | \"completed\" | \"inactive\"\n\ntype StepperContextValue = {\n  value: number\n  setValue: (step: number) => void\n  orientation: Orientation\n  linear: boolean\n  canOpen: (step: number) => boolean\n  register: (step: number, completed: boolean) => () => void\n}\n\nconst StepperContext = React.createContext<StepperContextValue | null>(null)\n\n/** The current step and a way to change it, for buttons and custom parts inside a Stepper. */\nfunction useStepper() {\n  const context = React.useContext(StepperContext)\n  if (!context) throw new Error(\"Stepper parts must be used inside <Stepper>.\")\n  const { value, setValue, orientation, linear, canOpen } = context\n  return { value, setValue, orientation, linear, canOpen }\n}\n\ntype StepperItemContextValue = {\n  step: number\n  state: StepState\n  active: boolean\n  completed: boolean\n  disabled: boolean\n  loading: boolean\n  invalid: boolean\n  /** The step can be opened now: not disabled, and allowed by `linear`. */\n  reachable: boolean\n}\n\nconst StepperItemContext = React.createContext<StepperItemContextValue | null>(null)\n\nfunction useStepperItem() {\n  const context = React.useContext(StepperItemContext)\n  if (!context) throw new Error(\"This Stepper part must be used inside <StepperItem>.\")\n  return context\n}\n\nfunction useStepperContext() {\n  const context = React.useContext(StepperContext)\n  if (!context) throw new Error(\"Stepper parts must be used inside <Stepper>.\")\n  return context\n}\n\ntype StepperProps = Omit<React.ComponentProps<\"ol\">, \"defaultValue\"> & {\n  /** The current step, 1-based. Pair with onValueChange. */\n  value?: number\n  /** The step to start on when value is not controlled. */\n  defaultValue?: number\n  onValueChange?: (step: number) => void\n  orientation?: Orientation\n  /** Block jumping ahead: a step opens only once every step before it is completed. */\n  linear?: boolean\n}\n\nfunction Stepper({\n  value: valueProp,\n  defaultValue = 1,\n  onValueChange,\n  orientation = \"horizontal\",\n  linear = false,\n  className,\n  onKeyDown,\n  ...props\n}: StepperProps) {\n  const [uncontrolled, setUncontrolled] = React.useState(defaultValue)\n  const value = valueProp ?? uncontrolled\n  const setValue = React.useCallback(\n    (step: number) => {\n      if (valueProp === undefined) setUncontrolled(step)\n      onValueChange?.(step)\n    },\n    [valueProp, onValueChange],\n  )\n\n  // Which steps are completed, so `linear` can tell whether a later step may open.\n  const [completed, setCompleted] = React.useState<Record<number, boolean>>({})\n  const register = React.useCallback((step: number, done: boolean) => {\n    setCompleted((prev) => (prev[step] === done ? prev : { ...prev, [step]: done }))\n    return () =>\n      setCompleted((prev) => {\n        if (!(step in prev)) return prev\n        const next = { ...prev }\n        delete next[step]\n        return next\n      })\n  }, [])\n  const canOpen = React.useCallback(\n    (step: number) => {\n      if (!linear || step <= value) return true\n      for (let s = 1; s < step; s++) if (!completed[s]) return false\n      return true\n    },\n    [linear, value, completed],\n  )\n\n  const context = React.useMemo(\n    () => ({ value, setValue, orientation, linear, canOpen, register }),\n    [value, setValue, orientation, linear, canOpen, register],\n  )\n\n  function handleKeyDown(event: React.KeyboardEvent<HTMLOListElement>) {\n    onKeyDown?.(event)\n    if (event.defaultPrevented) return\n    const target = event.target as HTMLElement\n    if (target.dataset.slot !== \"stepper-trigger\") return\n    const list = event.currentTarget\n    const triggers = Array.from(list.querySelectorAll<HTMLButtonElement>('[data-slot=\"stepper-trigger\"]')).filter(\n      (t) => !t.disabled && t.closest('[data-slot=\"stepper\"]') === list,\n    )\n    const index = triggers.indexOf(target as HTMLButtonElement)\n    if (index === -1) return\n    const rtl = getComputedStyle(list).direction === \"rtl\"\n    const back = orientation === \"vertical\" ? \"ArrowUp\" : rtl ? \"ArrowRight\" : \"ArrowLeft\"\n    const forward = orientation === \"vertical\" ? \"ArrowDown\" : rtl ? \"ArrowLeft\" : \"ArrowRight\"\n    let to: number\n    if (event.key === forward) to = (index + 1) % triggers.length\n    else if (event.key === back) to = (index - 1 + triggers.length) % triggers.length\n    else if (event.key === \"Home\") to = 0\n    else if (event.key === \"End\") to = triggers.length - 1\n    else return\n    event.preventDefault()\n    triggers[to]?.focus()\n  }\n\n  return (\n    <StepperContext.Provider value={context}>\n      <ol\n        data-slot=\"stepper\"\n        data-orientation={orientation}\n        aria-label={props[\"aria-labelledby\"] ? undefined : \"Progress\"}\n        onKeyDown={handleKeyDown}\n        className={cn(\"group/stepper flex\", orientation === \"horizontal\" ? \"w-full items-center gap-3\" : \"flex-col\", className)}\n        {...props}\n      />\n    </StepperContext.Provider>\n  )\n}\n\ntype StepperItemProps = React.ComponentProps<\"li\"> & {\n  /** This step's number, 1-based. */\n  step: number\n  completed?: boolean\n  disabled?: boolean\n  /** Shows a spinner in the indicator, e.g. while the step saves. */\n  loading?: boolean\n  /** Marks the step as having errors. */\n  invalid?: boolean\n}\n\nfunction StepperItem({\n  step,\n  completed = false,\n  disabled = false,\n  loading = false,\n  invalid = false,\n  className,\n  ...props\n}: StepperItemProps) {\n  const { value, orientation, canOpen, register } = useStepperContext()\n  React.useLayoutEffect(() => register(step, completed), [register, step, completed])\n\n  const active = value === step\n  const state: StepState = active ? \"active\" : invalid ? \"invalid\" : completed ? \"completed\" : \"inactive\"\n  const reachable = !disabled && canOpen(step)\n  const item = React.useMemo(\n    () => ({ step, state, active, completed, disabled, loading, invalid, reachable }),\n    [step, state, active, completed, disabled, loading, invalid, reachable],\n  )\n\n  return (\n    <StepperItemContext.Provider value={item}>\n      <li\n        data-slot=\"stepper-item\"\n        data-state={state}\n        data-active={active ? \"\" : undefined}\n        data-completed={completed ? \"\" : undefined}\n        data-invalid={invalid ? \"\" : undefined}\n        data-loading={loading ? \"\" : undefined}\n        data-disabled={disabled ? \"\" : undefined}\n        className={cn(\n          \"group/stepper-item relative\",\n          orientation === \"horizontal\" ? \"flex flex-1 items-center gap-3 last:flex-none\" : \"flex flex-col pb-8 last:pb-0\",\n          disabled && \"opacity-50\",\n          className,\n        )}\n        {...props}\n      />\n    </StepperItemContext.Provider>\n  )\n}\n\n/** Words a screen reader hears before the step's title, e.g. \"Step 2, completed:\". */\nfunction statusText(item: StepperItemContextValue) {\n  const status = item.loading ? \", in progress\" : item.invalid ? \", needs attention\" : item.completed ? \", completed\" : \"\"\n  return `Step ${item.step}${status}: `\n}\n\n/** The button that opens a step. Put the indicator, title and description inside it. */\nfunction StepperTrigger({ className, children, onClick, disabled, ...props }: React.ComponentProps<\"button\">) {\n  const { setValue, orientation } = useStepperContext()\n  const item = useStepperItem()\n  return (\n    <button\n      type=\"button\"\n      data-slot=\"stepper-trigger\"\n      data-state={item.state}\n      aria-current={item.active ? \"step\" : undefined}\n      aria-busy={item.loading || undefined}\n      tabIndex={item.active ? 0 : -1}\n      disabled={disabled || !item.reachable}\n      onClick={(event) => {\n        onClick?.(event)\n        if (!event.defaultPrevented && !item.active) setValue(item.step)\n      }}\n      className={cn(\n        \"group/stepper-trigger -m-1 grid min-w-0 grid-cols-[auto_minmax(0,1fr)] gap-x-3 rounded-lg p-1 text-start outline-none transition-colors\",\n        \"focus-visible:ring-3 focus-visible:ring-ring/50 enabled:cursor-pointer disabled:cursor-default\",\n        \"enabled:hover:*:data-[state=inactive]:data-[slot=stepper-title]:text-foreground enabled:hover:*:data-[state=inactive]:data-[slot=stepper-indicator]:border-primary/60\",\n        // horizontal: the title row stretches to the indicator's height when there is no description\n        orientation === \"horizontal\" ? \"grid-rows-[1fr_auto] items-center\" : \"items-start\",\n        className,\n      )}\n      {...props}\n    >\n      <span className=\"sr-only\">{statusText(item)}</span>\n      {children}\n    </button>\n  )\n}\n\n/** The circle: the step number (or your icon), a check when completed, a spinner when loading. */\nfunction StepperIndicator({ className, children, ...props }: React.ComponentProps<\"span\">) {\n  const { orientation } = useStepperContext()\n  const item = useStepperItem()\n  const look = item.loading ? \"loading\" : item.invalid ? \"invalid\" : item.completed ? \"completed\" : item.active ? \"active\" : \"inactive\"\n  return (\n    <span\n      aria-hidden=\"true\"\n      data-slot=\"stepper-indicator\"\n      data-state={look}\n      data-active={item.active ? \"\" : undefined}\n      className={cn(\n        \"row-span-2 flex size-8 shrink-0 items-center justify-center rounded-full border border-border bg-background text-xs font-semibold text-muted-foreground tabular-nums transition-[color,background-color,border-color,box-shadow] [&_svg]:size-4\",\n        \"data-[state=active]:border-primary data-[state=active]:text-foreground data-[state=loading]:border-primary data-[state=loading]:text-foreground\",\n        \"data-[state=completed]:border-primary data-[state=completed]:bg-primary data-[state=completed]:text-primary-foreground\",\n        \"data-[state=invalid]:border-destructive data-[state=invalid]:bg-destructive/10 data-[state=invalid]:text-destructive\",\n        \"data-active:ring-4 data-active:ring-primary/15 data-active:data-[state=invalid]:ring-destructive/15\",\n        orientation === \"horizontal\" ? \"self-center\" : \"self-start\",\n        className,\n      )}\n      {...props}\n    >\n      {item.loading ? (\n        <LoaderCircleIcon className=\"animate-spin\" />\n      ) : item.invalid ? (\n        <TriangleAlertIcon />\n      ) : item.completed ? (\n        <CheckIcon />\n      ) : (\n        (children ?? item.step)\n      )}\n    </span>\n  )\n}\n\nfunction StepperTitle({ className, ...props }: React.ComponentProps<\"span\">) {\n  const { orientation } = useStepperContext()\n  const item = useStepperItem()\n  return (\n    <span\n      data-slot=\"stepper-title\"\n      data-state={item.state}\n      className={cn(\n        \"block text-sm leading-5 font-medium text-foreground transition-colors data-[state=inactive]:text-muted-foreground data-[state=invalid]:text-destructive\",\n        orientation === \"horizontal\" ? \"self-center whitespace-nowrap\" : \"flex min-h-8 items-center\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction StepperDescription({ className, ...props }: React.ComponentProps<\"span\">) {\n  const { orientation } = useStepperContext()\n  const item = useStepperItem()\n  return (\n    <span\n      data-slot=\"stepper-description\"\n      data-state={item.state}\n      className={cn(\n        \"col-start-2 block text-muted-foreground\",\n        orientation === \"horizontal\" ? \"self-start text-xs leading-4 whitespace-nowrap\" : \"-mt-1 text-sm\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/** The line from this step to the next; filled once this step is completed. Hidden on the last step. */\nfunction StepperSeparator({ className, ...props }: React.ComponentProps<\"span\">) {\n  const { orientation } = useStepperContext()\n  const item = useStepperItem()\n  return (\n    <span\n      aria-hidden=\"true\"\n      data-slot=\"stepper-separator\"\n      data-state={item.completed ? \"completed\" : \"pending\"}\n      className={cn(\n        \"rounded-full bg-border transition-colors group-last/stepper-item:hidden data-[state=completed]:bg-primary\",\n        orientation === \"horizontal\" ? \"h-0.5 min-w-6 flex-1\" : \"absolute start-[calc(--spacing(4)-1px)] top-10 bottom-2 w-0.5\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\n/** What shows under the current step in a vertical stepper. Renders only while its step is current. */\nfunction StepperContent({ className, ...props }: React.ComponentProps<\"div\">) {\n  const item = useStepperItem()\n  if (!item.active) return null\n  return <div data-slot=\"stepper-content\" className={cn(\"ps-11 pt-3\", className)} {...props} />\n}\n\nexport {\n  Stepper,\n  StepperContent,\n  StepperDescription,\n  StepperIndicator,\n  StepperItem,\n  StepperSeparator,\n  StepperTitle,\n  StepperTrigger,\n  useStepper,\n}\n"
    }
  ],
  "docs": "Stepper is in components/ui. Examples: https://dresscodeui.com/components/stepper"
}
