# Onboarding survey

> Post-signup personalization survey with one question per step as numbered option cards and a summary confirmation screen.

- Kind: block · Category: Settings · Interactivity: script
- Install: `npx shadcn@latest add @haze/onboarding-survey`
- File: `src/components/haze/blocks/onboarding-survey.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/kbd, @haze/utils
- Docs page: https://hazeui.com/blocks/onboarding-survey

## Use when
- Tailoring a new workspace's starter templates based on role and primary goal
- Presenting fast single-click option cards with clear step progression and Back navigation

## Avoid when
- Collecting multi-field text and URL inputs; use multi-step-form

## Alternatives
- [choice-card](https://hazeui.com/ui/choice-card.md)
- [multi-step-form](https://hazeui.com/blocks/multi-step-form.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` | "haze-onboarding-survey" | no | Unique prefix for section heading IDs. |
| class | `string` |  | no | Extra classes on the outer section. |

## Accessibility
- Option cards are full-width native buttons paired with sculpted keycap indicators and announce each selection via role="status".
- Users can step backward at any point to revise previous answers before launching.
- Key Tab: Move across option cards, Back button and final Launch button
- Key Enter / Space: Choose an answer, go back or finish personalization

## Agent prompts

### Install and use

Install the Haze UI block "Onboarding survey" with `npx shadcn@latest add @haze/onboarding-survey`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import OnboardingSurvey from "@/components/haze/blocks/onboarding-survey.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/blocks/onboarding-survey.md

### Customize with real content

Adapt the Haze onboarding-survey block for our product. Replace the demo values of these props with our real content: id, class. Keep the layout, the heading level rules and these accessibility details: Option cards are full-width native buttons paired with sculpted keycap indicators and announce each selection via role="status". Users can step backward at any point to revise previous answers before launching. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using onboarding-survey, check it fits: use it when tailoring a new workspace's starter templates based on role and primary goal; presenting fast single-click option cards with clear step progression and back navigation. Avoid it when collecting multi-field text and url inputs; use multi-step-form. Alternatives: @haze/choice-card, @haze/multi-step-form.

## Example requests that should lead here
- Create a post-signup onboarding survey with large numbered option cards and a final starter-kit summary

## Source

```astro
---
import { ArrowLeft, Check, Sparkles } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
import Kbd from "../ui/kbd.astro";

interface Props {
  id?: string;
  class?: string;
}

const { id = "haze-onboarding-survey", class: className } = Astro.props;

const questions = [
  {
    key: "role",
    prompt: "What best describes your role?",
    options: ["Frontend / Full-stack engineer", "Design systems lead", "Product founder", "AI / platform engineer"],
  },
  {
    key: "goal",
    prompt: "What are you shipping first?",
    options: ["Marketing site & docs", "SaaS workspace & settings", "AI chat & agent flows", "Internal admin tools"],
  },
] as const;
---

<section aria-labelledby={`${id}-title`} data-haze-onb-survey class={cn("bg-background px-4 py-10 sm:px-6 sm:py-14", className)}>
  <div class="mx-auto max-w-xl rounded-2xl border border-border bg-card p-6 shadow-float sm:p-8">
    <header class="flex items-center justify-between gap-2">
      <span class="inline-flex items-center gap-1.5 text-xs font-medium text-muted-foreground">
        <Sparkles class="size-3.5" aria-hidden="true" />
        Personalize your workspace
      </span>
      <span data-os-step class="font-mono text-xs text-muted-foreground tabular-nums">1 / 3</span>
    </header>

    {
      questions.map((q, qi) => (
        <div data-os-pane={String(qi)} hidden={qi !== 0} class="mt-4">
          <h2 id={qi === 0 ? `${id}-title` : undefined} class="text-xl/7 font-semibold tracking-tight text-foreground">{q.prompt}</h2>
          <p class="mt-1 text-xs/5 text-muted-foreground">Click an option or press keys 1–4.</p>
          <ul role="list" class="mt-4 grid gap-2">
            {
              q.options.map((opt, oi) => (
                <li>
                  <button
                    type="button"
                    data-os-pick={opt}
                    data-os-key={q.key}
                    data-os-num={String(oi + 1)}
                    class="flex w-full cursor-pointer items-center justify-between gap-3 rounded-xl border border-border bg-muted/40 px-4 py-3 text-left text-sm/5 font-medium text-foreground transition-colors duration-150 hover:border-border-strong hover:bg-accent focus-visible:outline-2 focus-visible:outline-ring active:scale-[0.97] active:duration-75"
                  >
                    <span>{opt}</span>
                    <Kbd size="sm">{String(oi + 1)}</Kbd>
                  </button>
                </li>
              ))
            }
          </ul>
        </div>
      ))
    }

    <div data-os-pane="2" hidden class="mt-4 space-y-4">
      <h3 class="text-xl/7 font-semibold tracking-tight text-foreground">Your starter kit is ready</h3>
      <dl class="divide-y divide-border rounded-xl border border-border bg-muted/40 text-xs">
        <div class="flex justify-between gap-3 px-4 py-3"><dt class="text-muted-foreground">Role</dt><dd data-os-ans="role" class="font-medium text-foreground">Not selected</dd></div>
        <div class="flex justify-between gap-3 px-4 py-3"><dt class="text-muted-foreground">First project</dt><dd data-os-ans="goal" class="font-medium text-foreground">Not selected</dd></div>
      </dl>
      <button type="button" data-os-finish class="inline-flex h-10 w-full cursor-pointer items-center justify-center gap-1.5 rounded-lg bg-primary text-sm font-medium text-primary-foreground hover:opacity-90 focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
        <Check class="size-4" aria-hidden="true" />
        Launch personalized workspace
      </button>
    </div>

    <footer class="mt-5 flex items-center justify-between gap-2 border-t border-border pt-4">
      <button type="button" data-os-back disabled class="inline-flex h-8 cursor-pointer items-center gap-1 rounded-lg border border-frame bg-field px-2.5 text-xs font-medium text-foreground hover:bg-accent disabled:cursor-not-allowed disabled:opacity-45 focus-visible:outline-2 focus-visible:outline-ring transition-[background-color,border-color,color,opacity,scale] duration-150 ease-snappy active:scale-[0.97] active:duration-75">
        <ArrowLeft class="size-3.5" aria-hidden="true" />
        Back
      </button>
      <p data-os-status role="status" class="text-xs/4 text-muted-foreground"></p>
    </footer>
  </div>
</section>

<script>
  function initOnbSurveys() {
    document.querySelectorAll<HTMLElement>("[data-haze-onb-survey]").forEach((root) => {
      if (root.hasAttribute("data-enhanced")) return;
      root.setAttribute("data-enhanced", "");
      const panes = Array.from(root.querySelectorAll<HTMLElement>("[data-os-pane]"));
      const stepEl = root.querySelector<HTMLElement>("[data-os-step]");
      const back = root.querySelector<HTMLButtonElement>("[data-os-back]");
      const status = root.querySelector<HTMLElement>("[data-os-status]");
      let step = 0;

      const render = (msg?: string) => {
        panes.forEach((p, i) => (p.hidden = i !== step));
        if (stepEl) stepEl.textContent = `${step + 1} / 3`;
        if (back) back.disabled = step === 0;
        if (status && msg) status.textContent = msg;
      };

      root.querySelectorAll<HTMLButtonElement>("[data-os-pick]").forEach((btn) => {
        btn.addEventListener("click", () => {
          const k = btn.dataset.osKey!;
          const v = btn.dataset.osPick!;
          const target = root.querySelector<HTMLElement>(`[data-os-ans="${k}"]`);
          if (target) target.textContent = v;
          step = Math.min(2, step + 1);
          render(`Selected "${v}".`);
        });
      });

      back?.addEventListener("click", () => { if (step > 0) { step--; render(`Returned to step ${step + 1}.`); } });
      root.querySelector<HTMLButtonElement>("[data-os-finish]")?.addEventListener("click", () => render("Workspace personalized and ready."));
    });
  }
  initOnbSurveys();
  document.addEventListener("astro:page-load", initOnbSurveys);
</script>
```
