Shared helpers for resolving and formatting filter options.
Used by Bar component and individual input components to handle
options in consistent formats: ["value1", "value2"] or [{"Label", "value"}].
Summary
Functions
Extracts the label from an option.
Extracts the label from an option with display formatting.
Extracts the value from an option.
Extracts the value from an option as a string.
Resolves options from a config struct.
Functions
Extracts the label from an option.
For tuples, returns the first element. For simple values, returns the value as-is.
Examples
iex> opt_label({"Active", "active"})
"Active"
iex> opt_label("active")
"active"
Extracts the label from an option with display formatting.
Capitalizes string values that aren't already in tuple format.
Examples
iex> opt_label_display({"Active", "active"})
"Active"
iex> opt_label_display("active")
"Active"
iex> opt_label_display(:pending)
"Pending"
Extracts the value from an option.
Options can be simple values or {label, value} tuples.
Examples
iex> opt_value({"Active", "active"})
"active"
iex> opt_value("active")
"active"
Extracts the value from an option as a string.
Used for comparisons in UI where values need to be strings.
Examples
iex> opt_value_string({"Active", :active})
"active"
iex> opt_value_string(123)
"123"
Resolves options from a config struct.
Supports both static options lists and dynamic options functions.
Examples
iex> resolve_options(%{options: ["a", "b"]})
["a", "b"]
iex> resolve_options(%{options_fn: fn -> ["x", "y"] end})
["x", "y"]
iex> resolve_options(%{})
[]