View Source Pyro.Component.Helpers (Pyro v0.0.2)

A library of helpers for using/authoring Pyro components.

Link to this section Summary

Functions

Extract a value from nested structures (e.g. assigns) for a given key or path of keys with an optional fallback value (defaults to nil).

Gets the values option for a given component and prop.

A JS function to toggle CSS classes, since Phoenix does not yet provide one out of the box.

Translates the errors for a field from a keyword list of errors.

Link to this section Functions

Link to this function

get_by_path(value, keys, default \\ nil)

View Source
@spec get_by_path(any(), atom() | [atom()], any()) :: any()

Extract a value from nested structures (e.g. assigns) for a given key or path of keys with an optional fallback value (defaults to nil).

examples

Examples

iex> get_by_path(assigns(), :class)
"bg-red-500"

iex> get_by_path(assigns(), [:user, :name])
"John Doe"

iex> get_by_path(assigns(), [:picks, :libs])
"Ash"

iex> get_by_path(assigns(), [:user, :non_existing_field], "N/A")
"N/A"

iex> get_by_path(assigns(), nil, "N/A")
"N/A"

iex> get_by_path(nil, :name, "N/A")
"N/A"

iex> get_by_path(Core.__components__, [:button, :overridables, &(&1.name == :color), :opts, :values])
["root", "primary", "red", "yellow", "green"]
Link to this function

get_prop_value_opts(module, component, kind, name)

View Source
@spec get_prop_value_opts(module(), atom(), :attrs | :slots, atom()) :: any()

Gets the values option for a given component and prop.

examples

Examples

iex> get_prop_value_opts(Core, :icon, :attrs, :name) |> Enum.length()
876
Link to this function

toggle_class(js \\ %JS{}, classes, opts)

View Source
@spec toggle_class(js :: map(), classes :: String.t(), opts :: keyword()) :: map()

A JS function to toggle CSS classes, since Phoenix does not yet provide one out of the box.

examples

Examples

toggle_class("rotate-180 bg-green", to: "#icon")
Link to this function

translate_errors(errors, field)

View Source

Translates the errors for a field from a keyword list of errors.