OpenUI.LiveView.Components (OpenUI v0.1.1)

Copy Markdown View Source

Maps a library's components to the host's function components.

defmodule MyAppWeb.AssistantUI do
  use OpenUI.LiveView.Components,
    library: MyApp.Library,
    fields: %{"Input" => [name: "name", type: "input"]},
    forms: %{"Form" => "name"}

  def line_chart(assigns), do: ~H"..."
end

Every catalog component needs a function named after it in snake case (LineChart is line_chart/1), or the module does not compile. fields names the components that are form fields (the prop that holds the field name and the field's component type), and forms the components that give a form name to their subtree (and the prop that holds it). A form component renders a <fieldset> or a <div>, never a <form>: the renderer already wraps the program in one.

The assigns each function receives are described in OpenUI.LiveView.