# `PhoenixCap.Components`
[🔗](https://github.com/elchemista/phoenix_cap/blob/v0.1.0/lib/phoenix_cap/components.ex#L2)

HEEx components for the PhoenixCap assets and widget.

Add `<PhoenixCap.Components.assets />` to your root layout and render
`<PhoenixCap.Components.widget id="signup-captcha" />` in your form.

# `assets`

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

Loads the widget and theme from the endpoint. Render once in the root layout.

    <PhoenixCap.Components.assets />

For a custom mount, pass the same public path to both components.

## Attributes

* `endpoint` (`:string`) - Public path where PhoenixCap is mounted. Defaults to `"/cap"`.
* `nonce` (`:string`) - Optional CSP nonce for the widget script. Defaults to `nil`.

# `widget`

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

Renders a widget with a stable DOM ID. An enclosing form automatically
submits the hidden `cap-token` field. To position the widget elsewhere,
set `form` to the target form's ID.

    <PhoenixCap.Components.widget id="signup-check" form="signup" />

A standalone widget emits a `solve` event with the token in
`event.detail.token`. See the [JavaScript guide](javascript.md).

## Attributes

* `id` (`:string`) (required) - Stable DOM ID of the widget.
* `endpoint` (`:string`) - Public path where PhoenixCap is mounted. Defaults to `"/cap"`.
* `form` (`:string`) - DOM ID of the form to associate with the widget. Defaults to `nil`.
* `required` (`:boolean`) - Require a solved widget before submitting its form. Defaults to `true`.
* Global attributes are accepted.

---

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