LedgerUI.Components.Select.Options (LedgerUI v0.2.0)

Copy Markdown View Source

Option shapes and form plumbing shared by select, autocomplete, pillbox, tags_input, pill_select, segmented, checkbox_group and radio_group.

An option is one of

  • a string / number / atom: label and value are the same;
  • {label, value} (a keyword entry [Alabama: "AL"] is the same);
  • {label, value, count};
  • a map with :label and :value (:count, :hint, :disabled, :icon, :description, :color, :initials, :tone; every other key goes to data);
  • {group_label, [option]}, a group.

normalize/1 returns a list of option maps (%{label, value, disabled, hint, count, icon, description, color, initials, tone, data}; value is always a string) and %{group: label, options: [option]} entries.

Summary

Functions

Avatar tone class (t1..t5) taken from a name.

Like values/1 but a binary is split on commas.

Options without the group wrappers.

Initials of a label: first letters of the first and last word.

Replaces %{query} (or any %{key}) in a text.

Normalizes options and groups (see the module doc).

Fills id, name, value and errors from field and derives a stable id when none is given (never random: a hash of seed).

Form field for checkbox-like controls: returns {assigns, id}; checked?/1 tells if it is on.

To string, for option values (nil is the empty string).

%{style: s} for a style or %{}: an empty style={nil} would render style="".

Translates a changeset error ({msg, opts}) or passes a binary through.

A list of chosen values as strings: nil, a scalar, a list or a comma separated string.

Functions

avatar_tone(name)

Avatar tone class (t1..t5) taken from a name.

csv_values(value)

Like values/1 but a binary is split on commas.

flatten(options)

Options without the group wrappers.

initials(label)

Initials of a label: first letters of the first and last word.

interpolate(text, bindings)

Replaces %{query} (or any %{key}) in a text.

normalize(options)

Normalizes options and groups (see the module doc).

resolve(assigns, prefix, seed \\ nil)

Fills id, name, value and errors from field and derives a stable id when none is given (never random: a hash of seed).

resolve_field(assigns)

Form field for checkbox-like controls: returns {assigns, id}; checked?/1 tells if it is on.

str(value)

To string, for option values (nil is the empty string).

style_attrs(style)

%{style: s} for a style or %{}: an empty style={nil} would render style="".

translate_error(msg)

Translates a changeset error ({msg, opts}) or passes a binary through.

values(list)

A list of chosen values as strings: nil, a scalar, a list or a comma separated string.