Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(quill): add Questionnaire primitive (#81787)

Adam Leitha2861fc3efde
diff --git a/packages/quill/packages/primitives/AGENTS.md b/packages/quill/packages/primitives/AGENTS.md
index 7c81c94a0812..e07c4ff4f8b8 100644
--- a/packages/quill/packages/primitives/AGENTS.md
+++ b/packages/quill/packages/primitives/AGENTS.md
@@ -112,6 +112,8 @@ For a custom menu-like list inside a Popover (when DropdownMenu's open/close sem
Always wrap form controls in `Field` (see Composition Patterns below).
+For a run of questions asked one at a time — an agent needing a few decisions before it can carry on — use `Questionnaire` rather than stacking Fields yourself; it owns the ordering, progress, validation, and navigation. See its section below.
+
### Text
| Component | Use when |
@@ -879,6 +881,53 @@ The list holds no state: `value`/`total` are the app's count, and nothing is inf
</ChatTaskList>
```
+### Questionnaire (a run of questions, one at a time)
+
+The form an agent puts up when it needs the user to decide before it can carry on.
+Behavior comes from the headless `@shadcn/react/questionnaire` engine, which owns ordering, the active item, answers, validation, progress, navigation, and the answer shortcuts.
+Everything else stays the surrounding surface's: closing, persistence, transport, and branching.
+
+Define the questions once and pass them as `items`, then map the same array into the parts — `items` is what lets the engine render the active question, the progress, the actions, and the shortcut keys on the first paint.
+Answers come back through `FormData` on submit: `get(name)` for one, `getAll(name)` for a `multiple` item.
+Skipped items don't appear at all.
+
+```tsx
+<Questionnaire items={questions} onSubmit={handleSubmit}>
+ <QuestionnaireProgress />
+ {questions.map((question) => (
+ <QuestionnaireItem key={question.name} name={question.name} required={question.required}>
+ <QuestionnaireTitle>{question.prompt}</QuestionnaireTitle>
+ <QuestionnaireDescription>{question.description}</QuestionnaireDescription>
+ <QuestionnaireChoices>
+ {question.choices.map((choice) => (
+ <QuestionnaireChoice key={choice.value} value={choice.value}>
+ {choice.label}
+ <QuestionnaireChoiceDescription>{choice.description}</QuestionnaireChoiceDescription>
+ </QuestionnaireChoice>
+ ))}
+ <QuestionnaireInput aria-label="Another answer" placeholder="Type another answer…" />
+ </QuestionnaireChoices>
+ <QuestionnaireError />
+ </QuestionnaireItem>
+ ))}
+ <QuestionnaireActions>
+ <QuestionnairePrevious />
+ <QuestionnaireSkip />
+ <QuestionnaireNext />
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+</Questionnaire>
+```
+
+- **`QuestionnaireChoice` assembles its own row** — the overlaid native radio/checkbox, the indicator, the label, and the shortcut key. Write only the answer's text; add `QuestionnaireChoiceDescription` for a muted second line. `multiple` on the item swaps radios for checkboxes and the indicator's dot for a check.
+- **`QuestionnaireInput` always needs an accessible name.** A placeholder is not a label — pass `aria-label` or point `aria-labelledby` at a visible one. It shares the item's `name`, so typing in it replaces whatever choice was picked. It renders as an `InputGroup` wearing a choice's indicator, filled once there's text and tinted like a picked row — the indicator takes its shape from the choices beside it, round for radios and square for checkboxes. Pass `render` to replace the whole row.
+- **`QuestionnaireActions` is layout only** — a three-column row that pins Previous to the start and hugs Skip and Next/Submit to the end, so buttons don't move as they appear and disappear. It holds no state.
+- **Branching is the app's.** A question that no longer applies gets `disabled`, which drops it out of the order, the progress count, and the validation pass. Same for controlled navigation: pass `item`/`onItemChange` to send the user back to a question that failed the app's own checks, and `invalid` plus `QuestionnaireError` children to say why.
+- Only the active item is visible — the engine hides and inerts the rest, so every question stays mounted and keeps its answer. Don't unmount them yourself.
+- `shortcuts="letters"` / `"numbers"` puts a key on each answer. Picking by key doesn't advance; typing in a text field pauses them.
+- **Tabs across the top are the same controlled navigation**, for a short run the user should see whole before committing: hold the active question's name in state, pass it as both the root's `item` and the `Tabs` `value`, and take `onItemChange` and `onValueChange` back into it. Read each item's `onStatusChange` to show a check in its tab — keep the icon mounted and `invisible` until the answer lands, tinted `text-success-foreground`, so the label doesn't shift. Keep the tabs outside the form — inside it they are one more stop between a question and its answers, and their buttons take part in the form. In a `Card` that means the card wraps the questionnaire: tabs in `CardHeader`, then the root with `className="contents"` around `CardContent` and `CardFooter`.
+- Inside a `Dialog`, put `className="contents"` on the root so the header, body, and footer stay in the dialog's own grid (and keep their padding and dividers) while the form still wraps the submit button. Cancel and dismiss remain the dialog's. Drop `QuestionnaireActions` there and put the navigation buttons straight into `DialogFooter` next to the `DialogClose`, the way every other dialog does — the footer is already the button row, and nesting the actions grid inside it doubles the gap.
+
### Keyboard Shortcuts
```tsx
diff --git a/packages/quill/packages/primitives/package.json b/packages/quill/packages/primitives/package.json
index a10b79f2d438..decf9c095d90 100644
--- a/packages/quill/packages/primitives/package.json
+++ b/packages/quill/packages/primitives/package.json
@@ -35,7 +35,7 @@
"dependencies": {
"@base-ui/react": "catalog:",
"@posthog/quill-tokens": "workspace:^",
- "@shadcn/react": "^0.1.0",
+ "@shadcn/react": "^0.3.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^0.577.0",
diff --git a/packages/quill/packages/primitives/src/chat/questionnaire.css b/packages/quill/packages/primitives/src/chat/questionnaire.css
new file mode 100644
index 000000000000..ce34339c5d53
--- /dev/null
+++ b/packages/quill/packages/primitives/src/chat/questionnaire.css
@@ -0,0 +1,362 @@
+@layer components {
+ .quill-questionnaire {
+ display: flex;
+ flex-direction: column;
+ gap: 1rem;
+ width: 100%;
+ min-width: 0;
+ }
+
+ /*
+ * Reserves its own line and a fixed measure so `Question 2 of 5` rolling over to `Question 10 of
+ * 12` doesn't shift the item below it.
+ */
+ .quill-questionnaire__progress {
+ width: fit-content;
+ min-width: 14ch;
+ min-height: 1lh;
+ font-size: var(--text-xs, 0.75rem);
+ font-weight: 500;
+ font-variant-numeric: tabular-nums;
+ color: var(--muted-foreground);
+ }
+
+ /* A `fieldset`, stripped of the native chrome — the question's grouping is semantic, not visual. */
+ .quill-questionnaire__item {
+ display: flex;
+ flex-direction: column;
+ gap: 0.75rem;
+ min-width: 0;
+ padding: 0;
+ border: 0;
+ outline: none;
+ }
+
+ /*
+ * The title is the fieldset's `legend`, which sits in the border box rather than the flex flow, so
+ * the item's `gap` never lands under it. A margin does the work instead — but only when no
+ * description follows, since the description is the flex flow's first child and carries the gap.
+ */
+ .quill-questionnaire__title {
+ font-size: var(--text-sm, 0.875rem);
+ font-weight: 500;
+ line-height: 1.375;
+ color: var(--foreground);
+ text-wrap: pretty;
+ }
+
+ .quill-questionnaire__title:not(:has(~ [data-slot='questionnaire-description'])) {
+ margin-block-end: 0.75rem;
+ }
+
+ .quill-questionnaire__description {
+ margin: 0;
+ font-size: var(--text-xs, 0.75rem);
+ line-height: 1.625;
+ color: var(--muted-foreground);
+ text-wrap: pretty;
+ }
+
+ .quill-questionnaire__choices {
+ display: grid;
+ gap: 0.5rem;
+ min-width: 0;
+ }
+
+ /*
+ * A row is a `label` wrapping its own control, so the whole row is the hit target — start-aligned,
+ * because a choice that carries a description is two lines and its indicator belongs beside the
+ * first.
+ */
+ .quill-questionnaire__choice {
+ position: relative;
+ display: flex;
+ gap: 0.5rem;
+ align-items: flex-start;
+ min-width: 0;
+ padding-block: 0.4375rem;
+ padding-inline: 0.5rem;
+ font-size: var(--text-xs, 0.75rem);
+ line-height: 1.375;
+ text-align: start;
+ cursor: pointer;
+ user-select: none;
+ background-color: transparent;
+ border: 1px solid var(--input);
+ border-radius: var(--radius-sm);
+ outline: none;
+ transition:
+ color 0.15s ease,
+ background-color 0.15s ease,
+ border-color 0.15s ease;
+ }
+
+ :is(.dark, [theme='dark']) .quill-questionnaire__choice {
+ background-color: color-mix(in oklab, var(--input) 20%, transparent);
+ }
+
+ .quill-questionnaire__choice:hover {
+ background-color: color-mix(in oklab, var(--muted) 50%, transparent);
+ }
+
+ /*
+ * The native control is the row's only focusable element, and it's invisible — so the row wears its
+ * focus ring on the control's behalf.
+ */
+ .quill-questionnaire__choice:has(> input:focus-visible) {
+ border-color: color-mix(in oklab, var(--ring) 50%, transparent);
+ box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 30%, transparent);
+ }
+
+ .quill-questionnaire__choice[data-checked] {
+ background-color: color-mix(in oklab, var(--success) 30%, transparent);
+ border-color: color-mix(in oklab, var(--success-foreground) 40%, transparent);
+ }
+
+ .quill-questionnaire__choice[data-invalid] {
+ border-color: color-mix(in oklab, var(--destructive-foreground) 30%, transparent);
+ }
+
+ .quill-questionnaire__choice[data-disabled] {
+ pointer-events: none;
+ cursor: not-allowed;
+ opacity: 0.5;
+ }
+
+ /*
+ * Covers the row rather than sitting in it: clicks anywhere land on the real radio/checkbox, so
+ * native selection, form participation, and the arrow-key roving all keep working.
+ */
+ .quill-questionnaire__choice-input {
+ position: absolute;
+ inset: 0;
+ z-index: 10;
+ width: 100%;
+ height: 100%;
+ cursor: pointer;
+ opacity: 0;
+ }
+
+ /*
+ * The visible box. It only mirrors the hidden control's state, so it takes no pointer events —
+ * a click on it is a click on the row.
+ */
+ .quill-questionnaire__choice-indicator {
+ position: relative;
+ display: flex;
+ flex-shrink: 0;
+ align-items: center;
+ justify-content: center;
+ width: 0.875rem;
+ height: 0.875rem;
+ pointer-events: none;
+ border: 1px solid var(--input);
+ border-radius: 3px;
+ }
+
+ :is(.dark, [theme='dark']) .quill-questionnaire__choice-indicator {
+ background-color: color-mix(in oklab, var(--input) 30%, transparent);
+ }
+
+ /* One answer or several is the control's business; the shape is what tells the reader which. */
+ .quill-questionnaire__choice[data-type='radio'] .quill-questionnaire__choice-indicator {
+ border-radius: 9999px;
+ }
+
+ .quill-questionnaire__choice[data-checked] .quill-questionnaire__choice-indicator {
+ color: var(--primary-foreground);
+ background-color: var(--primary);
+ border-color: var(--primary);
+ }
+
+ .quill-questionnaire__choice-indicator-dot,
+ .quill-questionnaire__choice-indicator-check {
+ display: none;
+ }
+
+ .quill-questionnaire__choice[data-checked][data-type='radio'] .quill-questionnaire__choice-indicator-dot {
+ display: block;
+ width: 0.375rem;
+ height: 0.375rem;
+ background-color: var(--primary-foreground);
+ border-radius: 9999px;
+ }
+
+ .quill-questionnaire__choice[data-checked][data-type='checkbox'] .quill-questionnaire__choice-indicator-check {
+ display: block;
+ width: 0.625rem;
+ height: 0.625rem;
+ }
+
+ .quill-questionnaire__choice-label {
+ display: flex;
+ flex: 1;
+ flex-direction: column;
+ gap: 0.0625rem;
+ min-width: 0;
+ font-weight: 500;
+ line-height: 1.375;
+ }
+
+ .quill-questionnaire__choice-description {
+ font-weight: 400;
+ color: var(--muted-foreground);
+ }
+
+ /*
+ * Same geometry and ink as `Kbd`, which is what it is — the key that picks this answer. It isn't a
+ * `Kbd` element because the primitive owns the node, so it borrows `buttonVariants` for the chrome
+ * and only the sizing lives here.
+ */
+ .quill-questionnaire__choice-shortcut {
+ min-width: 1.25rem;
+ padding-inline: 0.25rem;
+ margin-inline-start: auto;
+ font-family: var(--font-q-sans, ui-sans-serif, system-ui, sans-serif);
+ font-weight: 500;
+ line-height: 1;
+ color: var(--muted-foreground);
+ pointer-events: none;
+ user-select: none;
+ border-radius: 0.25rem;
+ }
+
+ /*
+ * A freeform answer sits with the fixed choices rather than after them, so "or write your own" reads
+ * as one more row in the same list.
+ */
+ .quill-questionnaire__input-wrapper {
+ position: relative;
+ width: 100%;
+ min-width: 0;
+ }
+
+ /* Matches a choice row at rest — the group's own fill would read as a heavier row than the others. */
+ .quill-questionnaire__input-wrapper > .quill-questionnaire__input-group {
+ background-color: transparent;
+ }
+
+ :is(.dark, [theme='dark']) .quill-questionnaire__input-wrapper > .quill-questionnaire__input-group {
+ background-color: color-mix(in oklab, var(--input) 20%, transparent);
+ }
+
+ /* Lines the field up with the choices: same indicator offset, same gap before the text. */
+ .quill-questionnaire__input-wrapper
+ .quill-questionnaire__input-group
+ > [data-slot='input-group-addon'][data-align='inline-start'] {
+ padding-inline: 0.5rem 0;
+ }
+
+ .quill-questionnaire__input-wrapper .quill-questionnaire__input-group:has(> [data-align='inline-start']) > input {
+ padding-inline-start: 0.5rem;
+ }
+
+ /*
+ * The engine's input keeps its own `data-slot`, so the group's control-scoped focus rule can't see
+ * it — the row wears the ring itself, the way a choice row does for its overlaid control.
+ */
+ .quill-questionnaire__input-wrapper .quill-questionnaire__input-group:has(> input:focus-visible) {
+ border-color: color-mix(in oklab, var(--ring) 50%, transparent);
+ box-shadow: 0 0 0 3px color-mix(in oklab, var(--ring) 30%, transparent);
+ }
+
+ /* Outranks the dark rule above it, which would otherwise hold the neutral fill under the tint. */
+ .quill-questionnaire__input-wrapper > .quill-questionnaire__input-group[data-filled] {
+ background-color: color-mix(in oklab, var(--success) 20%, transparent);
+ border-color: color-mix(in oklab, var(--success-foreground) 40%, transparent);
+ }
+
+ .quill-questionnaire__input-indicator {
+ position: relative;
+ display: flex;
+ flex-shrink: 0;
+ align-items: center;
+ justify-content: center;
+ width: 0.875rem;
+ height: 0.875rem;
+ pointer-events: none;
+ border: 1px solid var(--input);
+ border-radius: 9999px;
+ }
+
+ :is(.dark, [theme='dark']) .quill-questionnaire__input-indicator {
+ background-color: color-mix(in oklab, var(--input) 30%, transparent);
+ }
+
+ /* The field has no control of its own, so the shape comes from the answers it sits with. */
+ .quill-questionnaire__choices:has([data-type='checkbox']) .quill-questionnaire__input-indicator {
+ border-radius: 3px;
+ }
+
+ .quill-questionnaire__input-group[data-filled] .quill-questionnaire__input-indicator {
+ color: var(--primary-foreground);
+ background-color: var(--primary);
+ border-color: var(--primary);
+ }
+
+ .quill-questionnaire__input-indicator-dot,
+ .quill-questionnaire__input-indicator-check {
+ display: none;
+ }
+
+ .quill-questionnaire__input-group[data-filled] .quill-questionnaire__input-indicator-dot {
+ display: block;
+ width: 0.375rem;
+ height: 0.375rem;
+ background-color: var(--primary-foreground);
+ border-radius: 9999px;
+ }
+
+ .quill-questionnaire__choices:has([data-type='checkbox'])
+ .quill-questionnaire__input-group[data-filled]
+ .quill-questionnaire__input-indicator-dot {
+ display: none;
+ }
+
+ .quill-questionnaire__choices:has([data-type='checkbox'])
+ .quill-questionnaire__input-group[data-filled]
+ .quill-questionnaire__input-indicator-check {
+ display: block;
+ width: 0.625rem;
+ height: 0.625rem;
+ }
+
+ .quill-questionnaire__error {
+ font-size: var(--text-xs, 0.75rem);
+ line-height: 1.625;
+ color: var(--destructive-foreground);
+ }
+
+ /*
+ * Three columns — a stretchy one, then two that hug — so Previous stays pinned to the start while
+ * Skip and Next hug the end and don't move when the other appears. `min-height` holds the row open
+ * on the first and last items, where some of those buttons aren't rendered at all.
+ */
+ .quill-questionnaire__actions {
+ display: grid;
+ grid-template-columns: minmax(0, 1fr) auto auto;
+ gap: 0.5rem;
+ align-items: center;
+ width: 100%;
+ min-height: 1.75rem;
+ }
+
+ .quill-questionnaire__previous {
+ grid-row-start: 1;
+ grid-column-start: 1;
+ justify-self: start;
+ }
+
+ .quill-questionnaire__skip {
+ grid-row-start: 1;
+ grid-column-start: 2;
+ justify-self: end;
+ }
+
+ .quill-questionnaire__next,
+ .quill-questionnaire__submit {
+ grid-row-start: 1;
+ grid-column-start: 3;
+ justify-self: end;
+ }
+}
diff --git a/packages/quill/packages/primitives/src/chat/questionnaire.stories.tsx b/packages/quill/packages/primitives/src/chat/questionnaire.stories.tsx
new file mode 100644
index 000000000000..a7c81de28ab6
--- /dev/null
+++ b/packages/quill/packages/primitives/src/chat/questionnaire.stories.tsx
@@ -0,0 +1,735 @@
+import type { Meta, StoryObj } from '@storybook/react'
+import { CheckIcon } from 'lucide-react'
+import * as React from 'react'
+
+import { Button } from '../button'
+import { Card, CardContent, CardDescription, CardFooter, CardHeader } from '../card'
+import {
+ Dialog,
+ DialogBody,
+ DialogClose,
+ DialogContent,
+ DialogFooter,
+ DialogHeader,
+ DialogTitle,
+ DialogTrigger,
+} from '../dialog'
+import { cn } from '../lib/utils'
+import { Progress } from '../progress'
+import { Tabs, TabsList, TabsTrigger } from '../tabs'
+import { Text } from '../text'
+import {
+ Questionnaire,
+ QuestionnaireActions,
+ QuestionnaireChoice,
+ QuestionnaireChoiceDescription,
+ QuestionnaireChoices,
+ QuestionnaireDescription,
+ QuestionnaireError,
+ QuestionnaireInput,
+ QuestionnaireItem,
+ QuestionnaireNext,
+ QuestionnairePrevious,
+ QuestionnaireProgress,
+ QuestionnaireSkip,
+ QuestionnaireSubmit,
+ QuestionnaireTitle,
+ type QuestionnaireItemStatus,
+} from './questionnaire'
+
+const meta: Meta<typeof Questionnaire> = {
+ title: 'Primitives/Chat/Questionnaire',
+ component: Questionnaire,
+ tags: ['autodocs'],
+}
+
+export default meta
+type Story = StoryObj<typeof meta>
+
+type Question = {
+ name: string
+ prompt: string
+ description?: string
+ required?: boolean
+ disabled?: boolean
+ multiple?: boolean
+ choices: readonly { value: string; label: string; description?: string; disabled?: boolean }[]
+ input?: { label: string; placeholder: string }
+}
+
+const QUESTIONS: readonly Question[] = [
+ {
+ name: 'direction',
+ required: true,
+ prompt: 'What should we prototype next?',
+ description: 'Choose a direction or write your own.',
+ choices: [
+ { value: 'delegation', label: 'Delegation', description: 'Show how work moves to a specialist.' },
+ { value: 'questions', label: 'Question prompts', description: 'Show choices while the interface waits.' },
+ { value: 'both', label: 'Both together' },
+ ],
+ input: { label: 'Another answer', placeholder: 'Type another answer…' },
+ },
+ {
+ name: 'detail',
+ prompt: 'How much detail should it include?',
+ description: 'Skip this if you are not sure yet.',
+ choices: [
+ { value: 'focused', label: 'Focused' },
+ { value: 'complete', label: 'Complete flow' },
+ ],
+ },
+]
+
+/**
+ * The whole run of questions, mapped from one collection. `items` is what lets the engine render the
+ * active item, the progress, the actions, and the shortcut keys on the first paint rather than after
+ * a client-side pass.
+ */
+function Questions({
+ questions,
+ onStatusChange,
+}: {
+ questions: readonly Question[]
+ onStatusChange?: (name: string, status: QuestionnaireItemStatus) => void
+}): React.ReactElement {
+ return (
+ <>
+ {questions.map((question) => (
+ <QuestionnaireItem
+ key={question.name}
+ name={question.name}
+ required={question.required}
+ disabled={question.disabled}
+ multiple={question.multiple}
+ onStatusChange={onStatusChange ? (status) => onStatusChange(question.name, status) : undefined}
+ >
+ <QuestionnaireTitle>{question.prompt}</QuestionnaireTitle>
+ {question.description ? (
+ <QuestionnaireDescription>{question.description}</QuestionnaireDescription>
+ ) : null}
+ <QuestionnaireChoices>
+ {question.choices.map((choice) => (
+ <QuestionnaireChoice key={choice.value} value={choice.value} disabled={choice.disabled}>
+ {choice.label}
+ {choice.description ? (
+ <QuestionnaireChoiceDescription>
+ {choice.description}
+ </QuestionnaireChoiceDescription>
+ ) : null}
+ </QuestionnaireChoice>
+ ))}
+ {question.input ? (
+ <QuestionnaireInput
+ aria-label={question.input.label}
+ placeholder={question.input.placeholder}
+ />
+ ) : null}
+ </QuestionnaireChoices>
+ <QuestionnaireError />
+ </QuestionnaireItem>
+ ))}
+ </>
+ )
+}
+
+/** Reads the answers back out of the form the way an app would, so the stories can show them. */
+function readAnswers(form: HTMLFormElement, questions: readonly Question[]): Record<string, string[]> {
+ const data = new FormData(form)
+ return Object.fromEntries(questions.map((question) => [question.name, data.getAll(question.name).map(String)]))
+}
+
+function Answers({ answers }: { answers: Record<string, string[]> | null }): React.ReactElement | null {
+ if (!answers) {
+ return null
+ }
+ return (
+ <Text size="xs" variant="muted" render={<pre />}>
+ {JSON.stringify(answers, null, 2)}
+ </Text>
+ )
+}
+
+/**
+ * The default shape: progress on top, one question at a time, navigation pinned to the bottom row.
+ * Answers arrive through `FormData` on submit — the engine never holds them for the app.
+ */
+export const Default: Story = {
+ render: () => {
+ function Demo(): React.ReactElement {
+ const [answers, setAnswers] = React.useState<Record<string, string[]> | null>(null)
+
+ return (
+ <div className="flex w-full max-w-sm flex-col gap-4">
+ <Questionnaire
+ items={QUESTIONS}
+ onSubmit={(event) => {
+ event.preventDefault()
+ setAnswers(readAnswers(event.currentTarget, QUESTIONS))
+ }}
+ >
+ <QuestionnaireProgress />
+ <Questions questions={QUESTIONS} />
+ <QuestionnaireActions>
+ <QuestionnairePrevious />
+ <QuestionnaireSkip />
+ <QuestionnaireNext />
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+ </Questionnaire>
+ <Answers answers={answers} />
+ </div>
+ )
+ }
+ return <Demo />
+ },
+}
+
+const MULTIPLE: readonly Question[] = [
+ {
+ name: 'signals',
+ required: true,
+ multiple: true,
+ prompt: 'Which signals should the agent watch?',
+ description: 'Pick as many as apply.',
+ choices: [
+ { value: 'errors', label: 'Errors', description: 'New and reopened exceptions.' },
+ { value: 'latency', label: 'Latency', description: 'Slow endpoints and queries.' },
+ { value: 'spend', label: 'Spend', description: 'Cost per user and per model.' },
+ { value: 'churn', label: 'Churn risk' },
+ ],
+ },
+]
+
+/** `multiple` swaps the radios for checkboxes, and the answer comes back as a list. */
+export const MultipleSelection: Story = {
+ render: () => (
+ <div className="w-full max-w-sm">
+ <Questionnaire items={MULTIPLE}>
+ <QuestionnaireProgress />
+ <Questions questions={MULTIPLE} />
+ <QuestionnaireActions>
+ <QuestionnairePrevious />
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+ </Questionnaire>
+ </div>
+ ),
+}
+
+const FREEFORM: readonly Question[] = [
+ {
+ name: 'audience',
+ required: true,
+ prompt: 'Who is this dashboard for?',
+ description: 'Choose an audience or describe your own.',
+ choices: [
+ { value: 'engineering', label: 'Engineering' },
+ { value: 'growth', label: 'Growth' },
+ { value: 'support', label: 'Support' },
+ ],
+ input: { label: 'Another audience', placeholder: 'Describe the audience…' },
+ },
+]
+
+/**
+ * The freeform field sits inside the choices rather than after them, so "or write your own" reads as
+ * one more row. It shares the item's name, so typing in it replaces whatever choice was picked.
+ */
+export const FreeformAnswer: Story = {
+ render: () => (
+ <div className="w-full max-w-sm">
+ <Questionnaire items={FREEFORM}>
+ <QuestionnaireProgress />
+ <Questions questions={FREEFORM} />
+ <QuestionnaireActions>
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+ </Questionnaire>
+ </div>
+ ),
+}
+
+const OPTIONAL: readonly Question[] = [
+ {
+ name: 'scope',
+ required: true,
+ prompt: 'What should the migration cover?',
+ choices: [
+ { value: 'schema', label: 'Schema only' },
+ { value: 'schema-data', label: 'Schema and data' },
+ ],
+ },
+ {
+ name: 'window',
+ prompt: 'When should it run?',
+ description: 'Skip this and we will pick the next quiet window.',
+ choices: [
+ { value: 'now', label: 'As soon as it is ready' },
+ { value: 'overnight', label: 'Overnight' },
+ ],
+ },
+]
+
+/**
+ * An optional item still has to be resolved — answered or skipped — before navigation moves on, so
+ * "no answer" is a decision the transcript records rather than a gap.
+ */
+export const ExplicitSkip: Story = {
+ render: () => (
+ <div className="w-full max-w-sm">
+ <Questionnaire items={OPTIONAL} defaultItem="window">
+ <QuestionnaireProgress />
+ <Questions questions={OPTIONAL} />
+ <QuestionnaireActions>
+ <QuestionnairePrevious />
+ <QuestionnaireSkip />
+ <QuestionnaireNext />
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+ </Questionnaire>
+ </div>
+ ),
+}
+
+/** `shortcuts` puts a key on every answer — `letters` for A–Z, `numbers` for 1–9. */
+export const Shortcuts: Story = {
+ render: () => {
+ function Demo(): React.ReactElement {
+ const [mode, setMode] = React.useState<'letters' | 'numbers' | undefined>('letters')
+
+ return (
+ <div className="flex w-full max-w-sm flex-col gap-4">
+ <div className="flex gap-2">
+ <Button variant={mode === undefined ? 'primary' : 'outline'} onClick={() => setMode(undefined)}>
+ None
+ </Button>
+ <Button variant={mode === 'letters' ? 'primary' : 'outline'} onClick={() => setMode('letters')}>
+ Letters
+ </Button>
+ <Button variant={mode === 'numbers' ? 'primary' : 'outline'} onClick={() => setMode('numbers')}>
+ Numbers
+ </Button>
+ </div>
+ <Questionnaire items={MULTIPLE} shortcuts={mode}>
+ <QuestionnaireProgress />
+ <Questions questions={MULTIPLE} />
+ <QuestionnaireActions>
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+ </Questionnaire>
+ </div>
+ )
+ }
+ return <Demo />
+ },
+}
+
+/**
+ * Controlled navigation: the app owns which item is active, so it can send the user back to one that
+ * failed its own checks and put the reason under it.
+ */
+export const CustomValidation: Story = {
+ render: () => {
+ function Demo(): React.ReactElement {
+ const [item, setItem] = React.useState('scope')
+ const [error, setError] = React.useState<string | null>(null)
+
+ return (
+ <div className="w-full max-w-sm">
+ <Questionnaire
+ items={OPTIONAL}
+ item={item}
+ onItemChange={setItem}
+ onSubmit={(event) => {
+ event.preventDefault()
+ const answers = readAnswers(event.currentTarget, OPTIONAL)
+ // Data migrations can't run in the quiet window, so this pair is invalid together.
+ if (answers.scope[0] === 'schema-data' && answers.window[0] === 'overnight') {
+ setError('Data migrations need a supervised window. Run it as soon as it is ready.')
+ setItem('window')
+ return
+ }
+ setError(null)
+ }}
+ >
+ <QuestionnaireProgress />
+ {OPTIONAL.map((question) => (
+ <QuestionnaireItem
+ key={question.name}
+ name={question.name}
+ required={question.required}
+ invalid={question.name === 'window' && error !== null}
+ >
+ <QuestionnaireTitle>{question.prompt}</QuestionnaireTitle>
+ {question.description ? (
+ <QuestionnaireDescription>{question.description}</QuestionnaireDescription>
+ ) : null}
+ <QuestionnaireChoices>
+ {question.choices.map((choice) => (
+ <QuestionnaireChoice key={choice.value} value={choice.value}>
+ {choice.label}
+ </QuestionnaireChoice>
+ ))}
+ </QuestionnaireChoices>
+ <QuestionnaireError>
+ {question.name === 'window' && error ? error : undefined}
+ </QuestionnaireError>
+ </QuestionnaireItem>
+ ))}
+ <QuestionnaireActions>
+ <QuestionnairePrevious />
+ <QuestionnaireSkip />
+ <QuestionnaireNext />
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+ </Questionnaire>
+ </div>
+ )
+ }
+ return <Demo />
+ },
+}
+
+/**
+ * A partly-filled run picked back up: `defaultItem` restores where the user left off and the choices
+ * carry `defaultChecked` for what they had already answered.
+ */
+export const Resume: Story = {
+ render: () => (
+ <div className="w-full max-w-sm">
+ <Questionnaire items={OPTIONAL} defaultItem="window">
+ <QuestionnaireProgress />
+ {OPTIONAL.map((question) => (
+ <QuestionnaireItem key={question.name} name={question.name} required={question.required}>
+ <QuestionnaireTitle>{question.prompt}</QuestionnaireTitle>
+ <QuestionnaireChoices>
+ {question.choices.map((choice) => (
+ <QuestionnaireChoice
+ key={choice.value}
+ value={choice.value}
+ defaultChecked={question.name === 'scope' && choice.value === 'schema'}
+ >
+ {choice.label}
+ </QuestionnaireChoice>
+ ))}
+ </QuestionnaireChoices>
+ <QuestionnaireError />
+ </QuestionnaireItem>
+ ))}
+ <QuestionnaireActions>
+ <QuestionnairePrevious />
+ <QuestionnaireSkip />
+ <QuestionnaireNext />
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+ </Questionnaire>
+ </div>
+ ),
+}
+
+/**
+ * Branching is the app's, not the engine's: a question that no longer applies is `disabled`, which
+ * drops it out of the order, the progress count, and the validation pass.
+ */
+export const ConditionalItems: Story = {
+ render: () => {
+ function Demo(): React.ReactElement {
+ const [scope, setScope] = React.useState<string | null>(null)
+ const questions: readonly Question[] = [
+ OPTIONAL[0],
+ // Only worth asking about a window once data is in scope.
+ { ...OPTIONAL[1], disabled: scope !== 'schema-data' },
+ ]
+
+ return (
+ <div className="flex w-full max-w-sm flex-col gap-4">
+ <Questionnaire items={questions}>
+ <QuestionnaireProgress />
+ {questions.map((question) => (
+ <QuestionnaireItem
+ key={question.name}
+ name={question.name}
+ required={question.required}
+ disabled={question.disabled}
+ >
+ <QuestionnaireTitle>{question.prompt}</QuestionnaireTitle>
+ <QuestionnaireChoices>
+ {question.choices.map((choice) => (
+ <QuestionnaireChoice
+ key={choice.value}
+ value={choice.value}
+ onChange={
+ question.name === 'scope'
+ ? (event) => setScope(event.currentTarget.value)
+ : undefined
+ }
+ >
+ {choice.label}
+ </QuestionnaireChoice>
+ ))}
+ </QuestionnaireChoices>
+ <QuestionnaireError />
+ </QuestionnaireItem>
+ ))}
+ <QuestionnaireActions>
+ <QuestionnairePrevious />
+ <QuestionnaireSkip />
+ <QuestionnaireNext />
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+ </Questionnaire>
+ <Text size="xs" variant="muted">
+ {scope === 'schema-data'
+ ? 'Two questions — the window question applies.'
+ : 'One question — the window question is out of the run.'}
+ </Text>
+ </div>
+ )
+ }
+ return <Demo />
+ },
+}
+
+/** Every navigation action exposes its state, so an app can word or gate them itself. */
+export const NavigationState: Story = {
+ render: () => (
+ <div className="w-full max-w-sm">
+ <Questionnaire items={QUESTIONS}>
+ <QuestionnaireProgress />
+ <Questions questions={QUESTIONS} />
+ <QuestionnaireActions>
+ <QuestionnairePrevious>Back</QuestionnairePrevious>
+ <QuestionnaireSkip>Not now</QuestionnaireSkip>
+ <QuestionnaireNext
+ render={(props, state) => (
+ <Button {...props} variant="primary" disabled={state.status === 'unanswered'} />
+ )}
+ >
+ Continue
+ </QuestionnaireNext>
+ <QuestionnaireSubmit>Start building</QuestionnaireSubmit>
+ </QuestionnaireActions>
+ </Questionnaire>
+ </div>
+ ),
+}
+
+/** The progress part hands over `current`/`total`, so it can be a bar instead of a line of text. */
+export const CustomProgress: Story = {
+ render: () => (
+ <div className="w-full max-w-sm">
+ <Questionnaire items={QUESTIONS}>
+ {/*
+ * The wrapper keeps the named progressbar and its `Question 1 of 2` value text, so the
+ * bar inside is decoration for the same number and is hidden from screen readers.
+ */}
+ <QuestionnaireProgress
+ className="w-full min-w-0"
+ render={(props, state) => (
+ <div {...props}>
+ <Progress aria-hidden="true" value={(state.current / state.total) * 100} />
+ </div>
+ )}
+ />
+ <Questions questions={QUESTIONS} />
+ <QuestionnaireActions>
+ <QuestionnairePrevious />
+ <QuestionnaireSkip />
+ <QuestionnaireNext />
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+ </Questionnaire>
+ </div>
+ ),
+}
+
+/** Each question carries a short label for its tab, which the prompt is too long to be. */
+type TabbedQuestion = Question & { tab: string }
+
+const TABBED: readonly TabbedQuestion[] = [
+ {
+ name: 'source',
+ tab: 'Source',
+ required: true,
+ prompt: 'Where should the data come from?',
+ choices: [
+ { value: 'warehouse', label: 'Data warehouse' },
+ { value: 'events', label: 'Product events' },
+ ],
+ },
+ {
+ name: 'schedule',
+ tab: 'Schedule',
+ required: true,
+ prompt: 'How often should it sync?',
+ choices: [
+ { value: 'hourly', label: 'Every hour' },
+ { value: 'daily', label: 'Once a day' },
+ { value: 'weekly', label: 'Once a week' },
+ ],
+ },
+ {
+ name: 'owner',
+ tab: 'Owner',
+ prompt: 'Who should own it?',
+ description: 'Skip this and it stays unassigned.',
+ choices: [
+ { value: 'me', label: 'Me' },
+ { value: 'team', label: 'The whole team' },
+ ],
+ input: { label: 'Someone else', placeholder: 'Name someone else…' },
+ },
+]
+
+/**
+ * Tabs as the way through the run: the whole set of questions is visible up front and any of them can
+ * be answered in any order, which suits a short run the user is meant to survey before committing.
+ *
+ * The tabs and the questionnaire stay in step because both read the same `item` state — the engine's
+ * own navigation moves it, and so does a tab. Each tab's check comes from the item's
+ * `onStatusChange`, so it appears on `answered` and stays hidden for a question that was skipped.
+ *
+ * The tabs sit outside the form, which is why the card wraps the questionnaire rather than the other
+ * way round. Inside the form they would be one more thing to tab through between the question and its
+ * answers, and their buttons would take part in the form.
+ */
+export const TabbedNavigation: Story = {
+ render: () => {
+ function Demo(): React.ReactElement {
+ const [item, setItem] = React.useState(TABBED[0].name)
+ const [statuses, setStatuses] = React.useState<Record<string, QuestionnaireItemStatus>>({})
+
+ return (
+ <div className="w-full max-w-sm">
+ <Card className="pt-2" size="sm">
+ <CardHeader className="border-b px-2">
+ <Tabs value={item} onValueChange={(value) => setItem(String(value))}>
+ <TabsList variant="line">
+ {TABBED.map((question) => {
+ const answered = statuses[question.name] === 'answered'
+ return (
+ <TabsTrigger
+ key={question.name}
+ value={question.name}
+ className={cn(answered ? 'bg-success/20' : '')}
+ >
+ {/* `invisible` rather than absent, so the label doesn't shift when it lands. */}
+ <CheckIcon
+ aria-hidden="true"
+ className={
+ answered ? 'text-success-foreground' : 'text-foreground/20'
+ }
+ />
+ <span className={cn(answered ? 'text-success-foreground' : '')}>
+ {question.tab}
+ </span>
+ <span className="sr-only">
+ {answered ? ', answered' : ', unanswered'}
+ </span>
+ </TabsTrigger>
+ )
+ })}
+ </TabsList>
+ </Tabs>
+ </CardHeader>
+ {/* `contents` hands the card's content and footer back to the card's own layout. */}
+ <Questionnaire
+ className="contents"
+ items={TABBED}
+ item={item}
+ onItemChange={setItem}
+ onSubmit={(event) => event.preventDefault()}
+ >
+ <CardContent className="flex flex-col gap-4">
+ <Questions
+ questions={TABBED}
+ onStatusChange={(name, status) =>
+ setStatuses((current) => ({ ...current, [name]: status }))
+ }
+ />
+ </CardContent>
+ <CardFooter>
+ <QuestionnaireActions>
+ <QuestionnairePrevious />
+ <QuestionnaireSkip />
+ <QuestionnaireNext />
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+ </CardFooter>
+ </Questionnaire>
+ </Card>
+ </div>
+ )
+ }
+ return <Demo />
+ },
+}
+
+/**
+ * In a card, the card's header carries the framing and the item's title stays the question — the
+ * fieldset's legend is still the thing the reader is answering.
+ */
+export const InCard: Story = {
+ render: () => (
+ <div className="w-full max-w-sm">
+ <Questionnaire items={QUESTIONS}>
+ <Card>
+ <CardHeader>
+ <CardDescription>Two questions, then it starts working.</CardDescription>
+ </CardHeader>
+ <CardContent className="flex flex-col gap-4">
+ <QuestionnaireProgress />
+ <Questions questions={QUESTIONS} />
+ </CardContent>
+ <CardFooter>
+ <QuestionnaireActions>
+ <QuestionnairePrevious />
+ <QuestionnaireSkip />
+ <QuestionnaireNext />
+ <QuestionnaireSubmit />
+ </QuestionnaireActions>
+ </CardFooter>
+ </Card>
+ </Questionnaire>
+ </div>
+ ),
+}
+
+/**
+ * In a dialog, cancelling and dismissing stay the dialog's — the questionnaire only owns getting from
+ * the first question to the last.
+ */
+export const InDialog: Story = {
+ render: () => (
+ <Dialog>
+ <DialogTrigger render={<Button variant="primary" />}>Set up agent</DialogTrigger>
+ <DialogContent>
+ {/*
+ * `contents` hands the header, body, and footer straight to the dialog's own grid, so
+ * they keep their padding and dividers while the form still wraps the submit button.
+ */}
+ <Questionnaire items={QUESTIONS} className="contents">
+ <DialogHeader>
+ <DialogTitle>Set up your first agent</DialogTitle>
+ </DialogHeader>
+ <DialogBody viewportClassName="flex flex-col gap-4">
+ <QuestionnaireProgress />
+ <Questions questions={QUESTIONS} />
+ </DialogBody>
+ {/*
+ * No `QuestionnaireActions` here — the footer is already the button row, and
+ * nesting the actions grid inside it doubles the gap between Cancel and Next.
+ */}
+ <DialogFooter>
+ <DialogClose render={<Button variant="outline" />}>Cancel</DialogClose>
+ <QuestionnairePrevious />
+ <QuestionnaireSkip />
+ <QuestionnaireNext />
+ <QuestionnaireSubmit />
+ </DialogFooter>
+ </Questionnaire>
+ </DialogContent>
+ </Dialog>
+ ),
+}
diff --git a/packages/quill/packages/primitives/src/chat/questionnaire.tsx b/packages/quill/packages/primitives/src/chat/questionnaire.tsx
new file mode 100644
index 000000000000..5daa0244ee78
--- /dev/null
+++ b/packages/quill/packages/primitives/src/chat/questionnaire.tsx
@@ -0,0 +1,347 @@
+import './questionnaire.css'
+
+import {
+ Questionnaire as QuestionnairePrimitive,
+ type QuestionnaireChoiceDefinition,
+ type QuestionnaireInputType,
+ type QuestionnaireItemDefinition,
+ type QuestionnaireItemStatus,
+ type QuestionnaireShortcutMode,
+} from '@shadcn/react/questionnaire'
+import { CheckIcon } from 'lucide-react'
+import * as React from 'react'
+
+import { Button, buttonVariants } from '../button'
+import { InputGroup, InputGroupAddon, InputGroupInput } from '../input-group'
+import { cn } from '../lib/utils'
+
+/**
+ * A run of questions asked one at a time — the form an agent puts up when it needs the user to
+ * decide before it can carry on. Quill wrapper over the headless `@shadcn/react/questionnaire`
+ * engine, which owns ordering, the active item, answers, validation, progress, navigation, and the
+ * answer shortcuts.
+ *
+ * What the engine leaves to the surface around it: closing, persistence, transport, and branching.
+ * So a questionnaire in a dialog still gets its cancel button from the dialog, and a conditional
+ * question is `disabled` by the app off an earlier answer rather than by a prop here.
+ *
+ * The root is a real `form` and each item a `fieldset` whose legend is the question, so answers come
+ * back through `FormData` — `get(name)` for one, `getAll(name)` for `multiple`. Fixed choices are
+ * native radios and checkboxes under an invisible overlay, which is what keeps arrow-key roving and
+ * form participation working while the whole row stays the hit target.
+ */
+function Questionnaire({
+ className,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Root>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Root
+ data-quill
+ data-slot="questionnaire"
+ className={cn('quill-questionnaire', className)}
+ {...props}
+ />
+ )
+}
+
+/** `Question 2 of 5` by default; pass children to word it differently. */
+function QuestionnaireProgress({
+ className,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Progress>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Progress
+ data-slot="questionnaire-progress"
+ className={cn('quill-questionnaire__progress', className)}
+ {...props}
+ />
+ )
+}
+
+/**
+ * One question. `name` is the key its answer arrives under and must be unique in the root. Only the
+ * active item is rendered visibly — the engine hides and inerts the rest, so all of them can stay
+ * mounted and keep their answers.
+ */
+function QuestionnaireItem({
+ className,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Item>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Item
+ data-slot="questionnaire-item"
+ className={cn('quill-questionnaire__item', className)}
+ {...props}
+ />
+ )
+}
+
+function QuestionnaireTitle({
+ className,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Title>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Title
+ data-slot="questionnaire-title"
+ className={cn('quill-questionnaire__title', className)}
+ {...props}
+ />
+ )
+}
+
+function QuestionnaireDescription({
+ className,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Description>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Description
+ data-slot="questionnaire-description"
+ className={cn('quill-questionnaire__description', className)}
+ {...props}
+ />
+ )
+}
+
+function QuestionnaireChoices({
+ className,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Choices>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Choices
+ data-slot="questionnaire-choices"
+ className={cn('quill-questionnaire__choices', className)}
+ {...props}
+ />
+ )
+}
+
+/**
+ * One fixed answer. The row assembles its own parts — the overlaid control, the indicator, the label
+ * children, and the shortcut key — so a caller only writes the answer's text. The indicator draws
+ * itself off the row's `data-type`: a dot for a radio, a check for a checkbox.
+ */
+function QuestionnaireChoice({
+ children,
+ className,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Choice>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Choice
+ data-slot="questionnaire-choice"
+ className={cn('quill-questionnaire__choice', className)}
+ {...props}
+ >
+ <QuestionnairePrimitive.ChoiceInput
+ data-slot="questionnaire-choice-input"
+ className="quill-questionnaire__choice-input"
+ />
+ <span
+ aria-hidden="true"
+ data-slot="questionnaire-choice-indicator"
+ className="quill-questionnaire__choice-indicator"
+ >
+ <span
+ data-slot="questionnaire-choice-indicator-dot"
+ className="quill-questionnaire__choice-indicator-dot"
+ />
+ <CheckIcon
+ data-slot="questionnaire-choice-indicator-check"
+ className="quill-questionnaire__choice-indicator-check"
+ />
+ </span>
+ <QuestionnairePrimitive.ChoiceLabel
+ data-slot="questionnaire-choice-label"
+ className="quill-questionnaire__choice-label"
+ >
+ {children}
+ </QuestionnairePrimitive.ChoiceLabel>
+ <QuestionnairePrimitive.ChoiceShortcut
+ data-slot="questionnaire-choice-shortcut"
+ className={cn(
+ buttonVariants({ variant: 'outline', size: 'xs' }),
+ 'quill-questionnaire__choice-shortcut'
+ )}
+ />
+ </QuestionnairePrimitive.Choice>
+ )
+}
+
+/** The muted second line of an answer — what picking it means. */
+function QuestionnaireChoiceDescription({ className, ...props }: React.ComponentProps<'span'>): React.ReactElement {
+ return (
+ <span
+ data-slot="questionnaire-choice-description"
+ className={cn('quill-questionnaire__choice-description', className)}
+ {...props}
+ />
+ )
+}
+
+/**
+ * A freeform answer alongside the fixed ones. It takes its `name` from the item, so it competes with
+ * the choices rather than adding to them. It always needs an accessible name — a placeholder is not
+ * a label, so pass `aria-label` or point `aria-labelledby` at a visible one.
+ *
+ * It wears a choice's indicator and fills it once there's text, so the row reads as the answer it is
+ * rather than a field that happens to sit under the answers. The indicator takes its shape from the
+ * choices beside it — round for radios, square for checkboxes.
+ */
+function QuestionnaireInput({
+ className,
+ render,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Input>): React.ReactElement {
+ return (
+ <div data-slot="questionnaire-input-wrapper" className="quill-questionnaire__input-wrapper">
+ <QuestionnairePrimitive.Input
+ data-slot="questionnaire-input"
+ className={className}
+ render={
+ render ??
+ ((inputProps) => (
+ <InputGroup
+ data-slot="questionnaire-input-group"
+ /* Otherwise only the text dims and the indicator stays at full strength. */
+ aria-disabled={inputProps.disabled ? true : undefined}
+ /*
+ * The engine gives the field a `name` only while it is the answer — `filled`
+ * would keep the indicator on after a choice took the answer back off it.
+ */
+ data-filled={inputProps.name !== undefined || undefined}
+ className="quill-questionnaire__input-group"
+ >
+ <InputGroupAddon align="inline-start">
+ <span
+ aria-hidden="true"
+ data-slot="questionnaire-input-indicator"
+ className="quill-questionnaire__input-indicator"
+ >
+ <span className="quill-questionnaire__input-indicator-dot" />
+ <CheckIcon className="quill-questionnaire__input-indicator-check" />
+ </span>
+ </InputGroupAddon>
+ <InputGroupInput {...inputProps} />
+ </InputGroup>
+ ))
+ }
+ {...props}
+ />
+ </div>
+ )
+}
+
+/** The engine's own message by default; pass children for a question-specific one. */
+function QuestionnaireError({
+ className,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Error>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Error
+ data-slot="questionnaire-error"
+ className={cn('quill-questionnaire__error', className)}
+ {...props}
+ />
+ )
+}
+
+/** Layout only — the row Previous, Skip, and Next/Submit sit in. It holds no state. */
+function QuestionnaireActions({ className, ...props }: React.ComponentProps<'div'>): React.ReactElement {
+ return (
+ <div data-slot="questionnaire-actions" className={cn('quill-questionnaire__actions', className)} {...props} />
+ )
+}
+
+function QuestionnairePrevious({
+ children,
+ className,
+ render,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Previous>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Previous
+ data-slot="questionnaire-previous"
+ className={cn('quill-questionnaire__previous', className)}
+ render={render ?? <Button variant="outline" />}
+ {...props}
+ >
+ {children ?? 'Previous'}
+ </QuestionnairePrimitive.Previous>
+ )
+}
+
+function QuestionnaireSkip({
+ children,
+ className,
+ render,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Skip>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Skip
+ data-slot="questionnaire-skip"
+ className={cn('quill-questionnaire__skip', className)}
+ render={render ?? <Button variant="outline" />}
+ {...props}
+ >
+ {children ?? 'Skip'}
+ </QuestionnairePrimitive.Skip>
+ )
+}
+
+function QuestionnaireNext({
+ children,
+ className,
+ render,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Next>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Next
+ data-slot="questionnaire-next"
+ className={cn('quill-questionnaire__next', className)}
+ render={render ?? <Button variant="primary" />}
+ {...props}
+ >
+ {children ?? 'Next'}
+ </QuestionnairePrimitive.Next>
+ )
+}
+
+function QuestionnaireSubmit({
+ children,
+ className,
+ render,
+ ...props
+}: React.ComponentProps<typeof QuestionnairePrimitive.Submit>): React.ReactElement {
+ return (
+ <QuestionnairePrimitive.Submit
+ data-slot="questionnaire-submit"
+ className={cn('quill-questionnaire__submit', className)}
+ render={render ?? <Button variant="primary" />}
+ {...props}
+ >
+ {children ?? 'Submit'}
+ </QuestionnairePrimitive.Submit>
+ )
+}
+
+export {
+ Questionnaire,
+ QuestionnaireActions,
+ QuestionnaireChoice,
+ QuestionnaireChoiceDescription,
+ QuestionnaireChoices,
+ QuestionnaireDescription,
+ QuestionnaireError,
+ QuestionnaireInput,
+ QuestionnaireItem,
+ QuestionnaireNext,
+ QuestionnairePrevious,
+ QuestionnaireProgress,
+ QuestionnaireSkip,
+ QuestionnaireSubmit,
+ QuestionnaireTitle,
+ type QuestionnaireChoiceDefinition,
+ type QuestionnaireInputType,
+ type QuestionnaireItemDefinition,
+ type QuestionnaireItemStatus,
+ type QuestionnaireShortcutMode,
+}
diff --git a/packages/quill/packages/primitives/src/index.ts b/packages/quill/packages/primitives/src/index.ts
index f88b1dcf8249..a463107bda11 100644
--- a/packages/quill/packages/primitives/src/index.ts
+++ b/packages/quill/packages/primitives/src/index.ts
@@ -279,6 +279,28 @@ export {
ProgressValue,
progressIndicatorVariants,
} from './progress'
+export {
+ Questionnaire,
+ QuestionnaireActions,
+ QuestionnaireChoice,
+ QuestionnaireChoiceDescription,
+ QuestionnaireChoices,
+ QuestionnaireDescription,
+ QuestionnaireError,
+ QuestionnaireInput,
+ QuestionnaireItem,
+ QuestionnaireNext,
+ QuestionnairePrevious,
+ QuestionnaireProgress,
+ QuestionnaireSkip,
+ QuestionnaireSubmit,
+ QuestionnaireTitle,
+ type QuestionnaireChoiceDefinition,
+ type QuestionnaireInputType,
+ type QuestionnaireItemDefinition,
+ type QuestionnaireItemStatus,
+ type QuestionnaireShortcutMode,
+} from './chat/questionnaire'
export { RadioGroup, RadioGroupItem, RadioIndicator } from './radio-group'
export { ResizableHandle, ResizablePanel, ResizablePanelGroup } from './resizable'
export { ScrollArea, ScrollBar, scrollShadowsCss, SCROLL_SHADOWS_STYLE_ID } from './scroll-area'
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index af9b5156bdb0..3b4ce998ac82 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -516,7 +516,7 @@ importers:
version: 5.3.0
jest-image-snapshot:
specifier: ^6.4.0
mockdate:
specifier: ^3.0.5
version: 3.0.5
@@ -1970,7 +1970,7 @@ importers:
version: 3.6.0
jest-image-snapshot:
specifier: ^6.4.0
storybook:
specifier: 'catalog:'
@@ -2155,8 +2155,8 @@ importers:
specifier: workspace:^
version: link:../tokens
'@shadcn/react':
- specifier: ^0.1.0
- version: 0.1.0(@types/[email protected])([email protected])
+ specifier: ^0.3.0
+ version: 0.3.0(@types/[email protected])([email protected])
class-variance-authority:
specifier: ^0.7.1
version: 0.7.1
@@ -2390,7 +2390,7 @@ importers:
version: 8.57.0
jest:
specifier: '*'
kea:
specifier: 'catalog:'
version: 4.0.0-pre.6(patch_hash=139b8d1f1304f9d9da452a9a1244c94ea679dbcb85687d8999563146879fb6f5)([email protected])
@@ -3291,7 +3291,7 @@ importers:
version: 2.1.1
jest:
specifier: '*'
kea:
specifier: 'catalog:'
version: 4.0.0-pre.6(patch_hash=139b8d1f1304f9d9da452a9a1244c94ea679dbcb85687d8999563146879fb6f5)([email protected])
@@ -4413,7 +4413,7 @@ importers:
version: 1.2.1
jest:
specifier: '*'
kea:
specifier: 'catalog:'
version: 4.0.0-pre.6(patch_hash=139b8d1f1304f9d9da452a9a1244c94ea679dbcb85687d8999563146879fb6f5)([email protected])
@@ -11048,8 +11048,8 @@ packages:
resolution: {integrity: sha512-YlEBwybUcOQ/KjMHDmof1vwweVnBtBxYlQp7DE3fOdtW4pqqdHWTnTntQs4VgYfxzjJYgtkd9LHlGtg8qy+JVQ==}
engines: {node: '>=14.18'}
- '@shadcn/[email protected]':
- resolution: {integrity: sha512-6i67TEnqValsZY7e4exJ4rkHo2OdHXmDH152YulwSpuEUnTQYumHkXzFsaje7HB7GbMTWuI9x1Jn6sSduCYdeA==}
+ '@shadcn/[email protected]':
+ resolution: {integrity: sha512-iKN0NuYe850VDHlxEfvppFrpa7CMV3zArTHusXlaSmeFeQhohGbIqclv6WwPTs/44I8EkXQpcuRt6sXEVKkWqQ==}
peerDependencies:
'@types/react': 18.3.27
react: 18.3.1
@@ -26706,7 +26706,7 @@ snapshots:
- supports-color
- ts-node
dependencies:
'@jest/console': 30.0.5
'@jest/pattern': 30.0.1
@@ -26721,7 +26721,7 @@ snapshots:
exit-x: 0.2.2
graceful-fs: 4.2.11
jest-changed-files: 30.0.5
jest-haste-map: 30.0.5
jest-message-util: 30.0.5
jest-regex-util: 30.0.1
@@ -26742,7 +26742,7 @@ snapshots:
- supports-color
- ts-node
dependencies:
'@jest/console': 30.0.5
'@jest/pattern': 30.0.1
@@ -26757,7 +26757,7 @@ snapshots:
exit-x: 0.2.2
graceful-fs: 4.2.11
jest-changed-files: 30.0.5
jest-haste-map: 30.0.5
jest-message-util: 30.0.5
jest-regex-util: 30.0.1
@@ -30607,7 +30607,7 @@ snapshots:
'@sentry/[email protected]': {}
optionalDependencies:
'@types/react': 18.3.27
react: 18.3.1
@@ -37912,15 +37912,15 @@ snapshots:
- supports-color
- ts-node
dependencies:
'@jest/test-result': 30.0.5
'@jest/types': 30.0.5
chalk: 4.1.2
exit-x: 0.2.2
import-local: 3.2.0
jest-util: 30.0.5
jest-validate: 30.0.5
yargs: 17.7.2
@@ -37931,15 +37931,15 @@ snapshots:
- supports-color
- ts-node
dependencies:
- '@jest/core': 30.0.5([email protected]([email protected]))
'@jest/test-result': 30.0.5
'@jest/types': 30.0.5
chalk: 4.1.2
exit-x: 0.2.2
import-local: 3.2.0
- jest-config: 30.0.5([email protected]([email protected]))
jest-util: 30.0.5
jest-validate: 30.0.5
yargs: 17.7.2
@@ -38077,7 +38077,7 @@ snapshots:
- babel-plugin-macros
- supports-color
dependencies:
'@babel/core': 7.29.0
'@jest/get-type': 30.0.1
@@ -38106,11 +38106,12 @@ snapshots:
optionalDependencies:
'@types/node': 22.18.8
esbuild-register: 3.6.0([email protected])
transitivePeerDependencies:
- babel-plugin-macros
- supports-color
dependencies:
'@babel/core': 7.29.0
'@jest/get-type': 30.0.1
@@ -38139,7 +38140,7 @@ snapshots:
optionalDependencies:
'@types/node': 22.18.8
esbuild-register: 3.6.0([email protected])
transitivePeerDependencies:
- babel-plugin-macros
- supports-color
@@ -38177,7 +38178,7 @@ snapshots:
- babel-plugin-macros
- supports-color
dependencies:
'@babel/core': 7.29.0
'@jest/get-type': 30.0.1
@@ -38205,12 +38206,13 @@ snapshots:
strip-json-comments: 3.1.1
optionalDependencies:
'@types/node': 25.8.0
+ esbuild-register: 3.6.0([email protected])
transitivePeerDependencies:
- babel-plugin-macros
- supports-color
dependencies:
'@babel/core': 7.29.0
'@jest/get-type': 30.0.1
@@ -38237,7 +38239,8 @@ snapshots:
slash: 3.0.0
strip-json-comments: 3.1.1
optionalDependencies:
- esbuild-register: 3.6.0([email protected])
+ '@types/node': 25.8.0
transitivePeerDependencies:
- babel-plugin-macros
- supports-color
@@ -39132,12 +39135,12 @@ snapshots:
- supports-color
- ts-node
dependencies:
'@jest/types': 30.0.5
import-local: 3.2.0
transitivePeerDependencies:
- '@types/node'
- babel-plugin-macros
@@ -39145,12 +39148,12 @@ snapshots:
- supports-color
- ts-node
dependencies:
- '@jest/core': 30.0.5([email protected]([email protected]))
'@jest/types': 30.0.5
import-local: 3.2.0
transitivePeerDependencies:
- '@types/node'
- babel-plugin-macros