Components

Questionnaire

An assistant’s questions, answered in the chat and sent as one Message.

Previews are drawn in the theme you made.

Edit it
variant
actions
scheme
direction

All at once #

A few questions before I plan

How busy should the days be?

What do you enjoy?
import { Questionnaire, QuestionnaireSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { Fields, TRIP_QUESTIONS } from '../../snippets/questionnaire.js'

// Every question at once. The Model is `Questionnaire.init`, folded by
// `Questionnaire.update`, whose `OutMessage.Answered` carries every answer
// once the form is sent. Each kind draws with the look of the widget it
// reuses, passed beside the questionnaire's own.
export default example({
  title: 'All at once',
  slots: QuestionnaireSlots,
  recipe: Recipes.Questionnaire,
  state: {
    Model: Questionnaire.Model,
    Message: Questionnaire.Message,
    init: () => ({
      model: Questionnaire.init({ id: 'questionnaire-basic', questions: TRIP_QUESTIONS }),
    }),
    update: (model, message) => {
      const { model: next, commands } = Questionnaire.update(model, message)
      return { model: next, commands }
    },
  },
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ inlineSize: 'min(28rem, 100%)' })],
      [
        Questionnaire.view(
          {
            model,
            onMessage,
            title: 'A few questions before I plan',
            style,
            ...Fields,
          },
          h,
        ),
      ],
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

One at a time, in a card #

Question 1 of 3

How busy should the days be?

import { Questionnaire, QuestionnaireSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { Fields, TRIP_QUESTIONS } from '../../snippets/questionnaire.js'

// One question at a time: `layout: 'paged'` on `init`. Next refuses a missing
// answer and moves the focus to the next question.
export default example({
  title: 'One at a time, in a card',
  slots: QuestionnaireSlots,
  recipe: Recipes.Questionnaire,
  pins: { variant: 'card' },
  state: {
    Model: Questionnaire.Model,
    Message: Questionnaire.Message,
    init: () => ({
      model: Questionnaire.init({
        id: 'questionnaire-paged',
        questions: TRIP_QUESTIONS,
        layout: 'paged',
      }),
    }),
    update: (model, message) => {
      const { model: next, commands } = Questionnaire.update(model, message)
      return { model: next, commands }
    },
  },
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ inlineSize: 'min(28rem, 100%)' })],
      [Questionnaire.view({ model, onMessage, style, ...Fields }, h)],
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

In another language #

Frage 1 von 3

How busy should the days be?

import { Questionnaire, QuestionnaireSlots, Recipes } from 'foldkit-mixins-ui'
import { example } from '../../gallery/example.js'
import { Fields, TRIP_QUESTIONS } from '../../snippets/questionnaire.js'

// Every fixed text is a word, with `{blanks}` where a number goes: the
// buttons, what a missing answer says, and where the reader is.
export default example({
  title: 'In another language',
  slots: QuestionnaireSlots,
  recipe: Recipes.Questionnaire,
  pins: { variant: 'card' },
  state: {
    Model: Questionnaire.Model,
    Message: Questionnaire.Message,
    init: () => ({
      model: Questionnaire.init({
        id: 'questionnaire-words',
        questions: TRIP_QUESTIONS,
        layout: 'paged',
      }),
    }),
    update: (model, message) => {
      const { model: next, commands } = Questionnaire.update(model, message)
      return { model: next, commands }
    },
  },
  view: ({ style, model, onMessage, h }) =>
    h.div(
      [h.Style({ inlineSize: 'min(28rem, 100%)' })],
      [
        Questionnaire.view(
          {
            model,
            onMessage,
            style,
            ...Fields,
            words: {
              submit: 'Senden',
              next: 'Weiter',
              back: 'Zurück',
              missing: 'Bitte antworten',
              skipped: 'Übersprungen',
              progress: 'Frage {page} von {total}',
            },
          },
          h,
        ),
      ],
    ),
})

In your application: recipe goes to forSlots, state to Bundle.withChild, and the body of view is the call. example is this site’s harness.

Usage

Each example above is a module of its own, shown whole and run as shown, over the theme module Create a theme writes. The page hands it the style picked above.

The recipe ↗This code ↗