Defines typed Phoenix function components for Xenia adapters.
Example
defmodule MyAppWeb.Components do
use Xenia.Components
component :chart,
adapter: "Chart",
doc: "Renders an interactive chart." do
prop :type, :string, required: true
prop :data, :map, default: %{}
event :click
end
endThe generated component can be used in HEEx:
<.chart
id="sales"
type="bar"
data={@sales}
on_click="bar_clicked"
/>Each declaration generates a normal Phoenix function component:
prop name, type, optsbecomes a Phoenixattrand is passed to the JavaScript adapter as a prop.Optional props that are absent are omitted. Explicit defaults are included.
event namebecomesattr :on_<name>, :string. Events without a binding are omitted.Components normally require
id. Declarations withform_value: :propalso acceptfield={@form[:name]}, using the field's id by default.Every component supports global HTML attributes,
shortcuts,on_crash, and the<:loading>and<:error>slots (seeXenia.Component).
Rendering is delegated to Xenia.Component.xenia/1.
The adapter must be registered separately in JavaScript
using createHooks().
Summary
Functions
Enables the Xenia component declaration DSL.
Generates a typed Phoenix function component.
Functions
Enables the Xenia component declaration DSL.
Generates a typed Phoenix function component.
Options
:adapter- required JavaScript adapter registration name, or a co-located adapter's".Name", defined in this module (seeXenia.Component.colocated/1).:form_value- optional declared prop name used as a Phoenix form value.:doc- optional documentation string.
Supported declarations
prop :name, :string
prop :data, :map, default: %{}
prop :type, :string, required: true
event :changeInvalid declarations raise ArgumentError during compilation.