Macaw.Component.Drawn (macaw_component v0.1.2)

Copy Markdown View Source

Drawn states (spec/02 §6): every component is always in exactly one, in this precedence, each but live with a theme role, a glyph and words, and never blank.

iex> Macaw.Component.Drawn.pick([:stale, :loading])
:loading
iex> Macaw.Component.Drawn.role(:no_data)
:neutral

Summary

Functions

The eight states, in precedence order.

The glyph of the state's role's cue (Macaw.Layers.Theme.cue/1), nil for live.

The state of highest precedence among a list, :live for [].

A static notice for a state other than live: a paragraph with the state's class and data-mw-drawn, a glyph element of the role's class hidden from assistive technology, then the words. It is not a live region, so it holds in every mode. live is empty.

The state's theme role, nil for live.

The state's words, nil for live.

Types

t()

@type t() ::
  :crashed | :down | :invalid | :loading | :no_data | :stale | :capped | :live

Functions

all()

@spec all() :: [t(), ...]

The eight states, in precedence order.

glyph(state)

@spec glyph(t()) :: atom() | nil

The glyph of the state's role's cue (Macaw.Layers.Theme.cue/1), nil for live.

pick(states)

@spec pick([t()]) :: t()

The state of highest precedence among a list, :live for [].

render(state, context)

@spec render(t(), Macaw.Component.Context.t() | nil) :: Phoenix.HTML.safe()

A static notice for a state other than live: a paragraph with the state's class and data-mw-drawn, a glyph element of the role's class hidden from assistive technology, then the words. It is not a live region, so it holds in every mode. live is empty.

iex> Macaw.Component.Drawn.render(:no_data, nil) |> Phoenix.HTML.safe_to_string()
~s(<p class="mw-drawn mw-drawn-no-data" data-mw-drawn="no_data"><span class="mw-glyph mw-glyph-diamond mw-role-neutral" aria-hidden="true"></span> No data</p>)

role(state)

@spec role(t()) :: atom() | nil

The state's theme role, nil for live.

words(state)

@spec words(t()) :: String.t() | nil

The state's words, nil for live.