Mixins / foldkit-mixins-ui

Questionnaire

namespace · packages/mixins-ui/src/questionnaire.ts:1

export * as Questionnaire from './questionnaire.js'

In the guides

Members

Questionnaire.Answer

const · packages/mixins-ui/src/questionnaire.ts:149

const Answer: Schema.Struct<{
  readonly chosen: Schema.$Array<Schema.String>
  readonly text: Schema.String
}>

The options chosen and the text written, whatever the question's kind.

Questionnaire.Answered

const · packages/mixins-ui/src/questionnaire.ts:188

const Answered: Schema.Struct<{
  readonly question: Schema.String
  readonly chosen: Schema.$Array<Schema.String>
  readonly text: Schema.String
}>

One question's answer, as the submit sends it.

Questionnaire.answerOf

function · packages/mixins-ui/src/questionnaire.ts:247

function answerOf(model: Model, question: string): Answer

The answer to question so far.

Questionnaire.Choice

const · packages/mixins-ui/src/questionnaire.ts:57

const Choice: Schema.Struct<{
  readonly value: Schema.String
  readonly label: Schema.String
  readonly description: Schema.OptionFromNullOr<Schema.String>
}>

Questionnaire.init

function · packages/mixins-ui/src/questionnaire.ts:210

function init(options: {
  readonly id: string
  readonly questions: ReadonlyArray<Question>
  readonly layout?: Layout | undefined
}): Model

A questionnaire, unanswered. Question ids must be unique: an answer is kept by its question's, and a repeat would share it, so it throws.

Questionnaire.isAnswered

function · packages/mixins-ui/src/questionnaire.ts:251

function isAnswered(question: Question, answer: Answer): boolean

Whether answer answers question: an option, or text that is not blank.

Questionnaire.Layout

const · packages/mixins-ui/src/questionnaire.ts:154

const Layout: Schema.Literals<readonly ['all', 'paged']>

Questionnaire.Message

const · packages/mixins-ui/src/questionnaire.ts:176

const Message: MessageUnion<{
  readonly GotRadio: {
    readonly question: Schema.String
    readonly message: MessageUnion<{
      readonly SelectedOption: { index: Schema.Number; value: Schema.String }
      readonly FocusedOption: { index: Schema.Number }
      readonly CompletedFocusOption: {}
    }>
  }
  readonly Toggled: {
    readonly question: Schema.String
    readonly value: Schema.String
  }
  readonly Typed: {
    readonly question: Schema.String
    readonly text: Schema.String
  }
  readonly Submitted: {}
  readonly Backed: {}
  readonly CompletedFocus: {}
}>

Questionnaire.Model

const · packages/mixins-ui/src/questionnaire.ts:157

const Model: Schema.Struct<{
  readonly id: Schema.String
  readonly questions: Schema.$Array<
    TaggedUnion<{
      readonly Single: {
        id: Schema.String
        prompt: Schema.String
        options: Schema.$Array<
          Schema.Struct<{
            readonly value: Schema.String
            readonly label: Schema.String
            readonly description: Schema.OptionFromNullOr<Schema.String>
          }>
        >
        other: Schema.OptionFromNullOr<Schema.String>
        optional: Schema.Boolean
      }
      readonly Multiple: {
        id: Schema.String
        prompt: Schema.String
        options: Schema.$Array<
          Schema.Struct<{
            readonly value: Schema.String
            readonly label: Schema.String
            readonly description: Schema.OptionFromNullOr<Schema.String>
          }>
        >
        other: Schema.OptionFromNullOr<Schema.String>
        optional: Schema.Boolean
      }
      readonly Text: {
        readonly id: Schema.String
        readonly prompt: Schema.String
        readonly placeholder: Schema.OptionFromNullOr<Schema.String>
        readonly multiline: Schema.Boolean
        readonly optional: Schema.Boolean
      }
    }>
  >
  readonly answers: Schema.$Record<
    Schema.String,
    Schema.Struct<{
      readonly chosen: Schema.$Array<Schema.String>
      readonly text: Schema.String
    }>
  >
  readonly radios: Schema.$Record<
    Schema.String,
    Schema.Struct<{
      readonly id: Schema.String
      readonly maybeFocusedIndex: Schema.Option<Schema.Number>
    }>
  >
  readonly layout: Schema.Literals<readonly ['all', 'paged']>
  readonly page: Schema.Number
  readonly missing: Schema.$Array<Schema.String>
  readonly submitted: Schema.Boolean
}>

Questionnaire.multiple

function · packages/mixins-ui/src/questionnaire.ts:123

function multiple(question: ChoiceQuestionInput): Question

A multiple-choice question, its omitted fields defaulted.

Questionnaire.OutMessage

const · packages/mixins-ui/src/questionnaire.ts:194

const OutMessage: MessageUnion<{
  readonly Answered: {
    readonly answers: Schema.$Array<
      Schema.Struct<{
        readonly question: Schema.String
        readonly chosen: Schema.$Array<Schema.String>
        readonly text: Schema.String
      }>
    >
  }
}>

Questionnaire.Question

const · packages/mixins-ui/src/questionnaire.ts:75

const Question: TaggedUnion<{
  readonly Single: {
    id: Schema.String
    prompt: Schema.String
    options: Schema.$Array<
      Schema.Struct<{
        readonly value: Schema.String
        readonly label: Schema.String
        readonly description: Schema.OptionFromNullOr<Schema.String>
      }>
    >
    other: Schema.OptionFromNullOr<Schema.String>
    optional: Schema.Boolean
  }
  readonly Multiple: {
    id: Schema.String
    prompt: Schema.String
    options: Schema.$Array<
      Schema.Struct<{
        readonly value: Schema.String
        readonly label: Schema.String
        readonly description: Schema.OptionFromNullOr<Schema.String>
      }>
    >
    other: Schema.OptionFromNullOr<Schema.String>
    optional: Schema.Boolean
  }
  readonly Text: {
    readonly id: Schema.String
    readonly prompt: Schema.String
    readonly placeholder: Schema.OptionFromNullOr<Schema.String>
    readonly multiline: Schema.Boolean
    readonly optional: Schema.Boolean
  }
}>

Questionnaire.QuestionnaireSlots

const · packages/mixins-ui/src/questionnaire.ts:33

const QuestionnaireSlots: Slots.Contract<{ readonly root: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly title: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly progress: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly question: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly prompt: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly words: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Intera …;

An assistant asking the reader structured questions in the chat, as Claude Code's and ChatGPT's clarifying questions: a single choice (the package's RadioGroup), a multiple choice (its CheckboxGroup), or free text (its Input or Textarea), each choice question with an optional "Other" field, asked all at once or one at a time, and sent with a submit. The questions, the answers so far and the radio groups' focus are a Model of this module's, which the application keeps and folds with update; once every question that must be is answered, the submit comes out as OutMessage.Answered, and the form gives way to a summary of the answers. A submit with one missing says so beside it and moves the focus to it, as Next does to the next question. The parts the reused components draw are styled by their own recipes, passed beside this one's style.

Questionnaire.QuestionnaireView

interface · packages/mixins-ui/src/questionnaire.ts:417

interface QuestionnaireView<Message> {
  readonly model: Model
  readonly onMessage: (message: typeof Message.Type) => NoInfer<Message>
  readonly title?: string | undefined
  readonly submitLabel?: string | undefined
  readonly nextLabel?: string | undefined
  readonly backLabel?: string | undefined
  readonly missingText?: string | undefined
  readonly skippedText?: string | undefined
  readonly progressText?: ((page: number, total: number) => string) | undefined
  readonly style?: NamedStyle<typeof QuestionnaireSlots> | undefined
  readonly mixins?: MixinList<Message> | undefined
  readonly radioGroup?: NamedStyle<typeof RadioGroupSlots> | undefined
  readonly checkboxGroup?: NamedStyle<typeof CheckboxGroupSlots> | undefined
  readonly input?: NamedStyle<typeof InputSlots> | undefined
  readonly textarea?: NamedStyle<typeof TextareaSlots> | undefined
  readonly button?: NamedStyle<typeof ButtonSlots> | undefined
  readonly submitButton?: NamedStyle<typeof ButtonSlots> | undefined
}

Questionnaire.single

function · packages/mixins-ui/src/questionnaire.ts:113

function single(question: ChoiceQuestionInput): Question

A single-choice question, its omitted fields defaulted.

Questionnaire.text

function · packages/mixins-ui/src/questionnaire.ts:133

function text(question: {
  readonly id: string
  readonly prompt: string
  readonly placeholder?: string | undefined
  readonly multiline?: boolean | undefined
  readonly optional?: boolean | undefined
}): Question

A free-text question, its omitted fields defaulted.

Questionnaire.update

function · packages/mixins-ui/src/questionnaire.ts:295

function update(model: Model, message: Message): Return

The questionnaire after message; the same Model when nothing changes.

Questionnaire.view

function · packages/mixins-ui/src/questionnaire.ts:462

function view<Outer>(
  options: QuestionnaireView<Outer>,
  h: HtmlBuilder<Outer>,
): Html