LedgerUI.Components.Pagination (LedgerUI v0.2.0)

Copy Markdown View Source

Pagination: the canvas pager (lu-pg2, shape canvas, rounded or pill) or the classic bar of buttons (lu-pages, shape="classic"), in three sizes.

<.pagination page={@page} total_pages={10} patch={&"/orders?page=#{&1}"} />
<.pagination page={@page} total_pages={10} on_change="paginate" shape="pill" />

Each page is a link when patch, navigate or href is given (a function from the page number to a path); otherwise a button pushing on_change with %{"page" => "3"} (to target). With neither, the pager is display-only (plain spans). Pages far from the current one collapse into …: siblings pages on each side of the current one and boundaries at each end.

A list footer: total_entries and page_size add the "Showing 1–15 of 128" summary (and work out total_pages), page_sizes a rows-per-page select in its own <form> pushing on_page_size with %{"page_size" => "30"}. With a summary, a select or an :aside the root is a lu-row around the pages.

The canvas shapes style > span, so interactive pages are spans holding the button or link. summary defaults to "Showing %{first}–%{last} of %{total}" when total_entries is given; an explicit summary is shown as-is without it. Accessibility, rendered server-side: the current page carries aria-current="page" (on the link/button, or on the span when the pager is display-only), every page and arrow has an aria-label (page_label, prev_label, next_label), the summary is role="status". shape="classic" is an addition to the README.

Summary

Functions

pagination(assigns)

Attributes

  • page (:integer) (required)
  • total_pages (:integer) - Defaults to nil.
  • total_entries (:integer) - Defaults to nil.
  • page_size (:integer) - Defaults to nil.
  • page_sizes (:list) - Defaults to [].
  • on_page_size (:any) - Defaults to nil.
  • summary (:string) - Defaults to nil.
  • page_size_label (:string) - Defaults to "%{size} / page".
  • page_size_aria (:string) - Defaults to "Rows per page".
  • siblings (:integer) - Defaults to 1.
  • boundaries (:integer) - Defaults to 1.
  • patch (:any) - Defaults to nil.
  • navigate (:any) - Defaults to nil.
  • href (:any) - Defaults to nil.
  • on_change (:any) - Defaults to nil.
  • target (:any) - Defaults to nil.
  • divided (:boolean) - Defaults to false.
  • shape (:string) - Defaults to "canvas". Must be one of "canvas", "rounded", "pill", or "classic".
  • variant (:string) - The same as shape; it wins when given. Defaults to nil. Must be one of nil, "canvas", "rounded", "pill", or "classic".
  • size (:string) - Defaults to "md". Must be one of "sm", "md", or "lg".
  • arrows (:boolean) - Defaults to true.
  • prev_label (:string) - Defaults to "Previous page".
  • next_label (:string) - Defaults to "Next page".
  • page_label (:string) - Defaults to "Page %{page}".
  • page_attrs (:any) - Function from a page number (or :ellipsis) to extra attrs (%{style: ..., class: ...}) of its item, e.g. for staggered animations. Defaults to nil.
  • class (:any) - Defaults to nil.
  • Global attributes are accepted.

Slots

  • aside