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.
Summary
Functions
Defines a library in a module
Finds a custom action by name.
Finds a component by name.
Reads a LibrarySpec, given as JSON text or as a decoded OpenUI.JSON.Object.
Finds a custom function by name.
Returns the library itself, or the library a module defines with use OpenUI.Library.
Returns the LibrarySpec of a library or of a module that uses OpenUI.Library.
Types
@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 }
Functions
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."]
endSee OpenUI.Library.DSL for the macros and the prop types.
@spec action(t(), String.t()) :: OpenUI.Library.Callable.t() | nil
Finds a custom action by name.
@spec component(t(), String.t()) :: OpenUI.Library.Component.t() | nil
Finds a component by name.
@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.
@spec function(t(), String.t()) :: OpenUI.Library.Callable.t() | nil
Finds a custom function by name.
Returns the library itself, or the library a module defines with use OpenUI.Library.
@spec to_spec(t() | module()) :: OpenUI.JSON.Object.t()
Returns the LibrarySpec of a library or of a module that uses OpenUI.Library.