Onboarding survey
Post-signup personalization survey with one question per step as numbered option cards and a summary confirmation screen.
pnpm dlx shadcn@latest add @haze/onboarding-survey---
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>When to use
- 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
When not to use
- Collecting multi-field text and URL inputs; use multi-step-form
Installation
Add the Haze registry to components.json once, then install Onboarding survey with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/onboarding-surveynpx shadcn@latest add @haze/onboarding-surveyyarn dlx shadcn@latest add @haze/onboarding-surveybunx --bun shadcn@latest add @haze/onboarding-surveyFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | "haze-onboarding-survey" | Unique prefix for section heading IDs. |
| class | string | – | Extra classes on the outer section. |
Keyboard interactions
- Tab
- Move across option cards, Back button and final Launch button
- EnterSpace
- Choose an answer, go back or finish personalization
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.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
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": "http://localhost:4329/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: http://localhost:4329/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.
Dependencies
- npm: @lucide/astro
- @haze/kbd
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.