Classes (classes v1.0.0) View Source
A pure function for generating CSS classes.
Link to this section Summary
Functions
Returns a string containing CSS.
Link to this section Functions
Returns a string containing CSS.
The argument can be any of the following:
- String or atom containing a CSS class or classes.
- Keyword list or map with string or atom keys. The key is a CSS class and the value is treated as a boolean indicating whether or not the class should be included.
nil
andfalse
are filtered.- Lists, including deeply nested lists, containing any of the above types.
This function does not dedupe classes.
Examples
iex> classes("my-class")
"my-class"
iex> classes(:myclass)
"myclass"
iex> classes(["one", :two])
"one two"
iex> classes(yes: true, no: false)
"yes"
iex> classes(%{"string-key" => true, "atom-key": true})
iex> classes(yes: "I'm truthy", no: nil)
"yes"
iex> classes([%{"one" => true}, [two: false, three: true]])
"one three"
iex> classes([{"string-key-tuple", true}, {"also-happens-to_work", nil}])
"string-key-tuple"
iex> classes([[[nil, false, "hello", :world]]])
"hello world"
iex> classes([{"invalid argument"}])
** (FunctionClauseError) no function clause matching in Classes.class_list/1