{
  "name": "onboarding",
  "type": "registry:block",
  "framework": "react",
  "title": "Onboarding",
  "description": "A short setup flow: a stepper, the current step's content and the buttons that move through it.",
  "registryDependencies": [
    "@newtui/stepper",
    "@newtui/button"
  ],
  "files": [
    {
      "path": "blocks/onboarding/onboarding.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { Button } from \"@/registry/bases/newt/ui/button\"\nimport { Stepper, type StepperStep } from \"@/registry/bases/newt/ui/stepper\"\n\n/** The wording of the three buttons. */\nexport interface OnboardingLabels {\n  back: string\n  next: string\n  finish: string\n}\n\nexport interface OnboardingProps extends Omit<\n  React.ComponentProps<\"section\">,\n  \"children\" | \"onChange\"\n> {\n  steps: readonly StepperStep[]\n  /** Index of the step being shown. Leave undefined to let the block own it. */\n  step?: number\n  defaultStep?: number\n  onStepChange?: (step: number) => void\n  /** Called when the last step's button is pressed. */\n  onComplete?: () => void\n  /** Whether the current step may be left. Defaults to yes. */\n  canContinue?: boolean\n  labels?: OnboardingLabels\n  /** The content of the step whose index it is given. */\n  children: (step: number) => React.ReactNode\n}\n\nconst defaultLabels: OnboardingLabels = {\n  back: \"Back\",\n  next: \"Next\",\n  finish: \"Finish\",\n}\n\n/*\n * A short setup flow: where you are in it, the current step's own content,\n * and the two buttons that move through it. The content is a function of the\n * step, so each step stays an ordinary component of yours and the block only\n * owns the order. Moving to another step moves focus to its heading, so a\n * screen reader starts from the new content.\n */\nexport function Onboarding({\n  steps,\n  step,\n  defaultStep = 0,\n  onStepChange,\n  onComplete,\n  canContinue = true,\n  labels = defaultLabels,\n  className,\n  children,\n  ...props\n}: OnboardingProps) {\n  const [internal, setInternal] = React.useState(defaultStep)\n  const current = Math.min(step ?? internal, steps.length - 1)\n  const last = current === steps.length - 1\n  const heading = React.useRef<HTMLHeadingElement | null>(null)\n  const moved = React.useRef(false)\n\n  React.useEffect(() => {\n    if (moved.current) heading.current?.focus()\n  }, [current])\n\n  const goTo = (next: number) => {\n    moved.current = true\n    if (step === undefined) setInternal(next)\n    onStepChange?.(next)\n  }\n\n  return (\n    <section\n      className={cn(\n        \"flex w-full flex-col gap-6 rounded-[var(--newt-radius-lg)] border border-newt-border bg-newt-bg-surface p-6\",\n        className\n      )}\n      {...props}\n    >\n      <Stepper steps={steps} value={current} />\n      <div className=\"flex flex-col gap-4\">\n        <h2\n          ref={heading}\n          tabIndex={-1}\n          className=\"m-0 text-lg font-semibold leading-6 text-newt-text-primary focus:outline-none\"\n        >\n          {steps[current]?.title}\n        </h2>\n        {children(current)}\n      </div>\n      <div className=\"flex justify-between gap-2\">\n        <Button\n          variant=\"secondary\"\n          disabled={current === 0}\n          onClick={() => goTo(current - 1)}\n        >\n          {labels.back}\n        </Button>\n        <Button\n          disabled={!canContinue}\n          onClick={() => {\n            if (last) onComplete?.()\n            else goTo(current + 1)\n          }}\n        >\n          {last ? labels.finish : labels.next}\n        </Button>\n      </div>\n    </section>\n  )\n}\n",
      "type": "registry:block"
    }
  ]
}