LiveStyle.Attrs (LiveStyle v0.12.0)
View SourceA struct representing HTML attributes for styled elements.
This struct implements Phoenix.HTML.Safe and can be spread directly
into HEEx templates:
~H"""<button {css([:base, :primary])}>Click me</button>"""Fields
:class- Space-separated class names (string):style- Inline styles for dynamic values (string or nil):prop_classes- Property-to-class mappings for merging (internal use)
Summary
Functions
Extracts just the class string from an Attrs struct.
Converts the Attrs struct to a keyword list suitable for spreading into HTML elements.
Types
Functions
Extracts just the class string from an Attrs struct.
Converts the Attrs struct to a keyword list suitable for spreading into HTML elements.
When spreading onto a component, the full Attrs struct is passed as the class value so that property classes can be merged. When rendering to HTML, Phoenix.HTML.Safe converts the struct to just the class string.
Examples
iex> LiveStyle.Attrs.to_list(%LiveStyle.Attrs{class: "btn", style: nil})
[class: %LiveStyle.Attrs{class: "btn", style: nil, prop_classes: nil}]
iex> LiveStyle.Attrs.to_list(%LiveStyle.Attrs{class: "btn", style: "--x: 1"})
[class: %LiveStyle.Attrs{class: "btn", style: "--x: 1", prop_classes: nil}, style: "--x: 1"]