A2UI.Component (A2UI v0.3.0)

Copy Markdown View Source

Represents an A2UI component in the adjacency list.

Components are flat — parent-child relationships use ID references via child/children props.

Summary

Functions

Parses a raw JSON map into a Component struct.

Converts a Component struct back to a JSON-compatible map.

Types

t()

@type t() :: %A2UI.Component{
  accessibility: map() | nil,
  id: String.t(),
  props: map(),
  type: String.t()
}

Functions

from_map(map)

@spec from_map(map()) :: t()

Parses a raw JSON map into a Component struct.

Extracts id, component (as type), and accessibility. All remaining keys become props.

Examples

iex> A2UI.Component.from_map(%{"id" => "header", "component" => "Text", "text" => "Hello", "variant" => "h1"})
%A2UI.Component{id: "header", type: "Text", props: %{"text" => "Hello", "variant" => "h1"}}

to_map(component)

@spec to_map(t()) :: map()

Converts a Component struct back to a JSON-compatible map.

Inverse of from_map/1. Props are spread as top-level keys, and "accessibility" is included only when non-nil.

Examples

iex> A2UI.Component.to_map(%A2UI.Component{id: "h", type: "Text", props: %{"text" => "Hi"}})
%{"id" => "h", "component" => "Text", "text" => "Hi"}