PhxComponentHelpers.extend_class
You're seeing just the function
extend_class
, go back to PhxComponentHelpers module for more information.
Set assigns with class attributes.
The class attribute will take provided default_classes
as a default value and will
be extended, on a class-by-class basis, by your assigns.
This function will identify default classes to be replaced by assigns on a prefix basis:
- "bg-gray-200" will be overwritten by "bg-blue-500" because they share the same "bg-" prefix
- "hover:bg-gray-200" will be overwritten by "hover:bg-blue-500" because they share the same "hover:bg-" prefix
- "m-1" would not be overwritten by "mt-1" because they don't share the same prefix ("m-" vs "mt-")
Parameters
assigns
- your component assignsdefault_classes
- the default classes that will be overridden by your assigns. This parameter can be a binary or a single parameter function that receives all assigns and returns a binary
Options
:attribute
- read & write css classes from & into this key
Example
assigns
|> extend_class("bg-blue-500 mt-8")
|> extend_class("py-4 px-2 divide-y-8 divide-gray-200", attribute: :wrapper_class)
|> extend_class(fn assigns ->
default = "p-2 m-4 text-sm "
if assigns[:active], do: default <> "bg-indigo-500", else: default <> "bg-gray-200"
end)
assigns
now contains @raw_class
and @raw_wrapper_class
.
If your input assigns were %{class: "mt-2", wrapper_class: "divide-none"}
then:
@raw_class
would contain"bg-blue-500 mt-2"
@raw_wrapper_class
would contain"py-4 px-2 divide-none"