ElementorexCms.Block.Prop (ElementorexCms v0.1.0)

Copy Markdown View Source

A property of a block: its type, default, label and editor control.

Props are declared with ElementorexCms.Block.prop/3. The type decides how a value is cast and sanitized when it reaches the document (from the editor or from stored JSON) and which control the inspector shows:

TypeValueControl
:stringone line of texttext input
:textmulti-line plain texttextarea
:richtextsanitized HTML (:rich policy)inline editing + textarea
:htmlsanitized HTML (:html policy)code editor
:selectone of :optionsselect, segmented, swatches
:booleantrue / falsetoggle
:integerinteger within :min..:maxnumber or range
:numbernumber within :min..:maxnumber or range
:urlsanitized link URLURL input
:imagesanitized image URLimage picker / upload
:iconHeroicons nameicon picker
:colorCSS color or theme variableswatches + color input
:datetime"2026-12-31T23:59"date and time input
:listlist of items, each with its :fieldsrepeater

Options

  • :default - value for new blocks and for missing or invalid values
  • :label, :help, :placeholder - texts of the control (translated with ElementorexCms.I18n)
  • :group - heading of the inspector section the control goes in
  • :control - overrides the default control (:textarea, :segmented, :swatches, :range, :code...)
  • :options - for :select: [{"Label", "value"}] or a list of values
  • :min, :max, :step, :unit - for numbers
  • :max_length - for text types
  • :policy - for :richtext: :rich (default) or :inline (only formatting inside a line, see ElementorexCms.HTML.Sanitizer)
  • :inline - the prop can be edited by typing on the canvas
  • :show_if - only show the control when another prop matches: {:icon, :present}, {:variant, "outline"} or {:size, ["lg", "xl"]}
  • :fields, :item_label, :max_items - for :list (fields takes {name, type, opts} tuples)

Summary

Functions

Casts and sanitizes a value. Invalid values fall back to the default (or to an empty value when the default would be misleading, like an unsafe URL).

The default value, with fresh ids for the items of a :list (every item carries an "id" so the editor can reorder it).

The default value with its texts translated to the current locale (see ElementorexCms.I18n): plain and rich text props, and the text fields of list items. Other values are returned as they are.

Builds a prop. Raises ArgumentError on an unknown type.

A blank item for a :list prop, with the defaults of its fields (translated).

Types a prop can have.

Values allowed by a :select prop.

Whether the control of prop should be shown given the other values, per its :show_if option.

Types

t()

@type t() :: %ElementorexCms.Block.Prop{
  control: term(),
  default: term(),
  fields: term(),
  group: term(),
  help: term(),
  inline: term(),
  item_label: term(),
  key: term(),
  label: term(),
  max: term(),
  max_items: term(),
  max_length: term(),
  min: term(),
  name: term(),
  options: term(),
  placeholder: term(),
  policy: term(),
  show_if: term(),
  step: term(),
  type: term(),
  unit: term()
}

Functions

cast(prop, value)

@spec cast(t(), term()) :: term()

Casts and sanitizes a value. Invalid values fall back to the default (or to an empty value when the default would be misleading, like an unsafe URL).

default(prop)

@spec default(t()) :: term()

The default value, with fresh ids for the items of a :list (every item carries an "id" so the editor can reorder it).

localized_default(prop)

@spec localized_default(t()) :: term()

The default value with its texts translated to the current locale (see ElementorexCms.I18n): plain and rich text props, and the text fields of list items. Other values are returned as they are.

new(name, type, opts \\ [])

@spec new(atom(), atom(), keyword()) :: t()

Builds a prop. Raises ArgumentError on an unknown type.

new_item(prop)

@spec new_item(t()) :: map()

A blank item for a :list prop, with the defaults of its fields (translated).

types()

@spec types() :: [atom()]

Types a prop can have.

values(prop)

@spec values(t()) :: [String.t()]

Values allowed by a :select prop.

visible?(prop, values)

@spec visible?(t(), map()) :: boolean()

Whether the control of prop should be shown given the other values, per its :show_if option.