# Question Builder Modal

A shadcn/ui question builder modal for event sign-up forms: pick one of eight question types, then set it up in a form as the panel springs to fit.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available for the docs, pricing and about pages: append `.md` to the URL or send an `Accept: text/markdown` header (the home page answers the header too). An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).

## At a glance

- **Good for:** Event registration forms with custom questions; Form and survey builders in SaaS apps; Sign-up flows where organisers add their own fields; Admin tools that configure what users are asked
- **Category:** Forms · **Type:** Forms · **Style:** Motion, Minimal, Dark mode
- **See it:** [Live preview](https://www.craftui.space/docs/blocks/question-builder-modal) · [Screenshot](https://www.craftui.space/llms.md/preview/question-builder-modal.ba189f1b.jpg)

![Question Builder Modal](https://www.craftui.space/llms.md/preview/question-builder-modal.ba189f1b.jpg)

## Install

```bash
pnpm dlx shadcn@latest add https://www.craftui.space/r/question-builder-modal.json
```

This is a paid item (BLK-VBJ8AE): the install needs a craftUI plan or a purchase of it. Signed in, the docs page gives your personal install command. Plans: https://www.craftui.space/pricing

## Usage

```tsx
import QuestionBuilderModal from "@/components/blocks/question-builder-modal/question-builder-modal";

export default function Page() {
  return <QuestionBuilderModal />;
}
```

With no props it renders with demo content; pass your own through the props below.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactElement` | — | Optional trigger, rendered as the dialog's trigger (a single element, such as a button). Omit it and drive the modal with `open` / `onOpenChange` instead. |
| `open` | `boolean` | — | Controlled open state. When set, the modal stops tracking its own state — pair with onOpenChange. |
| `onOpenChange` | `(open: boolean) => void` | — | Fires whenever the modal opens or closes, including on submit and on Escape. |
| `onAddQuestion` | `(draft: QuestionDraft) => void` | — | Fires on submit with { type, question, required, settings }. `settings` is per-type — e.g. { length } for text, { allowMultiple, options } for options, { contentType, showBeforeAccept, collectSignature } for terms. |
| `title` | `string` | `"Add Question"` | Picker headline, the step screens' centered title, and the dialog's accessible name. |
| `description` | `string` | `"Ask guests custom questions when they register."` | Sub-headline under the picker title, and the dialog's accessible description. |
| `types` | `QuestionType[]` | `QUESTION_TYPES` | Replace or reorder the type grid. Ids must stay within QuestionTypeId. |
| `className` | `string` | — | Extra classes merged onto the dialog panel (width, radius, padding). |

### `QuestionDraft`

| Field | Type | Description |
| --- | --- | --- |
| `type` (required) | `QuestionTypeId` | The question type that was picked. |
| `question` (required) | `string` | The question text (for Terms, the terms content or link). |
| `required` (required) | `boolean` | Whether guests must answer it. |
| `settings` (required) | `Record<string, unknown>` | Per-type detail: { length } for text, { allowMultiple, options } for options, { network } for social, { collectJobTitle, jobTitle } for company, { helperText } for checkbox, { contentType, showBeforeAccept, collectSignature } for terms, {} for phone and website. |

### `QuestionType`

| Field | Type | Description |
| --- | --- | --- |
| `id` (required) | `QuestionTypeId` | Selects the form the step screen renders, so it must stay within QuestionTypeId. |
| `label` (required) | `string` | The tile's label on the picker, and the name on the step screen. |
| `description` (required) | `string` | Shown under the label once the type is picked. |
| `icon` (required) | `IconSvgElement` | A Hugeicons icon object, such as `Link04Icon` from the free Hugeicons set. |
| `defaultQuestion` (required) | `string` | Prefills the question field so the step never opens empty-handed. |

## Files

The install adds:

- `components/blocks/question-builder-modal/question-builder-modal.tsx`
- `components/blocks/question-builder-modal/question-forms.tsx`
- `components/blocks/question-builder-modal/controls.tsx`
- `components/blocks/question-builder-modal/layout.tsx`
- `components/blocks/question-builder-modal/question-types.ts`
- `components/blocks/question-builder-modal/motion.ts`
- `components/blocks/question-builder-modal/styles.ts`
- `components/blocks/question-builder-modal/DESIGN.md`

npm dependencies (installed for you): `@hugeicons/core-free-icons`, `@hugeicons/react`, `motion`, `react-use-measure`.

shadcn/ui components it uses (the shadcn CLI adds any that are missing): `button`, `dialog`, `input`, `label`, `switch`, `textarea`.