snowhite v2.1.3 Snowhite.Helpers.Html View Source
Link to this section Summary
Functions
Helpers that creates a class using by a given set of predicates.
Link to this section Types
Link to this section Functions
Specs
classes([class_type()], list()) :: String.t()
Helpers that creates a class using by a given set of predicates.
It supports the following format:
{function, true_class, false_class}
: if the function is true, the true_class is prepended, otherwise the false_class.{function, class}
: if the function is true, the class is prepended.function
: returns the result of the given functionclass
: always present
Examples
iex> conditions = [
{fn user -> user.age > 18 end, "is-adult"},
{fn user -> user.state == true end, "is-active", "is-inactive"},
fn user -> if user.gender == :female, do: "is-female", else: "is-male" end,
"user"
]
iex> classes(conditions, [%{age: 20, active: true, gender: :female}])
"user is-female is-active is-adult"
iex> classes(conditions, [%{age: 10, active: true, gender: :male}])
"user is-male is-active"
iex> classes(conditions, [%{age: 10, active: false, gender: :female}])
"user is-female is_inactive"