{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stepper12",
  "title": "Stepper",
  "description": "Stepper built with shadcn/ui.",
  "dependencies": [
    "@base-ui/react@1",
    "lucide-react@0"
  ],
  "files": [
    {
      "path": "contents/components/stepper/12/index.tsx",
      "content": "\"use client\";\n\nimport { CheckIcon } from \"lucide-react\";\n\nimport {\n  Stepper,\n  StepperContent,\n  StepperDescription,\n  StepperIndicator,\n  StepperItem,\n  StepperNav,\n  StepperPanel,\n  StepperSeparator,\n  StepperTitle,\n  StepperTrigger,\n} from \"@/components/ui/stepper\";\n\nconst steps = [\n  {\n    title: \"Order placed\",\n    description: \"We received your order\",\n    detail: \"Order #4821 was confirmed on Oct 2 at 10:24 AM.\",\n  },\n  {\n    title: \"Packed\",\n    description: \"Your items are boxed\",\n    detail: \"Your package is ready at the Austin warehouse.\",\n  },\n  {\n    title: \"Shipped\",\n    description: \"On the way to you\",\n    detail: \"Estimated delivery is Friday, Oct 6.\",\n  },\n];\n\nexport default function StepperDemo() {\n  return (\n    <Stepper\n      defaultValue={2}\n      orientation=\"vertical\"\n      className=\"flex w-auto flex-col items-center gap-10 sm:flex-row sm:items-start\"\n      indicators={{ completed: <CheckIcon className=\"size-3.5\" /> }}\n    >\n      <StepperNav>\n        {steps.map((step, index) => (\n          <StepperItem\n            key={step.title}\n            step={index + 1}\n            className=\"relative items-start\"\n          >\n            <StepperTrigger className=\"items-start gap-3 rounded-md pb-10 text-left group-last/step:pb-0\">\n              <StepperIndicator>{index + 1}</StepperIndicator>\n              <div className=\"mt-0.5 flex flex-col gap-1\">\n                <StepperTitle>{step.title}</StepperTitle>\n                <StepperDescription className=\"text-xs\">\n                  {step.description}\n                </StepperDescription>\n              </div>\n            </StepperTrigger>\n            {steps.length > index + 1 && (\n              <StepperSeparator className=\"group-data-[state=completed]/step:bg-primary absolute top-7 left-3 m-0 -translate-x-1/2 group-data-[orientation=vertical]/stepper-nav:h-[calc(100%-2rem)]\" />\n            )}\n          </StepperItem>\n        ))}\n      </StepperNav>\n\n      <StepperPanel className=\"w-56 text-center text-sm sm:text-left\">\n        {steps.map((step, index) => (\n          <StepperContent\n            key={step.title}\n            value={index + 1}\n            className=\"text-muted-foreground\"\n          >\n            {step.detail}\n          </StepperContent>\n        ))}\n      </StepperPanel>\n    </Stepper>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/stepper12.tsx"
    },
    {
      "path": "components/ui/stepper.tsx",
      "content": "\"use client\";\n\nimport { mergeProps } from \"@base-ui/react/merge-props\";\nimport { useRender } from \"@base-ui/react/use-render\";\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\ntype StepperOrientation = \"horizontal\" | \"vertical\";\ntype StepState = \"active\" | \"completed\" | \"inactive\" | \"loading\";\ntype StepIndicators = {\n  active?: React.ReactNode;\n  completed?: React.ReactNode;\n  inactive?: React.ReactNode;\n  loading?: React.ReactNode;\n};\n\ntype StepperContextValue = {\n  id: string;\n  activeStep: number;\n  setActiveStep: (step: number) => void;\n  orientation: StepperOrientation;\n  indicators: StepIndicators;\n  registerTrigger: (node: HTMLButtonElement | null) => void;\n  triggerNodes: HTMLButtonElement[];\n};\n\ntype StepItemContextValue = {\n  step: number;\n  state: StepState;\n  isDisabled: boolean;\n  isLoading: boolean;\n};\n\nconst StepperContext = React.createContext<StepperContextValue | undefined>(\n  undefined,\n);\nconst StepItemContext = React.createContext<StepItemContextValue | undefined>(\n  undefined,\n);\n\nfunction useStepper() {\n  const context = React.useContext(StepperContext);\n  if (!context) {\n    throw new Error(\"useStepper must be used within a Stepper\");\n  }\n  return context;\n}\n\nfunction useStepItem() {\n  const context = React.useContext(StepItemContext);\n  if (!context) {\n    throw new Error(\"useStepItem must be used within a StepperItem\");\n  }\n  return context;\n}\n\ninterface StepperProps extends React.ComponentProps<\"div\"> {\n  defaultValue?: number;\n  value?: number;\n  onValueChange?: (value: number) => void;\n  orientation?: StepperOrientation;\n  indicators?: StepIndicators;\n}\n\nfunction Stepper({\n  defaultValue = 1,\n  value,\n  onValueChange,\n  orientation = \"horizontal\",\n  indicators = {},\n  className,\n  ...props\n}: StepperProps) {\n  const [internalStep, setInternalStep] = React.useState(defaultValue);\n  const [triggerNodes, setTriggerNodes] = React.useState<HTMLButtonElement[]>(\n    [],\n  );\n\n  const registerTrigger = React.useCallback(\n    (node: HTMLButtonElement | null) => {\n      if (!node) return;\n      setTriggerNodes((prev) => {\n        if (prev.includes(node)) return prev;\n        // Keep DOM order so arrow keys move to the visually next step.\n        return [...prev, node].sort((a, b) =>\n          a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING\n            ? -1\n            : 1,\n        );\n      });\n    },\n    [],\n  );\n\n  const setActiveStep = React.useCallback(\n    (step: number) => {\n      if (value === undefined) {\n        setInternalStep(step);\n      }\n      onValueChange?.(step);\n    },\n    [value, onValueChange],\n  );\n\n  const id = React.useId();\n  const activeStep = value ?? internalStep;\n\n  const contextValue = React.useMemo<StepperContextValue>(\n    () => ({\n      id,\n      activeStep,\n      setActiveStep,\n      orientation,\n      indicators,\n      registerTrigger,\n      triggerNodes,\n    }),\n    [\n      id,\n      activeStep,\n      setActiveStep,\n      orientation,\n      indicators,\n      registerTrigger,\n      triggerNodes,\n    ],\n  );\n\n  return (\n    <StepperContext.Provider value={contextValue}>\n      <div\n        data-slot=\"stepper\"\n        data-orientation={orientation}\n        className={cn(\"w-full\", className)}\n        {...props}\n      />\n    </StepperContext.Provider>\n  );\n}\n\ninterface StepperItemProps extends React.ComponentProps<\"div\"> {\n  step: number;\n  completed?: boolean;\n  disabled?: boolean;\n  loading?: boolean;\n}\n\nfunction StepperItem({\n  step,\n  completed = false,\n  disabled = false,\n  loading = false,\n  className,\n  ...props\n}: StepperItemProps) {\n  const { activeStep } = useStepper();\n\n  const state: StepState =\n    completed || step < activeStep\n      ? \"completed\"\n      : activeStep === step\n        ? \"active\"\n        : \"inactive\";\n\n  const isLoading = loading && step === activeStep;\n\n  return (\n    <StepItemContext.Provider\n      value={{ step, state, isDisabled: disabled, isLoading }}\n    >\n      <div\n        data-slot=\"stepper-item\"\n        data-state={state}\n        data-loading={isLoading || undefined}\n        className={cn(\n          \"group/step flex items-center justify-center not-last:flex-1 group-data-[orientation=horizontal]/stepper-nav:flex-row group-data-[orientation=vertical]/stepper-nav:flex-col\",\n          className,\n        )}\n        {...props}\n      />\n    </StepItemContext.Provider>\n  );\n}\n\ntype StepperTriggerProps = useRender.ComponentProps<\"button\">;\n\nfunction StepperTrigger({ className, render, ...props }: StepperTriggerProps) {\n  const { id, activeStep, setActiveStep, registerTrigger, triggerNodes } =\n    useStepper();\n  const { step, state, isDisabled, isLoading } = useStepItem();\n  const ref = React.useRef<HTMLButtonElement>(null);\n  const isSelected = activeStep === step;\n\n  React.useEffect(() => {\n    registerTrigger(ref.current);\n  }, [registerTrigger]);\n\n  const focusAt = (index: number) => {\n    const count = triggerNodes.length;\n    if (count) triggerNodes[(index + count) % count]?.focus();\n  };\n\n  const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {\n    const index = triggerNodes.findIndex((node) => node === ref.current);\n    switch (event.key) {\n      case \"ArrowRight\":\n      case \"ArrowDown\":\n        event.preventDefault();\n        focusAt(index + 1);\n        break;\n      case \"ArrowLeft\":\n      case \"ArrowUp\":\n        event.preventDefault();\n        focusAt(index - 1);\n        break;\n      case \"Home\":\n        event.preventDefault();\n        focusAt(0);\n        break;\n      case \"End\":\n        event.preventDefault();\n        focusAt(triggerNodes.length - 1);\n        break;\n    }\n  };\n\n  return useRender({\n    defaultTagName: \"button\",\n    render,\n    ref,\n    props: mergeProps<\"button\">(\n      {\n        type: \"button\",\n        role: \"tab\",\n        id: `${id}-tab-${step}`,\n        \"aria-selected\": isSelected,\n        \"aria-controls\": `${id}-panel-${step}`,\n        tabIndex: isSelected ? 0 : -1,\n        disabled: isDisabled,\n        onClick: () => setActiveStep(step),\n        onKeyDown: handleKeyDown,\n        className: cn(\n          \"inline-flex cursor-pointer items-center gap-2.5 rounded-full outline-none focus-visible:z-10 focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-60\",\n          className,\n        ),\n      },\n      {\n        \"data-slot\": \"stepper-trigger\",\n        \"data-state\": state,\n        \"data-loading\": isLoading || undefined,\n        ...props,\n      } as React.ComponentProps<\"button\">,\n    ),\n  });\n}\n\nfunction StepperIndicator({\n  className,\n  children,\n  ...props\n}: React.ComponentProps<\"div\">) {\n  const { indicators } = useStepper();\n  const { state, isLoading } = useStepItem();\n\n  const indicator =\n    (isLoading && indicators.loading) ||\n    (state === \"completed\" && indicators.completed) ||\n    (state === \"active\" && indicators.active) ||\n    (state === \"inactive\" && indicators.inactive) ||\n    children;\n\n  return (\n    <div\n      data-slot=\"stepper-indicator\"\n      data-state={state}\n      className={cn(\n        \"bg-muted text-muted-foreground data-[state=active]:bg-primary data-[state=active]:text-primary-foreground data-[state=completed]:bg-primary data-[state=completed]:text-primary-foreground relative flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-full text-xs font-medium\",\n        className,\n      )}\n      {...props}\n    >\n      <div className=\"absolute flex items-center justify-center\">\n        {indicator}\n      </div>\n    </div>\n  );\n}\n\nfunction StepperSeparator({\n  className,\n  ...props\n}: React.ComponentProps<\"div\">) {\n  const { state } = useStepItem();\n\n  return (\n    <div\n      data-slot=\"stepper-separator\"\n      data-state={state}\n      className={cn(\n        \"bg-muted m-0.5 rounded-full group-data-[orientation=horizontal]/stepper-nav:h-0.5 group-data-[orientation=horizontal]/stepper-nav:flex-1 group-data-[orientation=vertical]/stepper-nav:h-12 group-data-[orientation=vertical]/stepper-nav:w-0.5\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nfunction StepperTitle({ className, ...props }: React.ComponentProps<\"h3\">) {\n  const { state } = useStepItem();\n\n  return (\n    <h3\n      data-slot=\"stepper-title\"\n      data-state={state}\n      className={cn(\"text-sm leading-none font-medium\", className)}\n      {...props}\n    />\n  );\n}\n\nfunction StepperDescription({\n  className,\n  ...props\n}: React.ComponentProps<\"p\">) {\n  const { state } = useStepItem();\n\n  return (\n    <p\n      data-slot=\"stepper-description\"\n      data-state={state}\n      className={cn(\"text-muted-foreground text-sm\", className)}\n      {...props}\n    />\n  );\n}\n\nfunction StepperNav({ className, ...props }: React.ComponentProps<\"nav\">) {\n  const { activeStep, orientation } = useStepper();\n\n  return (\n    <nav\n      role=\"tablist\"\n      aria-orientation={orientation}\n      data-slot=\"stepper-nav\"\n      data-state={activeStep}\n      data-orientation={orientation}\n      className={cn(\n        \"group/stepper-nav inline-flex data-[orientation=horizontal]:w-full data-[orientation=horizontal]:flex-row data-[orientation=vertical]:flex-col\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nfunction StepperPanel({ className, ...props }: React.ComponentProps<\"div\">) {\n  const { activeStep } = useStepper();\n\n  return (\n    <div\n      data-slot=\"stepper-panel\"\n      data-state={activeStep}\n      className={cn(\"w-full\", className)}\n      {...props}\n    />\n  );\n}\n\ninterface StepperContentProps extends React.ComponentProps<\"div\"> {\n  value: number;\n  forceMount?: boolean;\n}\n\nfunction StepperContent({\n  value,\n  forceMount = false,\n  className,\n  ...props\n}: StepperContentProps) {\n  const { id, activeStep } = useStepper();\n  const isActive = value === activeStep;\n\n  if (!forceMount && !isActive) {\n    return null;\n  }\n\n  return (\n    <div\n      role=\"tabpanel\"\n      id={`${id}-panel-${value}`}\n      aria-labelledby={`${id}-tab-${value}`}\n      data-slot=\"stepper-content\"\n      data-state={isActive ? \"active\" : \"inactive\"}\n      hidden={!isActive}\n      className={cn(\"w-full\", className)}\n      {...props}\n    />\n  );\n}\n\nexport {\n  Stepper,\n  StepperContent,\n  StepperDescription,\n  StepperIndicator,\n  StepperItem,\n  StepperNav,\n  StepperPanel,\n  StepperSeparator,\n  StepperTitle,\n  StepperTrigger,\n  useStepItem,\n  useStepper,\n  type StepperContentProps,\n  type StepperItemProps,\n  type StepperProps,\n  type StepperTriggerProps,\n};\n",
      "type": "registry:ui",
      "target": "components/ui/stepper.tsx"
    }
  ],
  "type": "registry:component"
}