defmodule Scrivener.Components.BootstrapV5 do @moduledoc """ Bootstrap 5 pagination component for the Scrivener library Based on https://getbootstrap.com/docs/5.3/components/pagination/#overview Renders the following structure: """ use Phoenix.Component alias Scrivener.Components.PaginationLinks @doc ~S""" Renders a pagination component ## Examples <.pagination page={@page} url_params={["q", "term"]} path={&~p"/index?#{&1}"} /> """ attr(:page, Scrivener.Page, required: true, doc: "a `%Scrivener.Page{}` struct returned from `Repo.paginate/2`" ) attr(:url_params, :list, default: [], doc: "a list of tuples for the query parameters that will persist accross pagination (typically the current search, filter and/or sort parameters)" ) attr(:page_param, :string, default: "page") attr(:path, :any, required: true, doc: "a 1-arity function that receives the `url_params` merged with the current page number (`page`) and return the path. Typically a verified route sigil" ) attr(:navigation_mode, :atom, default: :navigate, values: [:navigate, :patch, :href], doc: "the link component navigation mode" ) attr(:options, :any, default: [], doc: "a `Keyword` list that can be used to customize the behaviour of the pagination. See `Scrivener.Components.PaginationLinks` defaults" ) attr(:rest, :global) def pagination(assigns) do assigns = assigns |> assign_new(:entries, fn %{page: page} -> page.entries end) |> assign_new(:page_number, fn %{page: page} -> page.page_number end) |> assign_new(:page_size, fn %{page: page} -> page.page_size end) |> assign_new(:total_entries, fn %{page: page} -> page.total_entries end) |> assign_new(:total_pages, fn %{page: page} -> page.total_pages end) ~H""" """ end attr(:text, :string) attr(:page_number, :integer, required: true) attr(:url_params, :map, default: []) attr(:page_param, :string, default: "page") attr(:page, Scrivener.Page, required: true) attr(:path, :any) attr(:navigation_mode, :atom, required: true, values: [:navigate, :patch, :href] ) defp page(%{text: :ellipsis} = assigns) do ~H"""