{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "question",
  "title": "Question",
  "description": "Single choice, multiple choice and free text questions in one form, then the recorded answers.",
  "dependencies": [
    "@kind-ui/agent-ui@0.9.0",
    "@ui-sdk/core@0.1.0-beta.17",
    "@ui-sdk/react@0.1.0-beta.17"
  ],
  "registryDependencies": [
    "@kind-ui/agent-ui-setup",
    "@kind-ui/internal-radio",
    "@kind-ui/internal-checkbox",
    "@kind-ui/internal-textarea"
  ],
  "files": [
    {
      "path": "packages/agent-ui/src/react/question.tsx",
      "content": "\"use client\";\n\nimport { questionPrimitive } from \"@kind-ui/agent-ui/core\";\nimport { createParts } from \"@ui-sdk/react/primitive\";\nimport type { ComponentProps } from \"react\";\nimport { KindCheckbox, KindCheckboxGroup, KindCheckboxIndicator } from \"./internal/checkbox\";\nimport { KindRadio, KindRadioGroup, KindRadioIndicator } from \"./internal/radio\";\nimport { KindTextarea } from \"./internal/textarea\";\n\nconst parts = createParts(questionPrimitive, {\n  root: \"form\",\n  item: \"fieldset\",\n  prompt: \"legend\",\n  choices: \"div\",\n  text: \"div\",\n  actions: \"div\",\n  submit: \"button\",\n  skip: \"button\",\n  status: \"span\",\n  \"status-icon\": \"span\",\n  error: \"span\",\n  summary: \"div\",\n  \"summary-icon\": \"span\",\n});\n\nexport type QuestionProps = ComponentProps<typeof parts.Root>;\n\n/**\n * One question or several in one form, each a fieldset, with Submit and Skip, then the recorded answers in the form's\n * place. Any `children` replace the default parts.\n */\nexport function Question({ children = DEFAULT_PARTS, ...props }: QuestionProps) {\n  return <parts.Root {...props}>{children}</parts.Root>;\n}\n\nexport const QuestionActions = parts.Actions;\nexport const QuestionStatusIcon = parts.StatusIcon;\nexport const QuestionSummaryIcon = parts.SummaryIcon;\n\nexport type QuestionItemProps = ComponentProps<typeof parts.Item>;\n\n/** The question whose `id` is `value`. Without children, it shows its prompt and its choices or text box. */\nexport function QuestionItem({ children = DEFAULT_ITEM_PARTS, ...props }: QuestionItemProps) {\n  return <parts.Item {...props}>{children}</parts.Item>;\n}\n\nexport type QuestionPromptProps = ComponentProps<typeof parts.Prompt>;\n\n/** The question's prompt, marked \"Required\" when it is, unless you pass children. */\nexport function QuestionPrompt({\n  children = ({ prompt, required }) => (\n    <>\n      {prompt}\n      {required ? (\n        <>\n          {\" \"}\n          <span data-question-required=\"\">Required</span>\n        </>\n      ) : null}\n    </>\n  ),\n  ...props\n}: QuestionPromptProps) {\n  return <parts.Prompt {...props}>{children}</parts.Prompt>;\n}\n\nexport type QuestionChoicesProps = ComponentProps<typeof parts.Choices>;\n\n/** A radio group for a single choice or a checkbox group for a multiple one, unless you pass children. */\nexport function QuestionChoices({\n  children = (state) => {\n    if (!(\"kind\" in state)) return null;\n    const options = state.options.map((option) => (\n      // biome-ignore lint/a11y/noLabelWithoutControl: the label wraps UI SDK's radio or checkbox, which it names.\n      <label key={option.value} data-question-option=\"\">\n        {state.kind === \"single\" ? (\n          <KindRadio value={option.value}>\n            <KindRadioIndicator />\n          </KindRadio>\n        ) : (\n          <KindCheckbox value={option.value}>\n            <KindCheckboxIndicator>{CHECK}</KindCheckboxIndicator>\n          </KindCheckbox>\n        )}\n        <span data-question-option-text=\"\">\n          <span>{option.label}</span>\n          {option.description ? <span data-question-option-description=\"\">{option.description}</span> : null}\n        </span>\n      </label>\n    ));\n    return state.kind === \"single\" ? (\n      <KindRadioGroup\n        aria-labelledby={state.labelledBy}\n        controller={state.controller}\n        defaultValue={state.defaultValue}\n        readOnly={state.readOnly}\n      >\n        {options}\n      </KindRadioGroup>\n    ) : (\n      <KindCheckboxGroup\n        controller={state.controller}\n        defaultValue={state.defaultValue}\n        readOnly={state.readOnly}\n      >\n        {options}\n      </KindCheckboxGroup>\n    );\n  },\n  ...props\n}: QuestionChoicesProps) {\n  return <parts.Choices {...props}>{children}</parts.Choices>;\n}\n\nexport type QuestionTextProps = ComponentProps<typeof parts.Text>;\n\n/** A text box for a text question, unless you pass children. Enter adds a line; it never submits. */\nexport function QuestionText({\n  children = (state) =>\n    \"controller\" in state ? (\n      <KindTextarea\n        controller={state.controller}\n        defaultValue={state.defaultValue}\n        readOnly={state.readOnly}\n        placeholder={state.placeholder}\n        aria-label={state.label}\n        rows={3}\n      />\n    ) : null,\n  ...props\n}: QuestionTextProps) {\n  return <parts.Text {...props}>{children}</parts.Text>;\n}\n\nexport type QuestionSubmitProps = ComponentProps<typeof parts.Submit>;\n\n/** Calls `onSubmit`. Reads the `submitLabel` unless you pass children. Rendered only while `onSubmit` is set. */\nexport function QuestionSubmit({ children = withPendingMark, ...props }: QuestionSubmitProps) {\n  return <parts.Submit {...props}>{children}</parts.Submit>;\n}\n\nexport type QuestionSkipProps = ComponentProps<typeof parts.Skip>;\n\n/** Calls `onSkip`. Reads the `skipLabel` unless you pass children. Rendered only while `onSkip` is set. */\nexport function QuestionSkip({ children = withPendingMark, ...props }: QuestionSkipProps) {\n  return <parts.Skip {...props}>{children}</parts.Skip>;\n}\n\nexport type QuestionStatusProps = ComponentProps<typeof parts.Status>;\n\n/**\n * \"Sending answers\" or \"Skipping\" while the host has them, unless you pass children. The pressed button holds the\n * running mark, so the words stand alone.\n */\nexport function QuestionStatus({ children = ({ label }) => label, ...props }: QuestionStatusProps) {\n  return <parts.Status {...props}>{children}</parts.Status>;\n}\n\nexport type QuestionErrorProps = ComponentProps<typeof parts.Error>;\n\n/** \"Answers not sent. Try again.\" after a submission fails, unless you pass children. */\nexport function QuestionError({ children = \"Answers not sent. Try again.\", ...props }: QuestionErrorProps) {\n  return <parts.Error {...props}>{children}</parts.Error>;\n}\n\nexport type QuestionSummaryProps = ComponentProps<typeof parts.Summary>;\n\n/** \"Answered\" with each question and its answer, or \"Skipped\", unless you pass children. */\nexport function QuestionSummary({\n  children = ({ outcome, items }) => (\n    <>\n      <span data-question-outcome=\"\">\n        <QuestionSummaryIcon />\n        {outcome}\n      </span>\n      {items.length > 0 ? (\n        <dl>\n          {items.map((item) => (\n            <div key={item.id}>\n              <dt>{item.prompt}</dt>\n              <dd data-empty={item.answer === undefined ? \"\" : undefined}>{item.answer ?? \"No answer\"}</dd>\n            </div>\n          ))}\n        </dl>\n      ) : null}\n    </>\n  ),\n  ...props\n}: QuestionSummaryProps) {\n  return <parts.Summary {...props}>{children}</parts.Summary>;\n}\n\n// The mark shows only while the button's call is pending (controls.css).\nconst withPendingMark = ({ label }: { label: string }) => (\n  <>\n    <span data-kind-pending-mark=\"\" data-status-mark=\"\" data-status=\"running\" aria-hidden=\"true\" />\n    {label}\n  </>\n);\n\n// Lucide's check, as the status mark draws it.\nconst CHECK = (\n  <svg\n    viewBox=\"0 0 24 24\"\n    fill=\"none\"\n    stroke=\"currentColor\"\n    strokeWidth=\"3.5\"\n    strokeLinecap=\"round\"\n    strokeLinejoin=\"round\"\n    aria-hidden=\"true\"\n  >\n    <path d=\"M20 6 9 17l-5-5\" />\n  </svg>\n);\n\n// Shared, so an update to the answers doesn't render the default parts' wrappers again.\nconst DEFAULT_ITEM_PARTS = (\n  <>\n    <QuestionPrompt />\n    <QuestionChoices />\n    <QuestionText />\n  </>\n);\n\nconst ACTIONS = (\n  <QuestionActions>\n    <QuestionSubmit />\n    <QuestionSkip />\n    <QuestionStatus />\n    <QuestionError />\n  </QuestionActions>\n);\n\nconst DEFAULT_PARTS: QuestionProps[\"children\"] = ({ questions }) => (\n  <>\n    {questions.map((question) => (\n      <QuestionItem key={question.id} value={question.id} />\n    ))}\n    {ACTIONS}\n    <QuestionSummary />\n  </>\n);\n",
      "type": "registry:ui",
      "target": "@ui/question.tsx"
    }
  ],
  "meta": {
    "layer": "react"
  },
  "type": "registry:ui"
}
