Aurora. Uix. Layout. ResourceMetadata
(Aurora UIX v0.1.4-rc.2)
Copy Markdown
Provides a comprehensive, declarative UI configuration system for structured data in Phoenix LiveView.
Enables rich, metadata-driven UI configuration for data structures with flexible field-level UI metadata management and seamless integration with Phoenix LiveView.
Configuration Strategies
- Field-level customization
- Bulk field configuration
- Automatic default generation based on field types
- Inheritance and extension of configurations
Supported Field Attributes
- Labels and placeholders
- Input types and lengths
- Validation rules (e.g. required)
- Rendering options (readonly, hidden, disabled)
- Precision and scale for numeric fields
- Custom rendering via component or function
- Omission flag to exclude fields entirely (
:omitted)
Example
defmodule MyApp.Product do
use Ecto.Schema
import Ecto.Changeset
schema "products" do
field :name, :string
field :price, :float
field :quantity, :integer
belongs_to :category, MyApp.Category
timestamps()
end
end
defmodule MyApp.Category do
use Ecto.Schema
import Ecto.Changeset
schema "categories" do
field :name, :string
has_many :products, MyApp.Product
timestamps()
end
end
defmodule MyAppWeb.Inventory.Views do
auix_resource_metadata :product, schema: MyApp.Product, context: MyApp.Inventory do
field :id, hidden: true
field :name, placeholder: "Product name", max_length: 40, required: true
field :price, placeholder: "Price", precision: 12, scale: 2
end
auix_resource_metadata :category, schema: MyApp.Category do
field :id, readonly: true
field :name, max_length: 20, required: true
field :products, resource: :product
end
end
Summary
Functions
Defines UI configuration for a schema.
Configures a single field within a resource configuration.
Applies configuration to multiple fields simultaneously.
Functions
Defines UI configuration for a schema.
Parameters
name(atom()) - Resource identifier.opts(keyword()) - Configuration options.do_block(Macro.t() | nil) - Field configurations block.
Options
Common Options
:order_by(atom() | list() | keyword()) - Order used for displaying the index.- atom() - Single field name (e.g.,
:name) - list() - List of field names
- keyword() - Direction-annotated fields (e.g.,
[desc: :created_at]) See Ecto.Query.order_by/3 for details about the supported directions.
- atom() - Single field name (e.g.,
Context-based Integration (:ctx type)
For Ecto schema resources with Context modules:
:schema(module()) - Required. Ecto schema module.:context(module()) - Required. Context module with CRUD functions.
Ash Framework Integration (:ash type)
For Ash Framework resources:
:ash_resource(module()) - Required. Ash resource module.:ash_actor_assign(atom()) - Optional. Name of thesocket.assignskey that holds the actor for policy-protected resources. When set, every generated CRUD call forwardsactor: socket.assigns[<assign>]to Ash (Ash.read/get/create/ update/destroy/loadandAshPhoenix.Form.for_update). When unset (default), noactor:is added, preserving the previous behaviour for resources that do not useAsh.Policy.Authorizer.:actor_assignis accepted as a shorthand alias.authorize?:is never set explicitly — the host domain's ownauthorizeconfig decides whether policies run. See the Ash integration guide — Authorization & policies for the worked example, behaviour matrix, and troubleshooting.
Note: You can also use :schema as an alias for :ash_resource when working with Ash resources.
context is irrelevant as ash resources know the domain that they belong to.
Examples
Context-based Resource
auix_resource_metadata(:product,
schema: MyApp.Inventory.Product,
context: MyApp.Inventory,
order_by: :reference
)Context Resource with Sort Direction
auix_resource_metadata(:product,
schema: MyApp.Inventory.Product,
context: MyApp.Inventory,
order_by: [desc: :created_at]
)Ash Resource
auix_resource_metadata(:author,
ash_resource: MyApp.Blog.Author,
order_by: [:name]
)Ash Resource with policy-protected actions (actor threading)
auix_resource_metadata(:template,
ash_resource: MyApp.Templates.InterfaceDocumentTemplate,
ash_actor_assign: :current_user
)Returns
Macro.t() - Configured metadata block for the resource.
Configures a single field within a resource configuration.
Provides fine-grained control over field presentation, validation, and interaction rules. Supports comprehensive customization of individual fields.
Parameters
field(atom() | tuple()): The name of the field to configureopts(keyword()): Field-specific configuration options
Options
The following options can be provided to configure the field:
:key(atom()| tuple()) - The referred field in the schema. This should be rarely changed.:type(atom()) - The html type that best represent the current field elixir type.:label(binary()) - A custom label for the field. (auto-generated from field name if omitted).:placeholder(binary()) - Placeholder text for the field.:length(non_neg_integer()) - Display length of the field.:precision(integer()) - The numeric precision for decimal or float fields.:scale(integer()) - The numeric scale for decimal or float fields.:readonly(boolean()) - Marks the field as read-only.:hidden(boolean()) - Hides the field.:filterable?(boolean()) - If true, allows the field to participate in UI filtering.:renderer(function()) - Custom rendering function/component.:required(boolean()) - Marks the field as required.:disabled(boolean()) - If true, the field should not participate in form interaction.:omitted(boolean()) - If true, the field will be entirely excluded from the UI and configuration.
Example
field :name, label: "Product Name", placeholder: "Enter product name", required: true
field :price, precision: 12, scale: 2, label: "Price ($)"
Applies configuration to multiple fields simultaneously.
Enables bulk configuration of fields, reducing repetitive code and promoting consistent field settings across multiple attributes.
Parameters
fields(list() of atoms or tuples): Fields to be configuredopts(keyword()): Configuration options applied to all specified fields
Example
fields [:msrp, :rrp, :list_price], precision: 10, scale: 2