KantaWeb.Components.Shared.Pagination (kanta v0.5.1)

A component for rendering pagination controls with support for page navigation.

This component displays a pagination interface with previous/next buttons and page numbers. It handles edge cases like ellipses for many pages and proper accessibility attributes.

Summary

Functions

Calculates the sequence of page numbers and ellipses to display in the pagination component.

Types

ellipsis_entry()

@type ellipsis_entry() :: :ellipsis

page_entry()

@type page_entry() :: {:page, integer()}

Functions

calculate_pages(current_page, total_pages, surrounding)

@spec calculate_pages(integer(), integer(), integer()) :: [
  page_entry() | ellipsis_entry()
]

Calculates the sequence of page numbers and ellipses to display in the pagination component.

Returns a list of entries, where each entry is either:

  • - A page number to display
  • :ellipsis - An ellipsis indicating skipped pages

render(assigns)

Attributes

  • metadata (:map) (required) - Pagination metadata with :page_number and :total_pages keys.
  • on_page_change (:any) (required) - Event to trigger when changing pages.
  • surrounding_pages_number (:integer) - Number of page links to show around current page. Defaults to 4.