Alternera.Resource.UI.Components (alternera_resource_ui v0.9.0)

Copy Markdown View Source

The building blocks a package's components draw with, beside the proxy's look in Alternera.UIKit: buttons, cards, a table of records, a resource's actions and a field's value as the generated page shows it. use Alternera.Resource.UI imports them.

The proxy may draw a block its own way: config :alternera_resource_ui, :components, Module names a module whose function of the same name and arity 1, when it exports one, draws it instead (the proxy's are AlterneraWeb.ResourceUIComponents). Without one, as in a package's own tests, the block draws itself here, with the same assigns.

Summary

Functions

A button that runs one declared action of the context's resource through the host's action runner: on record when given, else on the resource.

The resource's declared actions that act on on ("resource" or "record", which takes the selection actions too, run on that record alone), as buttons the viewer may press. They run through the host's action runner, which asks for input and confirmation and reports the outcome; record is the record a record action acts on.

A button in the proxy's look: variant is primary, secondary, danger, success, warning, outline or danger-outline; size md, sm or xs.

A card: the proxy's bordered box, with an optional title and actions in its header.

An empty state: a muted line, with an optional action below it.

A table of records: columns are attribute names (by default the resource's list fields); cell overrides how a column draws (<:cell :let={{field, record}}>); on_row is a phx-click for a row (phx-value-id is the record's id, Alternera.Resource.UI.record_id/1). The host draws its cells, with the resource's declared cell components, where it has a table of its own.

A field's value as the generated page shows it: blank as an em dash, booleans as Yes/No.

Functions

action_button(assigns)

A button that runs one declared action of the context's resource through the host's action runner: on record when given, else on the resource.

Attributes

  • ctx (Alternera.Resource.UI.Context) (required)
  • action (:atom) (required)
  • record (:any) - Defaults to nil.
  • variant (:string) - Defaults to "secondary".
  • size (:string) - Defaults to "sm".
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • inner_block (required)

actions(assigns)

The resource's declared actions that act on on ("resource" or "record", which takes the selection actions too, run on that record alone), as buttons the viewer may press. They run through the host's action runner, which asks for input and confirmation and reports the outcome; record is the record a record action acts on.

Attributes

  • ctx (Alternera.Resource.UI.Context) (required)
  • on (:string) - Defaults to "record". Must be one of "resource", or "record".
  • record (:any) - Defaults to nil.
  • size (:string) - Defaults to "sm".
  • class (:any) - Defaults to nil.

button(assigns)

A button in the proxy's look: variant is primary, secondary, danger, success, warning, outline or danger-outline; size md, sm or xs.

Attributes

  • variant (:string) - Defaults to "secondary". Must be one of "primary", "secondary", "danger", "success", "warning", "outline", or "danger-outline".
  • size (:string) - Defaults to "md". Must be one of "md", "sm", or "xs".
  • type (:string) - Defaults to "button".
  • class (:any) - Defaults to nil.
  • Global attributes are accepted. Supports all globals plus: ["disabled", "form", "name", "value"].

Slots

  • inner_block (required)

card(assigns)

A card: the proxy's bordered box, with an optional title and actions in its header.

Attributes

  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • title
  • actions
  • inner_block (required)

empty(assigns)

An empty state: a muted line, with an optional action below it.

Attributes

  • class (:any) - Defaults to nil.

Slots

  • inner_block (required)
  • action

record_table(assigns)

A table of records: columns are attribute names (by default the resource's list fields); cell overrides how a column draws (<:cell :let={{field, record}}>); on_row is a phx-click for a row (phx-value-id is the record's id, Alternera.Resource.UI.record_id/1). The host draws its cells, with the resource's declared cell components, where it has a table of its own.

Attributes

  • id (:string) (required)
  • records (:list) (required)
  • ctx (Alternera.Resource.UI.Context) (required)
  • resource (:atom) - the records' resource, by default the context's. Defaults to nil.
  • columns (:list) - Defaults to nil.
  • on_row (:any) - Defaults to nil.
  • target (:any) - Defaults to nil.
  • empty (:string) - Defaults to "No records".

Slots

  • cell

value(assigns)

A field's value as the generated page shows it: blank as an em dash, booleans as Yes/No.

Attributes

  • value (:any) (required)