MishkaGervaz.Form.Entities.Notice (MishkaGervaz v0.0.1-alpha.2)

Copy Markdown View Source

Static form notice — alerts and banners with a known position, validation binding, dismiss tracking, and master-only restriction.

A notice is declared statically and rendered dynamically: the position, type, and binding are pinned at compile time, while visible / show_when / bind_to decide whether to actually render on each frame. Five visual types (:info, :warning, :error, :success, :neutral) and a custom HEEx render escape hatch cover the common cases.

Positions

Atoms:

  • :form_top - above the <.form> element.
  • :before_header / :after_header - around the form header.
  • :before_groups / :before_fields - before grouped/ungrouped field rows.
  • :before_submit - above the submit/cancel row.
  • :form_bottom - below the submit row but inside <.form>.
  • :form_footer - below the form footer (last possible slot).

Tuples:

  • {:before_group, :group_name} / {:after_group, :group_name}

Bind to (dynamic activation)

  • :validation - shown when state.form_errors != [].
  • :uploads - shown when any registered upload has errors.
  • :dirty - shown when state.dirty? == true.
  • nil - no auto-binding; controlled solely by visible/show_when.

Example

layout do
  notice :read_only_banner do
    position :before_fields
    type :warning
    title "Read-Only Access"
    content "Your role can view but not modify these settings."
    icon "hero-lock-closed"
    visible fn state -> state.current_user.role == :viewer end
    restricted false
    dismissible false
  end

  notice :validation_summary do
    position :form_top
    type :error
    bind_to :validation
    title fn _state -> "Please fix the errors below" end
  end
end

See MishkaGervaz.Form.Dsl.Layout for the surrounding section and MishkaGervaz.Form.Entities.Notice.Ui for the ui sub-entity.

Summary

Functions

Validate a position value. Returns :ok or {:error, reason}.

Types

position()

@type position() ::
  :form_top
  | :before_header
  | :after_header
  | :before_groups
  | :before_fields
  | :before_submit
  | :form_bottom
  | :form_footer
  | {:before_group, atom()}
  | {:after_group, atom()}

t()

@type t() :: %MishkaGervaz.Form.Entities.Notice{
  __identifier__: atom() | nil,
  __spark_metadata__: map() | nil,
  bind_to: :validation | :uploads | :dirty | nil,
  content: String.t() | (-> String.t()) | (map() -> String.t()) | nil,
  dismissible: boolean(),
  icon: String.t() | nil,
  name: atom(),
  only_steps: [atom()] | nil,
  position: position(),
  render:
    (map() -> Phoenix.LiveView.Rendered.t())
    | (map(), map() -> Phoenix.LiveView.Rendered.t())
    | nil,
  restricted: boolean() | (map() -> boolean()),
  show_when: (map() -> boolean()) | nil,
  title: String.t() | (-> String.t()) | (map() -> String.t()) | nil,
  type: :info | :warning | :error | :success | :neutral,
  ui: MishkaGervaz.Form.Entities.Notice.Ui.t() | nil,
  visible: boolean() | (map() -> boolean())
}

Functions

transform(notice)

validate_position(pos)

Validate a position value. Returns :ok or {:error, reason}.