LineaUI.Components.Select.Options (linea_ui v0.1.1)

Copy Markdown View Source

The options of a select, in every shape the components accept, read into one shape.

An option is a string or number (label and value alike), a {label, value} tuple, a keyword entry label: value, or a map with :label and :value (and optionally :disabled; any other keys are kept for the :option and :item slots). A group is {group_label, [options]}.

iex> LineaUI.Components.Select.Options.normalize(["Wedding", {"Other", "other"}])
[
  %{type: :option, label: "Wedding", value: "Wedding", disabled: false, data: "Wedding"},
  %{type: :option, label: "Other", value: "other", disabled: false, data: {"Other", "other"}}
]

Summary

Functions

The option whose value is value, among options; a value that is not one of them becomes its own option.

The options alone, with the groups flattened.

Reads a list of options and groups.

The values of a select's value as a list of strings.

Types

group()

@type group() :: %{type: :group, label: String.t(), options: [option()]}

option()

@type option() :: %{
  type: :option,
  label: String.t(),
  value: String.t(),
  disabled: boolean(),
  data: term()
}

Functions

find(options, value)

@spec find([option()], String.t()) :: option()

The option whose value is value, among options; a value that is not one of them becomes its own option.

flat(entries)

@spec flat([option() | group()]) :: [option()]

The options alone, with the groups flattened.

normalize(options)

@spec normalize(list()) :: [option() | group()]

Reads a list of options and groups.

values(list)

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

The values of a select's value as a list of strings.