Athanor.Components.Formatting (Athanor v0.1.0-beta.1)

Copy Markdown View Source

Shared formatting surface for Athanor primitives.

Every component that ships with Athanor wraps its render output in apply/1, which emits a div with the inline styles + alignment class derived from node["props"]["formatting"]. The field set matches the legacy host-app formatting config exactly, so existing prod data round-trips byte-equal.

Field set (matches legacy @style_options)

  • text_color hex like "#000000"
  • background_color hex
  • padding_top integer px
  • padding_bottom integer px
  • padding_left integer px
  • padding_right integer px
  • border_radius integer px
  • border_width integer px
  • border_color hex
  • margin_top integer px
  • margin_bottom integer px
  • margin_left integer px
  • margin_right integer px

Plus alignment ("left" | "center" | "right") which maps to a flex utility class.

Summary

Functions

Map the alignment formatting key to a Tailwind flex class. Falls back to an empty string when unset or unknown.

Wrap rendered content with the formatting div.

Compute the inline style="..." value from a formatting map. Returns an empty string when no style fields are set.

Static list of supported style field keys.

Functions

alignment_class(_)

Map the alignment formatting key to a Tailwind flex class. Falls back to an empty string when unset or unknown.

apply(assigns)

Wrap rendered content with the formatting div.

Usage from a component's render(:live, ...):

def render(:live, node, _ctx) do
  formatting = node["props"]["formatting"] || %{}
  assigns = %{
    formatting: formatting,
    inner: ~H"<h2>{node["props"]["text"]}</h2>"
  }

  Athanor.Components.Formatting.apply(assigns)
end

Attributes

  • formatting (:map) - Defaults to %{}.
  • inner (:any) - Defaults to nil.

Slots

  • inner_block

build_style(formatting)

Compute the inline style="..." value from a formatting map. Returns an empty string when no style fields are set.

style_options()

Static list of supported style field keys.