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
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"]
Gets the values
option for a given component and prop.
examples
Examples
iex> get_prop_value_opts(Core, :icon, :attrs, :name) |> Enum.length()
876
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")
Translates the errors for a field from a keyword list of errors.