LiveFilter.OptionHelpers (LiveFilter v0.1.8)

Copy Markdown View Source

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

opt_label(value)

@spec opt_label(term()) :: term()

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"

opt_label_display(value)

@spec opt_label_display(term()) :: String.t()

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"

opt_value(value)

@spec opt_value(term()) :: term()

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"

opt_value_string(value)

@spec opt_value_string(term()) :: String.t()

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"

resolve_options(arg1)

@spec resolve_options(map()) :: list()

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(%{})
[]