# `RiddlerLiveView.Components`
[🔗](https://github.com/riddler/riddler_live_view/blob/v0.1.0/lib/riddler_live_view/components.ex#L1)

Function components for a presented screen and its elements.

`Riddler.Journey.present/3` answers a step of a Journey as data. For a
screen, the answer's `"screen"` carries the screen's `"key"`, its
`"title"` and its `"elements"`, and the answer carries `"progress"` only
where the host supplied it. The components here render that data as plain
semantic HTML:

  * `frame/1` draws the screen around its elements: the title, and
    progress when the answer carries it.
  * One component per element kind, named for the kind it renders:
    `heading/1`, `text/1`, `image/1`, `divider/1`, `link/1`,
    `text_question/1`, `secret_question/1`, `choice_question/1`,
    `boolean_question/1` and `button/1`.
  * `back/1` draws the Back control where the answer's `"moves"` let the
    visitor go back.
  * `elements/1` draws every element of a screen, in order, each through
    the component for its kind, a host's own kinds through the host's
    components, and an element of a kind it cannot draw not at all; the
    "Elements of a kind the package does not draw" section says what then
    happens to the screen's submit.

`link/1` and `button/1` share their names with components a Phoenix
application already has, `Phoenix.Component.link/1` and the `button/1` of
a generated `CoreComponents`, so a host aliases this module, or calls its
components fully qualified, rather than importing it beside them.

The markup ships no stylesheet and no CSS framework class. Every component
carries a `class` attribute, and a host may add its own classes through
the `class` attribute each component takes. Every component also carries
stable `data-riddler-*` attributes a host's stylesheet and tests can
select on:

  * `data-riddler-element` on the markup of each element, whose value is
    the element's kind, the `"type"` the answer gives it (`"heading"`,
    `"text"`, `"image"`, `"divider"`, `"link"`, `"text_question"`,
    `"secret_question"`, `"choice_question"`, `"boolean_question"`,
    `"button"`);
  * `data-riddler-key` on the markup of each element, whose value is the
    element's `"key"`;
  * `data-riddler-screen` on the frame, whose value is the screen's
    `"key"`;
  * `data-riddler-title`, `data-riddler-progress` and
    `data-riddler-elements` on the frame's title, progress and the
    container its elements render in;
  * `data-riddler-label`, `data-riddler-input`, `data-riddler-help` and
    `data-riddler-held` on a question's label, its input, its help and
    the paragraph that says a secret question's value is held;
  * `data-riddler-legend` on a choice question's legend, and
    `data-riddler-option` on each of its options, whose value is the
    option's `"value"`;
  * `data-riddler-select` on a choice question, `"one"` or `"many"`, and
    `data-riddler-min-selections` and `data-riddler-max-selections`
    where it carries those bounds under `"many"`;
  * `data-riddler-style` on a text question or a choice question, whose
    value is its `"style"` where it carries one, and
    `data-riddler-searchable` on a choice question, `"true"` where it is
    searchable;
  * `data-riddler-option-description` on an option's description, whose
    value is the option's `"value"`, and
    `data-riddler-option-descriptions` on the list of them drawn after a
    `<select>` or a datalist;
  * `data-riddler-outcome`, `data-riddler-validates` and
    `data-riddler-style` on a button, whose values are its `"outcome"`,
    `"true"` or `"false"` for whether it validates, and its `"style"`
    where it carries one;
  * `data-riddler-size` and `data-riddler-fit` on an image, whose values
    are its `"size"` and `"fit"` where it carries them, and
    `data-riddler-style` on a link, whose value is its `"style"` where it
    carries one;
  * `data-riddler-accessible-description` on the hidden text of an
    element's accessible description;
  * `data-riddler-back` on the Back control;
  * `data-riddler-unknown` on the notice `elements/1` draws for a screen
    with elements it cannot draw, whose value is their kinds that are
    strings, space-separated, and
    `data-riddler-blocked` on a button that notice disables, whose value
    is the notice's `id`;
  * `data-riddler-finding` on each finding drawn, whose value is the
    finding's `"code"`, and `data-riddler-focus` on the frame's focus
    trigger, whose value is the `id` of the finding it moves focus to.

A secret question's input never carries a value: no `value` attribute,
whatever the element carries, and `autocomplete="off"`.

A text's `"style"` is drawn as a class, `riddler-text-body` or
`riddler-text-caption`, so a host's stylesheet can set a caption apart. An
image's alt text is always drawn, as `alt=""` for a decorative image. A
link is a plain `<a href>`: it submits no form and raises no outcome.

## Accessible label and description

riddler presents, on an element of any kind, an `"accessible_label"`, the
name an assistive technology gives the element where its visible text is
not enough, and an `"accessible_description"`, a longer account it may read
after the name, each where the document wrote one and rendered from its
template. A component draws them on the node a visitor reaches:

  * the label is that node's `aria-label`: the `<h1>` to `<h6>` of a
    heading, the `<img>` of an image, the `<hr>` of a divider, the `<a>` of
    a link, the `<button>` of a button, and the `<input>` or `<textarea>`
    of a text, secret or boolean question, not the `<div>` around it,
    which has no role to name;
  * a choice question's label is its `<fieldset>`'s `aria-label`, the
    name of the group its options sit in, since each option keeps its own
    label; where the options are drawn as a `<select>` or a search input,
    that control carries the label too, in place of the `aria-labelledby`
    that names it by the legend, since `aria-labelledby` would win over it;
  * the description is a `<span hidden>` drawn after the element, or after
    a question's help inside it, whose `id` is derived from `id_prefix` and
    the element's `"key"`; the node that carries the label names it last in
    its `aria-describedby`, after the ids already there: a question's
    findings, what is held and its help, in that order, and the notice that
    blocks a button. A choice question drawn as a `<select>` or a search
    input names its findings, its help and its description from that
    control as well as from its fieldset.

A text draws no `aria-label`: its node is a paragraph, which ARIA does not
let an author name, and an assistive technology reads its text. Its
description is drawn and named all the same.

An image's `"alt"` stays its `alt`. Where the image carries a label too, the
label is its `aria-label`, which an assistive technology reads in place of
the `alt`; the `alt` is still what a browser shows where the image does not
load. An image whose `"alt"` is empty is decorative until it carries a
label: a named image is no longer hidden from an assistive technology.

The label is drawn as riddler presents it, whatever the element's visible
text says. A visitor who speaks a control's visible text to operate it is
understood only where the label contains that text (WCAG 2.5.3, Label in
Name); riddler's records leave the wording to the document's author, and
the package neither checks it nor joins the two.

An element that carries neither, or carries them blank, draws exactly the
markup it draws without them: no `aria-label`, no hidden text and no `id`
in `aria-describedby`. Each component takes an `id_prefix` for the
description's `id`, and `elements/1` passes its own to every element.

## Findings

When riddler refuses what the visitor submitted, the host holds a list of
`Riddler.Finding` structs, or their wire form, a map with the string keys
`"code"`, `"message"`, `"field"`, `"element_key"`, `"position"` and
`"author_message"`. A host passes the same list as `findings` to the frame
and to each question component, and each draws the findings that are its
own:

  * a question draws, beside its input, every finding whose
    `element_key` is the question's `"key"`, names each in its input's
    `aria-describedby` ahead of its help, and sets `aria-invalid="true"`
    on its input; a choice question names them from its fieldset, and
    marks and names them on each of its inputs or its `<select>`;
  * the frame draws, above the elements, every finding that names no
    question of the screen: one with no `element_key`, and one whose
    `element_key` is not the key of a question among the screen's
    `"elements"`, and names them in its `<section>`'s `aria-describedby`.

A finding is a paragraph that can take focus, `tabindex="-1"`, and is
never in the tab order. The text drawn is the finding's
`"author_message"`, the text the document's author wrote for its code,
where it is a non-blank string. Otherwise it is this package's own
sentence for the code, which a host replaces code by code with the
`finding_text` attribute. A finding's `"message"` is riddler's sentence for
the host and is never drawn, so nothing a message quotes of a response
reaches the page.

The frame moves focus to the first finding when the findings appear: the
first the frame draws itself, or else the first finding of the first
question in the screen's `"elements"` that has one. It does so with a
`phx-mounted` `Phoenix.LiveView.JS.focus/1` on a hidden trigger whose `id`
names that finding, so focus moves whenever the first finding changes. A
refusal that leaves the same first finding in place moves it again only
where the host passes `refusals`, a count it changes on every refused
submit, as `RiddlerLiveView.Journey` does: the trigger's `id` carries the
count, so each refusal mounts a trigger of its own.

Every `id` a component derives opens on its `id_prefix`, `"riddler"` by
default, followed by the screen's or the question's `"key"`. A page that
draws two screens at once, or two Journeys, passes each its own prefix, so
no `id` is carried twice.

## Elements of a kind the package does not draw

A screen may carry an element whose `"type"` is not one of the kinds
above. A host whose screens carry kinds of its own passes `elements/1` a
component map, `components`, that names, for each such type, the host's
function component that draws it; that component is called with the
element and the screen's `moves`, `findings`, `finding_text` and
`blocked_by`. A component map may not name a kind the package draws.

An element whose kind neither the package nor the component map draws is
not drawn, and the visitor may not submit the screen it is on:

  * `elements/1` draws a notice above the screen's elements saying that
    part of the screen cannot be shown, in the package's own sentence or
    the text the host passes as `unknown_text`;
  * every button it draws for the screen is drawn `disabled`, names the
    notice in its `aria-describedby` and carries `data-riddler-blocked`;
  * `unknown_kinds/2` answers the kinds of the screen that nothing draws,
    so a host, or the LiveComponent that embeds these components, refuses
    a submit of that screen whatever the browser sends: a disabled button
    is the browser's to honour, not a guarantee.

The Back control is not a submit and is not disabled.

## Example

A patron registration's details screen, from the answer riddler gives:

    <RiddlerLiveView.Components.frame screen={@answer["screen"]} progress={@answer["progress"]} findings={@findings}>
      <RiddlerLiveView.Components.heading element={heading} />
      <RiddlerLiveView.Components.text element={text} />
      <RiddlerLiveView.Components.text_question element={email} findings={@findings} />
      <RiddlerLiveView.Components.button element={continue} moves={@answer["moves"]} />
      <RiddlerLiveView.Components.back screen={@answer["screen"]} moves={@answer["moves"]} />
    </RiddlerLiveView.Components.frame>

# `back`

```elixir
@spec back(map()) :: Phoenix.LiveView.Rendered.t()
```

Draws the Back control, only where the answer's `"moves"` say `"back"` is
`true`.

Back is not an element of the screen and raises no outcome: it is a
`<button type="button">` that submits no form, so nothing the visitor
entered on the screen is validated or sent. Pressed, it pushes `event`
with riddler's back request as its value, `"screen"`, the key of the
screen shown, and `"back"`, `true`, with no `"outcome"`; a host's
LiveView, or the component named by `target`, handles the event and
passes the request on. LiveView adds the button's own `"value"`, an empty
string, to the params, and `Riddler.Journey.decode_submit/1` drops it.
The back request comes from the page and a visitor can send one the moves
did not offer, so the host checks that the moves it presented say
`"back"` is `true` before it acts on it, as
`Riddler.Journey.decode_submit/1` says.

## Attributes

* `screen` (`:map`) (required) - The answer's `"screen"`: its `"key"` is the back request's `"screen"`.
* `moves` (`:map`) (required) - The answer's `"moves"`: its `"outcomes"` and `"back"`.
* `label` (`:string`) - The control's text. Defaults to `"Back"`.
* `event` (`:string`) - The event the control pushes. Defaults to `"back"`.
* `target` (`:any`) - Where the event is pushed: a LiveComponent's `@myself` or a selector; the LiveView when nil. Defaults to `nil`.
* `class` (`:any`) - Classes added to the control's own. Defaults to `nil`.

# `boolean_question`

```elixir
@spec boolean_question(map()) :: Phoenix.LiveView.Rendered.t()
```

Renders a `boolean_question` element as a lone labelled checkbox.

The question's `"label"` is the checkbox's `<label>`, and the checkbox
submits `"true"` when it is ticked; an unticked checkbox submits nothing.
It is drawn ticked where the answer presents `true` for the question.
riddler validates a boolean question's response as `true` or `false`, so
the code that hands the submit to riddler turns the submitted `"true"`
into `true` and an absent one into `false` first, as
`RiddlerLiveView.Journey` does.

The checkbox carries `required` where the question is required: riddler
reads a required boolean question as one whose response must be `true`,
which is what `required` asks of a checkbox. The question's `"help"`, when
it has one, is a paragraph the checkbox names as its description.

Given `findings`, the question draws those whose `element_key` is its
`"key"` after the label, names them in the checkbox's description ahead
of the help, and marks the checkbox `aria-invalid="true"`.

The checkbox's `id` is derived from `id_prefix` and the question's
`"key"`, and its `name` is the key unless the host passes one.

## Attributes

* `element` (`:map`) (required) - A `boolean_question` element of the answer: its `"key"` and `"label"` and, where present, `"help"`, `"required"` and `"value"`.
* `name` (`:string`) - The checkbox's `name`; the element's `"key"` when nil. Defaults to `nil`.
* `class` (`:any`) - Classes added to the question's own. Defaults to `nil`.
* `findings` (`:list`) - The findings of a refused submit, `Riddler.Finding` structs or their wire form; the question draws those whose `element_key` is its `"key"`. Defaults to `[]`.
* `finding_text` (`:map`) - The text drawn, by finding code, for a finding whose author wrote no message, in place of the package's own. Defaults to `%{}`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.

# `button`

```elixir
@spec button(map()) :: Phoenix.LiveView.Rendered.t()
```

Renders a `button` element as a submit button that raises its outcome.

The button is drawn only where the answer's `"moves"` lists its
`"outcome"` among `"outcomes"`: a client reads what it may submit from the
moves, never from the elements, so a button whose outcome the moves do not
list is not drawn. Drawn, it is a `<button type="submit">` whose text is
the button's `"label"` and whose `name` and `value` are `"outcome"` and the
button's outcome, so the form it submits carries the outcome under the key
riddler's submit names.

A button whose `"validates"` is `false` does not validate the screen it
submits: it carries `formnovalidate`, so the browser's own checks do not
stop the press, and `data-riddler-validates="false"`. Every other button
carries `data-riddler-validates="true"`, riddler's default. The attribute
is a hook for a host's stylesheet, tests and client scripts, not the
server's source: a form submit carries only the pressed button's `name`
and `value`. The submit names the outcome, not the button's key: in a
document riddler validates, no two buttons a screen shows together raise
one outcome, so the host finds the pressed button, and whether it
validates, by its outcome. The button's `"style"`, a string from the open
set riddler leaves to a renderer, is carried as `data-riddler-style` and
drawn no differently.

The submitted outcome comes from the page and a visitor can change it, so
the host checks it is among the `"outcomes"` of the moves it presented
before it acts on it, as `Riddler.Journey.decode_submit/1` says.

Given `blocked_by`, the `id` of the notice `elements/1` draws for a screen
it cannot draw in full, the button is drawn `disabled`, names the notice
in its `aria-describedby` and carries `data-riddler-blocked`.

## Attributes

* `element` (`:map`) (required) - A `button` element of the answer: its `"key"`, `"label"` and `"outcome"` and, where present, `"validates"` and `"style"`.
* `moves` (`:map`) (required) - The answer's `"moves"`: its `"outcomes"` and `"back"`.
* `blocked_by` (`:string`) - The `id` of a notice saying why the screen cannot be submitted; given one, the button is drawn disabled and names it. Defaults to `nil`.
* `class` (`:any`) - Classes added to the button's own. Defaults to `nil`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.

# `choice_question`

```elixir
@spec choice_question(map()) :: Phoenix.LiveView.Rendered.t()
```

Renders a `choice_question` element as a fieldset of options whose legend
is the question's `"label"`.

The question's `"select"` fixes what the visitor picks: one option under
`"one"`, any number under `"many"`. Its `"style"` picks how the options are
drawn, from the hints riddler names:

  * under `"one"`, `"radio"` draws a radio button per option and
    `"dropdown"` a `<select>` that opens on an empty option, which
    submits an empty value where the visitor chooses none;
  * under `"many"`, `"checkboxes"` draws a checkbox per option and
    `"list"` a `<select multiple>`;
  * `"chips"`, under either, draws the radio buttons or checkboxes, each
    option's `<div>` carrying the class `riddler-chip` beside
    `riddler-option` for a host's stylesheet to draw as a chip;
  * no style, or a style the package does not draw, draws radio buttons
    under `"one"` and checkboxes under `"many"`.

A style that is a non-blank string is carried as the fieldset's
`data-riddler-style`.

Where `"searchable"` is `true` under `"one"`, whatever the style, the
options are drawn as a text input bound by its `list` to a `<datalist>`
of the options, so the browser offers the options that match what the
visitor types; the input is labelled by the legend and submits the value
typed or picked, which riddler checks is an option's. A datalist is the
browser's own filter and needs no script. Under `"many"` a datalist cannot
pick more than one value, so the options are drawn as without the hint.
Either way the fieldset carries `data-riddler-searchable="true"`. The
input shows and submits an option's `"value"`, which some browsers list
beside its label and others in place of it, so a searchable question
reads best where its values are words a visitor would type.

An option's `"description"`, a line riddler presents under the option's
label, is drawn with an `id` derived from the option's: beside a radio
button or a checkbox, a paragraph after its label, named in that input's
`aria-describedby` after its findings; beside a `<select>` or a datalist,
whose options can hold no markup, a description list after the control,
each option's label and description, the `<option>` naming its
description in its `aria-describedby`. Browsers do not expose an
option's description inside an open `<select>` or datalist, so there the
list after the control is what a visitor reads.

Each option's `"label"` is what the visitor reads and its `"value"` is
what the input submits. The value the answer presents for the question, a
response the visitor already gave or its prefill or default, is drawn
chosen: under `"one"` the option whose value it is, under `"many"` every
option whose value is in its list. A presented value of another shape
chooses nothing.

Under `"one"` the inputs carry `required` where the question is required.
Under `"many"` nothing is marked `required`, since a required checkbox is
one that must itself be ticked; the bounds riddler reads under `"many"`,
`"min_selections"` and `"max_selections"`, are carried as the fieldset's
`data-riddler-min-selections` and `data-riddler-max-selections` and are
not enforced in the browser: riddler validates what the visitor submits
against them.

The question's `"help"`, when it has one, is a paragraph the fieldset
names as its description. Each option input's `id` is derived from
`id_prefix`, the question's `"key"` and the option's `"value"`, a
`<select>`'s from the prefix and the key alone, and the `name` is the
key unless the host passes one; under `"many"` the name ends in `[]`, so
the submitted params carry a list.

Given `findings`, the question draws those whose `element_key` is its
`"key"` after its options, names them in the fieldset's description ahead
of the help, and marks each option input, or the `<select>`,
`aria-invalid="true"` and names them in its description too.

## Attributes

* `element` (`:map`) (required) - A `choice_question` element of the answer: its `"key"`, `"label"`, `"select"` and `"answer_options"`, each a `"value"` and a `"label"` and, where present, a `"description"`, and, where present, `"help"`, `"required"`, `"style"`, `"searchable"`, `"min_selections"`, `"max_selections"` and `"value"`.
* `name` (`:string`) - The inputs' `name`; the element's `"key"` when nil, with `[]` added under `"many"`. Defaults to `nil`.
* `class` (`:any`) - Classes added to the question's own. Defaults to `nil`.
* `findings` (`:list`) - The findings of a refused submit, `Riddler.Finding` structs or their wire form; the question draws those whose `element_key` is its `"key"`. Defaults to `[]`.
* `finding_text` (`:map`) - The text drawn, by finding code, for a finding whose author wrote no message, in place of the package's own. Defaults to `%{}`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.

# `divider`

```elixir
@spec divider(map()) :: Phoenix.LiveView.Rendered.t()
```

Renders a `divider` element as an `<hr>`, a rule between the elements
before and after it.

## Attributes

* `element` (`:map`) (required) - A `divider` element of the answer: its `"key"`.
* `class` (`:any`) - Classes added to the rule's own. Defaults to `nil`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.

# `elements`

```elixir
@spec elements(map()) :: Phoenix.LiveView.Rendered.t()
```

Draws every element of a screen, in the screen's order.

Each element of the screen's `"elements"` is drawn by the component for
its `"type"`: one of this module's for a kind the package draws, or the
host's own for a type the component map, `components`, names. A host's
component is called with exactly the assigns `element`, `moves`,
`findings`, `finding_text` and `blocked_by`, and draws the element as it
chooses; it is called as a function, so the defaults of any `attr` it
declares are not applied.
`findings` and `finding_text` pass to every question.

An element of any other kind is not drawn. Where the screen has one, a
notice is drawn above the elements, a status region (a paragraph with
`role="status"`) whose text is `unknown_text`, and every button is drawn
disabled and names the notice; `unknown_kinds/2` answers the same kinds for
the host's submit. The module's "Elements of a kind the package does not draw" section says why.

The notice's `id` is derived from `id_prefix` and the screen's `"key"`,
and `id_prefix` passes to every element the package draws.

Raises `ArgumentError` for a component map that names a kind the package
draws, or whose value for a type is not a function of one argument: both
are a host's wiring, never a visitor's input.

## Attributes

* `screen` (`:map`) (required) - The answer's `"screen"`: its `"key"` and its `"elements"`.
* `moves` (`:map`) (required) - The answer's `"moves"`: which buttons are drawn.
* `components` (`:map`) - The component map: for each of the host's own element types, the host's function component that draws it. Defaults to `%{}`.
* `findings` (`:list`) - The findings of a refused submit, `Riddler.Finding` structs or their wire form, passed to every question. Defaults to `[]`.
* `finding_text` (`:map`) - The text drawn, by finding code, for a finding whose author wrote no message, passed to every question. Defaults to `%{}`.
* `time_zone` (`:string`) - The visitor's time zone, passed to every text question, as `text_question/1` describes it. Defaults to `nil`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.
* `unknown_text` (`:string`) - The notice's text, drawn where the screen has an element nothing draws. Defaults to `"Part of this screen cannot be shown here, so it cannot be sent."`.
* `class` (`:any`) - Classes added to the notice's own. Defaults to `nil`.

# `frame`

```elixir
@spec frame(map()) :: Phoenix.LiveView.Rendered.t()
```

Draws a presented screen around its elements.

The screen is a `<section>`. Its title, when the screen has one, is the
section's `<h1>` and labels the section. Progress is drawn only when
`progress` is given, as a `<progress>` whose value is the step and whose
maximum is the number of steps; the package counts no steps itself. The
elements render inside the frame's inner block.

The title's `id` is derived from `id_prefix` and the screen's `"key"`, so
a page that draws two frames of the same screen at once passes each its
own `id_prefix`.

Given `findings`, the frame draws, between its progress and its elements,
each finding that names no question among the screen's `"elements"`, names
them as the section's description, and moves focus to the first finding of
the screen when the findings appear; the module's "Findings" section says
which finding is first.

The frame reads the questions from the `screen` it is given, so pass the
answer's `"screen"` whole. A screen map without `"elements"` names no
question, so the frame draws every finding, and a question the host draws
inside the frame draws it again.

## Attributes

* `screen` (`:map`) (required) - The answer's `"screen"`: its `"key"`, its `"title"`, a string or nil, and its `"elements"`.
* `findings` (`:list`) - The findings of a refused submit, `Riddler.Finding` structs or their wire form; the frame draws those no question of the screen draws. Defaults to `[]`.
* `finding_text` (`:map`) - The text drawn, by finding code, for a finding whose author wrote no message, in place of the package's own. Defaults to `%{}`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.
* `progress` (`:map`) - The answer's `"progress"`, `"step"` of `"of"`, or nil where the host supplied none. Defaults to `nil`.
* `progress_label` (`:string`) - The accessible name of the progress bar. Defaults to `"Progress"`.
* `refusals` (`:integer`) - The number of submits refused so far, where the host counts them; each new count moves focus to the first finding again. Defaults to `nil`.
* `class` (`:any`) - Classes added to the frame's own. Defaults to `nil`.
## Slots

* `inner_block` (required) - The screen's elements.

# `heading`

```elixir
@spec heading(map()) :: Phoenix.LiveView.Rendered.t()
```

Renders a `heading` element as the HTML heading of its `"level"`, `<h1>`
to `<h6>`.

A heading whose text is empty renders nothing: an empty heading names no
section and is read out as a bare heading.

Raises `ArgumentError` for a level outside 1 to 6, which riddler never
presents.

## Attributes

* `element` (`:map`) (required) - A `heading` element of the answer: its `"key"`, `"level"` and `"text"`.
* `class` (`:any`) - Classes added to the heading's own. Defaults to `nil`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.

# `image`

```elixir
@spec image(map()) :: Phoenix.LiveView.Rendered.t()
```

Renders an `image` element as an `<img>`.

The image's `"src"` is drawn as riddler presents it: riddler presents only
the URLs its rule admits, and the package checks none again. Its `"alt"`
is always drawn, so a visitor who cannot see the image is told what it
shows; an empty `"alt"` marks the image decorative and is drawn `alt=""`,
which tells such a visitor nothing. Its `"size"` and `"fit"`, hints a
renderer owns, are carried as `data-riddler-size` and `data-riddler-fit`
where they are strings, and are drawn no differently.

An image with no `"src"` renders nothing; riddler presents none.

## Attributes

* `element` (`:map`) (required) - An `image` element of the answer: its `"key"`, `"src"` and `"alt"` and, where present, `"size"` and `"fit"`.
* `class` (`:any`) - Classes added to the image's own. Defaults to `nil`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.

# `link`

```elixir
@spec link(map()) :: Phoenix.LiveView.Rendered.t()
```

Renders a `link` element as an `<a href>` whose text is its `"label"`.

A link is a plain navigation: it submits no form, carries no outcome and
pushes no event, and riddler never lists it among the `"outcomes"` of the
moves. Following it is the browser's navigation, of which the host hears
nothing. The `"href"` is drawn as riddler presents it: riddler presents
only the URLs its rule admits, and the package checks none again. The
link's `"style"`, a hint a renderer owns, is carried as
`data-riddler-style` where it is a string, and drawn no differently.

A link whose label is blank, or that has no `"href"`, renders nothing: a
link with no text is read out as a bare link.

## Attributes

* `element` (`:map`) (required) - A `link` element of the answer: its `"key"`, `"label"` and `"href"` and, where present, `"style"`.
* `class` (`:any`) - Classes added to the link's own. Defaults to `nil`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.

# `secret_question`

```elixir
@spec secret_question(map()) :: Phoenix.LiveView.Rendered.t()
```

Renders a `secret_question` element as a labelled password input that
never carries a value.

The input has no `value` attribute, whatever the element carries, and sets
`autocomplete="off"`, so nothing the visitor typed is drawn back into the
page or offered again by the browser. riddler presents no value for a
secret question, only `"held"`; where `"held"` is `true` a paragraph says
a value is held, and the input names it as part of its description.

The input carries `required` where the question is required and no value
is held: a held value already satisfies `required` in riddler's
validation. The question's `"help"`, when it has one, is a paragraph the
input names as its description too.

Given `findings`, the question draws those whose `element_key` is its
`"key"` after the input, names them in the input's description ahead of
what is held and the help, and marks the input `aria-invalid="true"`. No
finding carries the response, and a finding's `"message"` is not drawn.

The input's `id` is derived from `id_prefix` and the question's `"key"`.
Its `name` is `riddler-password[` and the key and `]` unless the host
passes one, so the submitted params carry the value under
`"riddler-password"`, keyed by the question's key. LiveView logs the
params of every event at the `:debug` level after Phoenix's
`:filter_parameters`, whose default filters each parameter whose name
contains `password`; the name keeps the value out of that log line
wherever the host keeps that default. A host that passes its own `name`
keeps the value out of the log itself.

## Attributes

* `element` (`:map`) (required) - A `secret_question` element of the answer: its `"key"`, `"label"` and `"held"` and, where present, `"help"` and `"required"`.
* `name` (`:string`) - The input's `name`; `riddler-password[` and the element's `"key"` and `]` when nil. Defaults to `nil`.
* `held_text` (`:string`) - The text shown where a value is held. Defaults to `"A value is held."`.
* `class` (`:any`) - Classes added to the question's own. Defaults to `nil`.
* `findings` (`:list`) - The findings of a refused submit, `Riddler.Finding` structs or their wire form; the question draws those whose `element_key` is its `"key"`. Defaults to `[]`.
* `finding_text` (`:map`) - The text drawn, by finding code, for a finding whose author wrote no message, in place of the package's own. Defaults to `%{}`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.

# `text`

```elixir
@spec text(map()) :: Phoenix.LiveView.Rendered.t()
```

Renders a `text` element as a paragraph.

The text's `"style"` is drawn as a class beside `riddler-text`:
`riddler-text-caption` for `"caption"`, and `riddler-text-body` for
`"body"`, for no style and for a style riddler does not offer, since a
text with no style is body.

## Attributes

* `element` (`:map`) (required) - A `text` element of the answer: its `"key"` and `"text"` and, where present, `"style"`.
* `class` (`:any`) - Classes added to the paragraph's own. Defaults to `nil`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.

# `text_question`

```elixir
@spec text_question(map()) :: Phoenix.LiveView.Rendered.t()
```

Renders a `text_question` element as a labelled text input.

The question's `"label"` is the input's `<label>`. Its `"help"`, when it
has one, is a paragraph the input names as its description. The input
carries the question's `"placeholder"`, and `required` where the question
is required. The value the answer presents for the question, a response
the visitor already gave or its prefill or default, is the input's
`value`; a presented value that is not text or a number is not drawn.

The `"format"` picks the input's `type`: `email` for `"email"`, `tel` for
`"phone"`, `date` for `"date"`, `time` for `"time"`, `datetime-local` for
`"datetime"` where the host passes a `time_zone`, and `text` for every
other format and for none, `"datetime"` without a `time_zone` among them.
The "A datetime question and the visitor's time zone" section below says
how a datetime-local input is drawn. A date or time input
carries the question's `"min"` and `"max"` as riddler presents them, which
admission holds to the format's shape, the shape the browser's own bounds
take. A time input moves by the minute, the browser's default, unless the
presented value or a bound carries seconds, when it carries `step="1"` and
moves by the second; never by a fraction of one. The values those inputs
submit, `YYYY-MM-DD` for a date and `HH:MM`, or `HH:MM:SS` where the input
moves by the second, for a time, are riddler's shapes for those formats as
submitted, so a host passes them on unchanged. The browser does not hold a
date to four digits of year, and riddler refuses a year it cannot read as
`response.format`. Every other input carries no `pattern`, `min` or `max`,
so the browser is not asked to check the format: riddler does.

The question's `"style"`, a hint, picks how the field is drawn where the
package draws that hint for the question's format:

  * `"multiline"`, under no format or `"pattern"`, is a `<textarea>` holding
    the presented value;
  * `"slider"`, under `"integer"` or `"number"` where `"min"` and `"max"` are
    both numbers, is an `<input type="range">` carrying them and the
    question's `"step"`; a range input has no empty value, so it submits
    the value it shows, its midpoint rounded to the step where the
    visitor moved nothing;
  * `"stepper"`, under `"integer"` or `"number"`, is an
    `<input type="number">` carrying the numeric `"min"` and `"max"` it has
    and the question's `"step"`.

The browser steps a range or a number input from its `min`, so under
`"integer"` a slider or a stepper is drawn only where every numeric bound
is a whole number, an integer or a float with no fractional part: from a
bound such as `0.5` it would offer only values riddler refuses as
`response.format`, and a range input always submits one. A slider or a
stepper with a bound that is not whole is drawn as the question with no
style.

A slider or a stepper with no `"step"` moves by one under `"integer"`, the
browser's default, and by any amount under `"number"`, `step="any"`.
riddler does not read the step when it validates, so the step the browser
holds the visitor to is the only one. Any other style, and a style under a
format it is not drawn for, is drawn as the question with no style: a
renderer that does not draw a hint loses nothing. A style that is a
non-blank string is carried as `data-riddler-style` either way.

The browser's own checks for the input's `type`, its bounds and step and
for `required` still run, and can stop a submit with the browser's own
message; a host that wants none of them draws the form itself and adds
`novalidate` to it.

Given `findings`, the question draws those whose `element_key` is its
`"key"` after the input, names them in the input's description ahead of
the help, and marks the input `aria-invalid="true"`; the module's
"Findings" section says what text each shows.

The input's `id` is derived from `id_prefix` and the question's `"key"`,
and its `name` is the key unless the host passes one.

## A datetime question and the visitor's time zone

riddler's `"datetime"` is an instant: a date and a time joined by `T`,
then `Z` or an offset `+HH:MM` or `-HH:MM`. The browser's
`<input type="datetime-local">` takes and submits a wall time with no
offset. Where the host passes `time_zone`, the visitor's time zone as a
name its configured `Calendar.TimeZoneDatabase` resolves, such as
`"America/Denver"`, the question is drawn as a datetime-local input, and
its presented `"value"`, `"min"` and `"max"` are drawn as the wall times
they are in that zone, `YYYY-MM-DDTHH:MM`, or `YYYY-MM-DDTHH:MM:SS` where
the presented text carries seconds. The input carries `step="1"` and
moves by the second where any of them carries seconds. A presented value
or bound not in riddler's datetime shape, or whose wall time in the zone
falls outside the four-digit years the input takes, is not drawn.

What the input submits is a wall time with no offset, which riddler
refuses as `response.format`; `RiddlerLiveView.Journey` adds the offset
before it hands the submit on, as its moduledoc's "A submit" section says.
A host that draws a datetime question itself, with this component, adds
the offset itself.

With no `time_zone`, or one the host's database does not resolve (Elixir's
default database knows only `"Etc/UTC"`), a datetime question is drawn as
a plain text input, with no bounds, and the visitor types the instant in
riddler's shape.

## Attributes

* `element` (`:map`) (required) - A `text_question` element of the answer: its `"key"`, `"label"` and, where present, `"help"`, `"placeholder"`, `"required"`, `"format"`, `"min"`, `"max"`, `"style"`, `"step"` and `"value"`.
* `time_zone` (`:string`) - The visitor's time zone, a name the host's `Calendar.TimeZoneDatabase` resolves; a `"datetime"` question is drawn as a datetime-local input in it. A plain text input when nil. Defaults to `nil`.
* `name` (`:string`) - The input's `name`; the element's `"key"` when nil. Defaults to `nil`.
* `class` (`:any`) - Classes added to the question's own. Defaults to `nil`.
* `findings` (`:list`) - The findings of a refused submit, `Riddler.Finding` structs or their wire form; the question draws those whose `element_key` is its `"key"`. Defaults to `[]`.
* `finding_text` (`:map`) - The text drawn, by finding code, for a finding whose author wrote no message, in place of the package's own. Defaults to `%{}`.
* `id_prefix` (`:string`) - The prefix of every `id` the component derives, `"riddler"` unless the host passes one; two Journeys on one page each pass their own. Defaults to `"riddler"`.

# `unknown_kinds`

```elixir
@spec unknown_kinds(map(), %{optional(String.t()) =&gt; (map() -&gt; term())}) :: [
  String.t() | nil
]
```

Answers the kinds of a screen's elements that neither the package nor the
component map draws, each once, in the order the screen first carries
them; `[]` where every element is drawn.

A screen with an element of such a kind is not to be submitted: the
module's "Elements of a kind the package does not draw" section says why.
An element whose `"type"` is not a string is of no kind anything draws;
it is answered as `nil`.

Raises `ArgumentError` for a component map `elements/1` refuses.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
