Aurora. Uix. Selection
(Aurora UIX v0.1.4-rc.8)
Copy Markdown
Manages selection state for paginated data structures with per-page tracking.
This module provides a data structure and functions to handle item selections across multiple pages, maintaining both global selection state and per-page selection tracking for UI components.
Key Features
- Global selection tracking across all pages.
- Per-page selection state for efficient UI updates
- Automatic state derivation for selection counts and page indicators
Summary
Functions
Creates a new empty selection struct.
Adds selection state to an item map for UI rendering.
Sets the selection state for a specific item on a given page.
Updates derived state fields based on current selections.
Types
Functions
@spec new() :: t()
Creates a new empty selection struct.
Returns
t() - A new selection struct with empty selection state.
Adds selection state to an item map for UI rendering.
Takes an item map and adds a :selected_check__ field indicating whether
the item is currently selected based on the global selection state.
Parameters
item(map()) - The item map to enhance with selection stateitem_id(term()) - The unique identifier to check for selectionselection(t()) - The selection struct containing current selections
Returns
map() - The item map with added :selected_check__ boolean field.
Examples
iex> selection = %Aurora.Uix.Selection{selected: MapSet.new([1, 2])}
iex> item = %{id: 1, name: "Item 1"}
iex> Aurora.Uix.Selection.set_item_select_state(item, 1, selection)
%{id: 1, name: "Item 1", selected_check__: true}
Sets the selection state for a specific item on a given page.
Adds or removes an item from both global and per-page selection tracking.
When state is true, the item is added to selections; otherwise it's removed.
Parameters
item_id(term()) - The unique identifier for the item to select/deselectselection(t()) - The current selection structstate(boolean()) -trueto select the item,falseto deselectpage(integer()) - The page number where this selection occurs (page is1when rendering infinite scroll)
Returns
t() - Updated selection struct with the new selection state.
Updates derived state fields based on current selections.
Recalculates selected_count and selected_any_in_page? based on the current
selection state.
Parameters
selection(t()) - The selection struct to updatepage(integer()) - The page number to check for any selections (defaults to 1 - infinite scroll case)
Returns
t() - Updated selection struct with recalculated state fields.