{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stepper14",
  "title": "Stepper",
  "description": "Stepper built with shadcn/ui.",
  "dependencies": [
    "@base-ui/react@1",
    "lucide-react@0"
  ],
  "registryDependencies": [
    "button",
    "card",
    "field",
    "input"
  ],
  "files": [
    {
      "path": "contents/components/stepper/14/index.tsx",
      "content": "\"use client\";\n\nimport { useState } from \"react\";\nimport { CheckIcon, PartyPopperIcon } from \"lucide-react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport {\n  Card,\n  CardContent,\n  CardDescription,\n  CardFooter,\n  CardHeader,\n  CardTitle,\n} from \"@/components/ui/card\";\nimport { Field, FieldGroup, FieldLabel } from \"@/components/ui/field\";\nimport { Input } from \"@/components/ui/input\";\nimport {\n  Stepper,\n  StepperContent,\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: \"Account\",\n    description: \"Tell us who you are.\",\n    fields: [\n      { id: \"name\", label: \"Full name\", placeholder: \"Alex Morgan\" },\n      {\n        id: \"email\",\n        label: \"Email\",\n        placeholder: \"alex@acme.com\",\n        type: \"email\",\n      },\n    ],\n  },\n  {\n    title: \"Workspace\",\n    description: \"Set up a home for your team.\",\n    fields: [\n      { id: \"workspace\", label: \"Workspace name\", placeholder: \"Acme Inc.\" },\n      { id: \"url\", label: \"Workspace URL\", placeholder: \"acme\" },\n    ],\n  },\n  {\n    title: \"Invite\",\n    description: \"Bring your teammates along.\",\n    fields: [\n      {\n        id: \"invite\",\n        label: \"Teammate email\",\n        placeholder: \"sam@acme.com\",\n        type: \"email\",\n      },\n    ],\n  },\n];\n\nexport default function StepperDemo() {\n  const [currentStep, setCurrentStep] = useState(1);\n  const isDone = currentStep > steps.length;\n  const isLast = currentStep === steps.length;\n  const step = steps[currentStep - 1] ?? {\n    title: \"You are all set\",\n    description: \"Your workspace is ready to use.\",\n  };\n\n  return (\n    <Card className=\"w-full max-w-md\">\n      <Stepper\n        value={currentStep}\n        onValueChange={setCurrentStep}\n        className=\"flex flex-col gap-6\"\n        indicators={{ completed: <CheckIcon className=\"size-3.5\" /> }}\n      >\n        <CardHeader className=\"gap-6\">\n          <StepperNav>\n            {steps.map((item, index) => (\n              <StepperItem key={item.title} step={index + 1}>\n                <StepperTrigger className=\"gap-2 rounded-md\">\n                  <StepperIndicator>{index + 1}</StepperIndicator>\n                  <StepperTitle className=\"group-data-[state=inactive]/step:text-muted-foreground max-sm:hidden\">\n                    {item.title}\n                  </StepperTitle>\n                </StepperTrigger>\n                {steps.length > index + 1 && (\n                  <StepperSeparator className=\"group-data-[state=completed]/step:bg-primary mx-2.5\" />\n                )}\n              </StepperItem>\n            ))}\n          </StepperNav>\n          <div className=\"flex flex-col gap-1.5\">\n            <CardTitle>{step.title}</CardTitle>\n            <CardDescription>{step.description}</CardDescription>\n          </div>\n        </CardHeader>\n\n        <CardContent>\n          <StepperPanel>\n            {steps.map((item, index) => (\n              <StepperContent key={item.title} value={index + 1}>\n                <FieldGroup>\n                  {item.fields.map((field) => (\n                    <Field key={field.id}>\n                      <FieldLabel htmlFor={field.id}>{field.label}</FieldLabel>\n                      <Input\n                        id={field.id}\n                        type={field.type ?? \"text\"}\n                        placeholder={field.placeholder}\n                      />\n                    </Field>\n                  ))}\n                </FieldGroup>\n              </StepperContent>\n            ))}\n            <StepperContent\n              value={steps.length + 1}\n              className=\"flex flex-col items-center gap-3 py-6 text-center\"\n            >\n              <div className=\"bg-muted flex size-12 items-center justify-center rounded-full\">\n                <PartyPopperIcon className=\"size-5\" />\n              </div>\n              <p className=\"text-muted-foreground text-sm\">\n                We sent the invites. Your teammates will get an email shortly.\n              </p>\n            </StepperContent>\n          </StepperPanel>\n        </CardContent>\n\n        <CardFooter className=\"justify-between gap-2\">\n          {isDone ? (\n            <Button\n              variant=\"outline\"\n              className=\"w-full\"\n              onClick={() => setCurrentStep(1)}\n            >\n              Start over\n            </Button>\n          ) : (\n            <>\n              <Button\n                variant=\"outline\"\n                onClick={() => setCurrentStep((prev) => prev - 1)}\n                disabled={currentStep === 1}\n              >\n                Back\n              </Button>\n              <Button onClick={() => setCurrentStep((prev) => prev + 1)}>\n                {isLast ? \"Create workspace\" : \"Continue\"}\n              </Button>\n            </>\n          )}\n        </CardFooter>\n      </Stepper>\n    </Card>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/stepper14.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"
}