{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sign-up-steps",
  "type": "registry:block",
  "title": "Sign Up Steps",
  "description": "Two-step sign-up: account, then workspace, with focus management.",
  "files": [
    {
      "path": "src/registry/blocks/auth/sign-up-steps.tsx",
      "type": "registry:block",
      "content": "\"use client\";\n\nimport {\n  useEffect,\n  useId,\n  useRef,\n  useState,\n  type ChangeEvent,\n  type ComponentProps,\n  type CSSProperties,\n  type FormEvent,\n} from \"react\";\nimport { Eye, EyeOff, Loader2 } from \"lucide-react\";\n\nimport { Button } from \"@/components/ui/button\";\nimport { Input } from \"@/components/ui/input\";\nimport { Label } from \"@/components/ui/label\";\nimport {\n  Select,\n  SelectContent,\n  SelectItem,\n  SelectTrigger,\n  SelectValue,\n} from \"@/components/ui/select\";\nimport { cn } from \"@/lib/utils\";\n\nexport type SignUpStepsValues = {\n  email: string;\n  password: string;\n  workspaceName: string;\n  teamSize: string;\n  role: string;\n};\n\nexport type SignUpStepsOption = { value: string; label: string };\n\nexport type SignUpStepsProps = {\n  /** Headings for step 1 and step 2. */\n  stepTitles?: [string, string];\n  /** Short labels for the step list in the margin. */\n  stepLabels?: [string, string];\n  teamSizes?: SignUpStepsOption[];\n  roles?: SignUpStepsOption[];\n  /** Domain shown after the workspace slug, e.g. \"larch.app\". */\n  workspaceDomain?: string;\n  onSubmit?: (values: SignUpStepsValues) => void | Promise<void>;\n  signInHref?: string;\n  termsHref?: string;\n  /** Wordmark square, progress fill, selected segment and primary button. Defaults to Devsloka blue. */\n  accent?: string;\n  /** Text colour on `accent`. Defaults to white. */\n  accentForeground?: string;\n} & Omit<ComponentProps<\"section\">, \"onSubmit\">;\n\nconst DEFAULTS = {\n  stepTitles: [\"Create your account\", \"Set up your workspace\"] as [string, string],\n  stepLabels: [\"Account\", \"Workspace\"] as [string, string],\n  teamSizes: [\n    { value: \"1\", label: \"Just me\" },\n    { value: \"2-5\", label: \"2–5\" },\n    { value: \"6-15\", label: \"6–15\" },\n    { value: \"16+\", label: \"16+\" },\n  ],\n  roles: [\n    { value: \"researcher\", label: \"Researcher\" },\n    { value: \"designer\", label: \"Designer\" },\n    { value: \"product\", label: \"Product manager\" },\n    { value: \"academic\", label: \"Academic or student\" },\n    { value: \"other\", label: \"Something else\" },\n  ],\n  workspaceDomain: \"larch.app\",\n  accent: \"#0A6EFF\",\n  accentForeground: \"#FFFFFF\",\n};\n\ntype Field = keyof SignUpStepsValues;\ntype Errors = Partial<Record<Field, string>>;\ntype Status = \"idle\" | \"submitting\" | \"success\" | \"error\";\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;\nconst STEP_FIELDS: Record<1 | 2, Field[]> = {\n  1: [\"email\", \"password\"],\n  2: [\"workspaceName\", \"teamSize\", \"role\"],\n};\n\nfunction validate(values: SignUpStepsValues, step: 1 | 2): Errors {\n  const errors: Errors = {};\n  if (step === 1) {\n    const email = values.email.trim();\n    if (!email) errors.email = \"Enter your work email.\";\n    else if (!EMAIL_PATTERN.test(email))\n      errors.email = \"That email looks incomplete. Check for a typo.\";\n    if (!values.password) errors.password = \"Choose a password.\";\n    else if (values.password.length < 12)\n      errors.password = `Use at least 12 characters (${values.password.length} so far).`;\n  } else {\n    if (!values.workspaceName.trim())\n      errors.workspaceName = \"Name the workspace. You can change it later.\";\n    if (!values.teamSize) errors.teamSize = \"Pick the closest team size.\";\n    if (!values.role) errors.role = \"Pick the role closest to yours.\";\n  }\n  return errors;\n}\n\nconst slugify = (value: string) =>\n  value\n    .toLowerCase()\n    .trim()\n    .replace(/[^a-z0-9]+/g, \"-\")\n    .replace(/^-+|-+$/g, \"\")\n    .slice(0, 40);\n\nconst defaultSubmit = () =>\n  new Promise<void>((resolve) => setTimeout(resolve, 900));\n\nconst linkClass =\n  \"rounded-sm font-medium underline decoration-1 underline-offset-4 outline-none hover:decoration-2 focus-visible:ring-2 focus-visible:ring-ring\";\n\nexport function SignUpSteps({\n  stepTitles = DEFAULTS.stepTitles,\n  stepLabels = DEFAULTS.stepLabels,\n  teamSizes = DEFAULTS.teamSizes,\n  roles = DEFAULTS.roles,\n  workspaceDomain = DEFAULTS.workspaceDomain,\n  onSubmit = defaultSubmit,\n  signInHref = \"#\",\n  termsHref = \"#\",\n  accent = DEFAULTS.accent,\n  accentForeground = DEFAULTS.accentForeground,\n  className,\n  style,\n  ...props\n}: SignUpStepsProps) {\n  const id = useId();\n  const headingRef = useRef<HTMLHeadingElement>(null);\n  const navigatedRef = useRef(false);\n  const [step, setStep] = useState<1 | 2>(1);\n  const [values, setValues] = useState<SignUpStepsValues>({\n    email: \"\",\n    password: \"\",\n    workspaceName: \"\",\n    teamSize: \"\",\n    role: \"\",\n  });\n  const [showPassword, setShowPassword] = useState(false);\n  const [errors, setErrors] = useState<Errors>({});\n  const [attempted, setAttempted] = useState<Record<1 | 2, boolean>>({ 1: false, 2: false });\n  const [status, setStatus] = useState<Status>(\"idle\");\n  const [message, setMessage] = useState(\"\");\n\n  const fieldId = (name: Field) => `${id}-${name}`;\n  const errorId = (name: Field) => `${id}-${name}-error`;\n  const submitting = status === \"submitting\";\n  const slug = slugify(values.workspaceName);\n  const done = status === \"success\";\n\n  // Move focus to the new step's heading after Back / Continue (not on first render).\n  useEffect(() => {\n    if (navigatedRef.current) headingRef.current?.focus();\n  }, [step, done]);\n\n  const goTo = (next: 1 | 2) => {\n    navigatedRef.current = true;\n    setErrors({});\n    setStatus(\"idle\");\n    setMessage(\"\");\n    setStep(next);\n  };\n\n  const update = <K extends Field>(name: K, value: SignUpStepsValues[K], revalidateNow = false) => {\n    const next = { ...values, [name]: value };\n    setValues(next);\n    if (revalidateNow && attempted[step])\n      setErrors((current) => ({ ...current, [name]: validate(next, step)[name] }));\n  };\n\n  const revalidate = (name: Field) => {\n    if (attempted[step])\n      setErrors((current) => ({ ...current, [name]: validate(values, step)[name] }));\n  };\n\n  const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {\n    event.preventDefault();\n    setAttempted((current) => ({ ...current, [step]: true }));\n    const nextErrors = validate(values, step);\n    setErrors(nextErrors);\n    const firstInvalid = STEP_FIELDS[step].find((field) => nextErrors[field]);\n    if (firstInvalid) {\n      const target = document.getElementById(fieldId(firstInvalid));\n      // For the radio group, focus the checked radio or the first one.\n      if (target instanceof HTMLFieldSetElement) {\n        target\n          .querySelector<HTMLInputElement>(\"input:checked, input[type=radio]\")\n          ?.focus();\n      } else {\n        target?.focus();\n      }\n      return;\n    }\n\n    if (step === 1) {\n      goTo(2);\n      return;\n    }\n\n    setStatus(\"submitting\");\n    setMessage(\"\");\n    try {\n      await onSubmit({\n        ...values,\n        email: values.email.trim(),\n        workspaceName: values.workspaceName.trim(),\n      });\n      navigatedRef.current = true;\n      setStatus(\"success\");\n      setMessage(`Workspace created at ${slug || \"your-team\"}.${workspaceDomain}.`);\n    } catch (error) {\n      setStatus(\"error\");\n      setMessage(\n        error instanceof Error && error.message\n          ? error.message\n          : \"We couldn't create the workspace just now. Nothing was lost; try again in a moment.\"\n      );\n    }\n  };\n\n  const inputProps = (name: \"email\" | \"password\" | \"workspaceName\") => ({\n    id: fieldId(name),\n    name,\n    value: values[name],\n    \"aria-invalid\": errors[name] ? true : undefined,\n    \"aria-describedby\": errors[name] ? errorId(name) : undefined,\n    onChange: (event: ChangeEvent<HTMLInputElement>) => update(name, event.target.value),\n    onBlur: () => revalidate(name),\n  });\n\n  const errorText = (name: Field) =>\n    errors[name] ? (\n      <p id={errorId(name)} className=\"text-xs text-destructive\">\n        {errors[name]}\n      </p>\n    ) : null;\n\n  const progress = done ? 100 : step === 1 ? 50 : 100;\n\n  return (\n    <section\n      data-slot=\"sign-up-steps\"\n      aria-labelledby={`${id}-title`}\n      style={\n        {\n          \"--block-accent\": accent,\n          \"--block-accent-fg\": accentForeground,\n          ...style,\n        } as CSSProperties\n      }\n      className={cn(\"w-full bg-background text-foreground\", className)}\n      {...props}\n    >\n      <div className=\"mx-auto max-w-6xl px-6 py-16 md:py-24\">\n        <div className=\"grid gap-10 md:grid-cols-12 md:gap-8\">\n          <div className=\"md:col-span-4\">\n            <span className=\"inline-flex items-center gap-2 text-lg font-semibold tracking-tight\">\n              <span aria-hidden=\"true\" className=\"size-2.5 bg-[var(--block-accent)]\" />\n              Larch\n            </span>\n            <ol className=\"mt-10 hidden border-t md:block\">\n              {stepLabels.map((label, index) => {\n                const number = (index + 1) as 1 | 2;\n                const current = !done && number === step;\n                const complete = done || number < step;\n                return (\n                  <li\n                    key={label}\n                    aria-current={current ? \"step\" : undefined}\n                    className={cn(\n                      \"flex items-baseline gap-4 border-b py-3 text-sm\",\n                      current ? \"font-medium text-foreground\" : \"text-muted-foreground\"\n                    )}\n                  >\n                    <span className=\"font-mono text-xs tabular-nums\">0{number}</span>\n                    {label}\n                    {complete ? (\n                      <span className=\"ml-auto font-mono text-[11px] tracking-wider uppercase\">\n                        Done\n                      </span>\n                    ) : null}\n                  </li>\n                );\n              })}\n            </ol>\n            <p className=\"mt-6 hidden max-w-[16rem] text-xs leading-relaxed text-muted-foreground md:block\">\n              Free for up to three people. No card, and you can delete the workspace at any time.\n            </p>\n          </div>\n\n          <div className=\"md:col-span-7 md:col-start-6\">\n            <div className=\"max-w-md\">\n              <div className=\"flex items-baseline justify-between font-mono text-xs tracking-wider text-muted-foreground uppercase\">\n                <span>{done ? \"Complete\" : `Step ${step} of 2`}</span>\n                <span>{done ? \"\" : stepLabels[step - 1]}</span>\n              </div>\n              <div aria-hidden=\"true\" className=\"mt-3 h-0.5 w-full bg-border\">\n                <div\n                  className=\"h-full bg-[var(--block-accent)] transition-[width] duration-300 motion-reduce:transition-none\"\n                  style={{ width: `${progress}%` }}\n                />\n              </div>\n\n              <h2\n                id={`${id}-title`}\n                ref={headingRef}\n                tabIndex={-1}\n                className=\"mt-10 text-3xl font-semibold tracking-[-0.03em] outline-none md:text-4xl\"\n              >\n                {done ? \"Your workspace is ready.\" : stepTitles[step - 1]}\n              </h2>\n\n              {done ? (\n                <div className=\"mt-6\">\n                  <p className=\"text-sm leading-relaxed text-muted-foreground\">\n                    We sent a confirmation to{\" \"}\n                    <span className=\"font-medium text-foreground\">{values.email.trim()}</span>.\n                    Your team can find you at:\n                  </p>\n                  <p className=\"mt-4 border-y py-3 font-mono text-sm\">\n                    {slug || \"your-team\"}.{workspaceDomain}\n                  </p>\n                </div>\n              ) : (\n                <form\n                  noValidate\n                  onSubmit={handleSubmit}\n                  aria-busy={submitting}\n                  className=\"mt-8 grid gap-6\"\n                >\n                  {step === 1 ? (\n                    <>\n                      <div className=\"grid gap-2\">\n                        <Label htmlFor={fieldId(\"email\")}>Work email</Label>\n                        <Input\n                          {...inputProps(\"email\")}\n                          type=\"email\"\n                          autoComplete=\"email\"\n                          inputMode=\"email\"\n                          required\n                        />\n                        {errorText(\"email\")}\n                      </div>\n                      <div className=\"grid gap-2\">\n                        <Label htmlFor={fieldId(\"password\")}>Password</Label>\n                        <div className=\"relative\">\n                          <Input\n                            {...inputProps(\"password\")}\n                            aria-describedby={cn(`${id}-password-hint`, errors.password && errorId(\"password\"))}\n                            type={showPassword ? \"text\" : \"password\"}\n                            autoComplete=\"new-password\"\n                            required\n                            className=\"pr-10\"\n                          />\n                          <button\n                            type=\"button\"\n                            aria-label={showPassword ? \"Hide password\" : \"Show password\"}\n                            onClick={() => setShowPassword((current) => !current)}\n                            className=\"absolute inset-y-0 right-0 flex w-10 items-center justify-center rounded-r-md text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n                          >\n                            {showPassword ? (\n                              <EyeOff aria-hidden=\"true\" className=\"size-4\" />\n                            ) : (\n                              <Eye aria-hidden=\"true\" className=\"size-4\" />\n                            )}\n                          </button>\n                        </div>\n                        <p id={`${id}-password-hint`} className=\"text-xs text-muted-foreground\">\n                          At least 12 characters. A short sentence works well.\n                        </p>\n                        {errorText(\"password\")}\n                      </div>\n                    </>\n                  ) : (\n                    <>\n                      <div className=\"grid gap-2\">\n                        <Label htmlFor={fieldId(\"workspaceName\")}>Workspace name</Label>\n                        <Input\n                          {...inputProps(\"workspaceName\")}\n                          aria-describedby={cn(`${id}-slug`, errors.workspaceName && errorId(\"workspaceName\"))}\n                          autoComplete=\"organization\"\n                          placeholder=\"Field Notes\"\n                          required\n                        />\n                        <p id={`${id}-slug`} className=\"font-mono text-xs text-muted-foreground\">\n                          {slug || \"your-team\"}.{workspaceDomain}\n                        </p>\n                        {errorText(\"workspaceName\")}\n                      </div>\n\n                      <fieldset\n                        id={fieldId(\"teamSize\")}\n                        aria-invalid={errors.teamSize ? true : undefined}\n                        aria-describedby={errors.teamSize ? errorId(\"teamSize\") : undefined}\n                        className=\"grid gap-2\"\n                      >\n                        <legend className=\"mb-2 text-sm leading-none font-medium\">Team size</legend>\n                        <div className=\"grid grid-cols-2 border-t border-l sm:grid-cols-4\">\n                          {teamSizes.map((option) => {\n                            const optionId = `${id}-team-${option.value}`;\n                            return (\n                              <label\n                                key={option.value}\n                                htmlFor={optionId}\n                                className=\"relative cursor-pointer border-r border-b text-center text-sm has-[:checked]:bg-[var(--block-accent)] has-[:checked]:text-[var(--block-accent-fg)] has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring has-[:focus-visible]:ring-inset\"\n                              >\n                                <input\n                                  id={optionId}\n                                  type=\"radio\"\n                                  name=\"teamSize\"\n                                  value={option.value}\n                                  checked={values.teamSize === option.value}\n                                  onChange={() => update(\"teamSize\", option.value, true)}\n                                  className=\"sr-only\"\n                                />\n                                <span className=\"block px-3 py-2.5 tabular-nums\">{option.label}</span>\n                              </label>\n                            );\n                          })}\n                        </div>\n                        {errorText(\"teamSize\")}\n                      </fieldset>\n\n                      <div className=\"grid gap-2\">\n                        <Label htmlFor={fieldId(\"role\")}>Your role</Label>\n                        <Select\n                          name=\"role\"\n                          value={values.role}\n                          onValueChange={(value) => update(\"role\", value, true)}\n                        >\n                          <SelectTrigger\n                            id={fieldId(\"role\")}\n                            aria-invalid={errors.role ? true : undefined}\n                            aria-describedby={errors.role ? errorId(\"role\") : undefined}\n                            className=\"w-full\"\n                          >\n                            <SelectValue placeholder=\"Choose one\" />\n                          </SelectTrigger>\n                          <SelectContent>\n                            {roles.map((role) => (\n                              <SelectItem key={role.value} value={role.value}>\n                                {role.label}\n                              </SelectItem>\n                            ))}\n                          </SelectContent>\n                        </Select>\n                        {errorText(\"role\")}\n                      </div>\n                    </>\n                  )}\n\n                  <div className=\"flex flex-wrap items-center justify-between gap-4 border-t pt-6\">\n                    {step === 2 ? (\n                      <Button\n                        type=\"button\"\n                        variant=\"ghost\"\n                        className=\"rounded-none\"\n                        disabled={submitting}\n                        onClick={() => goTo(1)}\n                      >\n                        Back\n                      </Button>\n                    ) : (\n                      <p className=\"text-xs text-muted-foreground\">\n                        By continuing you accept the{\" \"}\n                        <a href={termsHref} className={linkClass}>\n                          terms\n                        </a>\n                        .\n                      </p>\n                    )}\n                    <Button\n                      type=\"submit\"\n                      size=\"lg\"\n                      disabled={submitting}\n                      className=\"rounded-none bg-[var(--block-accent)] text-[var(--block-accent-fg)] shadow-none hover:bg-[var(--block-accent)] hover:underline hover:underline-offset-4\"\n                    >\n                      {submitting ? (\n                        <>\n                          <Loader2 aria-hidden=\"true\" className=\"animate-spin motion-reduce:animate-none\" />\n                          Creating workspace…\n                        </>\n                      ) : step === 1 ? (\n                        \"Continue\"\n                      ) : (\n                        \"Create workspace\"\n                      )}\n                    </Button>\n                  </div>\n                </form>\n              )}\n\n              <p\n                role=\"status\"\n                aria-live=\"polite\"\n                className={cn(\n                  \"mt-6 text-sm empty:hidden\",\n                  status === \"error\" ? \"border-l-2 border-destructive pl-3 text-destructive\" : \"sr-only\"\n                )}\n              >\n                {status === \"idle\" && !done ? `Step ${step} of 2: ${stepLabels[step - 1]}` : message}\n              </p>\n\n              {!done ? (\n                <p className=\"mt-10 text-sm text-muted-foreground\">\n                  Already have an account?{\" \"}\n                  <a href={signInHref} className={cn(linkClass, \"text-foreground\")}>\n                    Sign in\n                  </a>\n                </p>\n              ) : null}\n            </div>\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "button",
    "input",
    "label",
    "select"
  ]
}
