# `OpenUI.Library`
[🔗](https://github.com/ideia4it/openui/blob/v0.1.1/lib/openui/library.ex#L1)

A component library: the components, custom functions, custom actions and
groups a program may use (prompt.md, section 2).

A library comes from a LibrarySpec document with `from_spec/2`, or from a
module defined with `use OpenUI.Library`. Either way `to_spec/1` gives the
LibrarySpec back, ready to share with other clients.

# `t`

```elixir
@type t() :: %OpenUI.Library{
  actions: [OpenUI.Library.Callable.t()],
  components: [OpenUI.Library.Component.t()],
  functions: [OpenUI.Library.Callable.t()],
  groups: [OpenUI.Library.Group.t()],
  id: String.t() | nil,
  root: String.t() | nil,
  spec: OpenUI.JSON.Object.t() | nil,
  version: String.t() | nil
}
```

# `__using__`
*macro* 

Defines a library in a module:

    defmodule MyApp.Library do
      use OpenUI.Library, id: "myapp", version: "1.0.0", root: "Stack"

      component "Stack",
        description: "Lays out children in a column",
        props: [children: [type: {:array, :component}, required: true]]

      function "Percent",
        description: "Part over total as a percentage",
        params: [part: [type: :number, required: true], total: [type: :number, required: true]],
        returns: :string,
        impl: &MyApp.Formulas.percent/1

      action "CopyToClipboard", description: "Copies text", params: [text: [type: :string, required: true]]

      group "Layout", ["Stack"], notes: ["Wrap every page in a Stack."]
    end

See `OpenUI.Library.DSL` for the macros and the prop types.

# `action`

```elixir
@spec action(t(), String.t()) :: OpenUI.Library.Callable.t() | nil
```

Finds a custom action by name.

# `component`

```elixir
@spec component(t(), String.t()) :: OpenUI.Library.Component.t() | nil
```

Finds a component by name.

# `from_spec`

```elixir
@spec from_spec(binary() | OpenUI.JSON.Object.t(), keyword()) ::
  {:ok, t()} | {:error, [String.t()]}
```

Reads a LibrarySpec, given as JSON text or as a decoded `OpenUI.JSON.Object`.

Custom functions have no implementation in the spec; pass them as
`functions: %{"Name" => fun}`, each `fun` taking one map keyed by the param
names.

# `function`

```elixir
@spec function(t(), String.t()) :: OpenUI.Library.Callable.t() | nil
```

Finds a custom function by name.

# `resolve`

```elixir
@spec resolve(t() | module()) :: t()
```

Returns the library itself, or the library a module defines with `use OpenUI.Library`.

# `to_spec`

```elixir
@spec to_spec(t() | module()) :: OpenUI.JSON.Object.t()
```

Returns the LibrarySpec of a library or of a module that uses `OpenUI.Library`.

---

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