# `Wiztchta.Components`
[🔗](https://github.com/darth-jorge/wiztcha/blob/v0.1.0/lib/wiztchta/components.ex#L1)

Function components for rendering challenges inside forms.

Import them app-wide, e.g. in the `html_helpers` of `my_app_web.ex`:

    import Wiztchta.Components

# `wiztchta`

Renders a challenge plus the hidden token input. Place it inside any form.

In controllers/dead views a fresh challenge is generated on every render:

    <.form for={@form} action={~p"/contact"}>
      ...
      <.wiztchta />
    </.form>

In LiveViews, keep the challenge in an assign so re-renders don't replace
it, and assign a new one after each submit:

    socket = assign(socket, :challenge, Wiztchta.new())

    <.wiztchta challenge={@challenge} />

## Attributes

* `challenge` (`Wiztchta.Challenge`) - a challenge from `Wiztchta.new/1`; generated on render when nil. Defaults to `nil`.
* `type` (`:atom`) - challenge module, when generating on render. Defaults to `nil`.
* `opts` (`:list`) - options for `Wiztchta.new/1`, when generating on render. Defaults to `[]`.
* `id` (`:string`) - DOM id; must be unique per page. Defaults to `"wiztchta"`.
* `name` (`:string`) - form param name; defaults to the `:param` config. Defaults to `nil`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.

---

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