# `MishkaGervaz.UIAdapters.Dynamic`
[🔗](https://github.com/mishka-group/mishka_gervaz/blob/v0.0.1-alpha.3/lib/mishka_gervaz/ui_adapters/dynamic.ex#L1)

Dynamic UI adapter for database-driven components.

Loads components from a database (or any user-supplied source) and renders
them at runtime. When the configured component is not available, falls
back to another `MishkaGervaz.Behaviours.UIAdapter` implementation
(Tailwind by default).

## Configuration

Set this adapter on the DSL with the renderer and resolver:

    presentation do
      ui_adapter :dynamic
      ui_adapter_opts [
        site: "Global",
        component_renderer: &MishkaCmsCore.Runtime.LiveViewHelpers.component/1,
        module_resolver: &MishkaCmsCore.Runtime.Compilers.Helpers.module_name/3,
        fallback: MishkaGervaz.UIAdapters.Tailwind
      ]
    end

## Options

  * `:site` — site identifier passed to the renderer (default `"Global"`)
  * `:component_renderer` — `(assigns) -> Phoenix.LiveView.Rendered.t()`
    called with `:component_name` and `:site` injected into the assigns
  * `:module_resolver` — `(component_name, site, kind) -> module()` used
    to test whether the dynamic component is actually loaded
  * `:fallback` — adapter to delegate to when the dynamic component is
    unavailable or the renderer is not configured (default
    `MishkaGervaz.UIAdapters.Tailwind`)

Every callback declared on `MishkaGervaz.Behaviours.UIAdapter` is wired
identically: try the dynamic renderer, fall back if unavailable. The list
is taken from `MishkaGervaz.Behaviours.UIAdapter.component_functions/0`,
so adding a new behaviour callback automatically lights up here.

# `__using__`
*macro* 

Use this module to create a Dynamic adapter with pre-configured options.

## Options

Same as the module-level options — `:site`, `:fallback`,
`:component_renderer`, `:module_resolver`.

## Example

    defmodule MyApp.GervazUIAdapter do
      use MishkaGervaz.UIAdapters.Dynamic,
        site: "Global",
        component_renderer: &MyApp.LiveViewHelpers.component/1,
        module_resolver: &MyApp.Compilers.Helpers.module_name/3,
        fallback: MishkaGervaz.UIAdapters.Tailwind
    end

# `with_config`

```elixir
@spec with_config(
  map(),
  keyword()
) :: map()
```

Adds the Dynamic adapter configuration to an assigns map.

## Options

  * `:site` (default `"Global"`)
  * `:fallback` (default `MishkaGervaz.UIAdapters.Tailwind`)
  * `:component_renderer` (optional)
  * `:module_resolver` (optional)

## Example

    assigns = MishkaGervaz.UIAdapters.Dynamic.with_config(assigns,
      site: "MyApp",
      component_renderer: &MyApp.Runtime.component/1,
      module_resolver: &MyApp.Runtime.module_name/3,
      fallback: MyApp.UIAdapters.Custom
    )

---

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