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

Copy Markdown View Source

Shared formatting tab UI fragment. Stateless function component.

Each component's editor form LC embeds this via Athanor.Components.EditorForm.Shell. On change, the formatting form fires phx-change="update_props" scoped to the parent LC — the LC's handle_event("update_props", %{"formatting" => fmt} = _params, ...) pattern-matches the formatting-only shape and writes it wholesale into props["formatting"].

Saved JSON shape (matches legacy):

props["formatting"] = %{
  "text_color" => "#RRGGBB" | "",
  "background_color" => "#RRGGBB" | "",
  "border_color" => "#RRGGBB" | "",
  "padding_top" => integer,
  "padding_bottom" => integer,
  "padding_left" => integer,
  "padding_right" => integer,
  "margin_top" => integer,
  "margin_bottom" => integer,
  "margin_left" => integer,
  "margin_right" => integer,
  "border_radius" => integer,
  "border_width" => integer,
  "alignment" => "left" | "center" | "right"
}

Summary

Functions

Build a Phoenix.HTML.Form for the formatting fields, defaulted from the existing formatting map (or an empty map). Use as: :formatting so all fields submit under the formatting[...] namespace.

Coerce the params map from a formatting-form phx-change into a clean prop-ready map (integer fields converted from strings). Matches the JSON shape on disk.

Initial set of expanded sections. Mirrors the legacy default of "colors" being open by default.

Toggle a section's expanded/collapsed state in the MapSet.

Functions

build_form(formatting)

Build a Phoenix.HTML.Form for the formatting fields, defaulted from the existing formatting map (or an empty map). Use as: :formatting so all fields submit under the formatting[...] namespace.

Returns a tracked form ready to pass to editor_form/1.

coerce_params(params)

Coerce the params map from a formatting-form phx-change into a clean prop-ready map (integer fields converted from strings). Matches the JSON shape on disk.

default_open_sections()

Initial set of expanded sections. Mirrors the legacy default of "colors" being open by default.

editor_form(assigns)

Attributes

  • form (:any) (required) - A Phoenix.HTML.Form built with as: :formatting.
  • myself (:any) (required) - phx-target — the parent LC's myself.
  • open_sections (:any) (required) - MapSet of section keys currently expanded.

toggle_section(open_sections, section)

Toggle a section's expanded/collapsed state in the MapSet.