LedgerUI.Helpers (LedgerUI v0.2.0)

Copy Markdown View Source

Small helpers shared by all components.

Summary

Functions

Renders a boolean as the strings "true" / "false" (for aria-* attributes).

Joins class values into a single string, dropping empties.

Functions

bool_attr(value)

@spec bool_attr(term()) :: String.t()

Renders a boolean as the strings "true" / "false" (for aria-* attributes).

iex> LedgerUI.Helpers.bool_attr(true)
"true"
iex> LedgerUI.Helpers.bool_attr(nil)
"false"

cx(list)

@spec cx(term()) :: String.t()

Joins class values into a single string, dropping empties.

Accepts strings, nil, false, {class, condition} tuples and nested lists.

iex> LedgerUI.Helpers.cx(["lu-btn", nil, false, {"on", true}, {"off", false}, ["a", " "], "b  c"])
"lu-btn on a b c"

iex> LedgerUI.Helpers.cx([nil])
""