# `A2UICore.State.Component`
[🔗](https://github.com/a2ui-elixir/a2ui/blob/v0.1.1/umbrella/apps/a2ui_core/lib/a2ui_core/state/component.ex#L1)

One component instance on a surface: its id, catalog type, and
properties.

The wire form is a flat object — `{"id": "title", "component": "Text",
"text": "Hello"}`. A `Component` splits that into `id`, `type` and
`props` (everything else), and `tree/1` puts it back together.

A component optionally records the `catalog_id` it was created
against, so a surface holding components from several catalogs can
look up each one's schema and child-reference spec.

Child references are derived from a `A2UICore.Catalog.RefSpec`, which
the catalog supplies for the component's type (see
`child_references/3`).

    iex> alias A2UICore.State.Component
    iex> component = Component.from_wire(%{"id" => "c", "component" => "Card", "child" => "t"})
    iex> {component.id, component.type, component.props}
    {"c", "Card", %{"child" => "t"}}
    iex> Component.tree(component)
    %{"id" => "c", "component" => "Card", "child" => "t"}

# `info`
*since 0.1.0* 

```elixir
@type info() :: %{
  optional(:ref_spec) =&gt; A2UICore.Catalog.RefSpec.t() | nil,
  optional(:allowed_parents) =&gt; [String.t()] | nil,
  optional(:allowed_children) =&gt; [String.t()] | nil
}
```

What a catalog knows about a component type: the child-reference spec
and the composition constraints (`nil` or `[]` means unconstrained).

# `t`
*since 0.1.0* 

```elixir
@type t() :: %A2UICore.State.Component{
  catalog_id: String.t() | nil,
  id: String.t(),
  props: map(),
  type: String.t()
}
```

# `child_references`
*since 0.1.0* 

```elixir
@spec child_references(t(), A2UICore.Catalog.RefSpec.t() | nil, Enumerable.t() | nil) ::
  [
    A2UICore.Catalog.RefSpec.child_ref()
  ]
```

The `{child_id, property_path}` pairs this component references.

A catalog's `spec` is authoritative when it names child properties.
Without one (an unknown type, or a schema with no `ComponentId` /
`ChildList` references) the references are inferred from property
names and shapes: `child`, `children`, `*Child`, values holding a
`componentId` / `child` key, and — when `known_ids` is given — strings
naming a component on the surface.

# `from_wire`
*since 0.1.0* 

```elixir
@spec from_wire(map(), keyword()) :: t()
```

Builds a component from a wire object (`id`, `component`, and the
properties).

# `new`
*since 0.1.0* 

```elixir
@spec new(String.t(), String.t(), map(), keyword()) :: t()
```

Builds a component from its parts.

# `tree`
*since 0.1.0* 

```elixir
@spec tree(t()) :: map()
```

The wire object: the properties plus `id` and `component`.

---

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