Skip to main content

pagination

Function pagination 

Source
pub fn pagination<S>(
    current: u32,
    count: u32,
    link: impl Fn(u32) -> Link<S>,
    text: &PaginationText,
) -> El<S>
Expand description

Links to the pages of a list of count pages, on page current.

Pages are counted from 1, and link gives the link to a page. The links are the page before and the page after, the first and the last page, and the pages next to the current one, with … for the pages left out. The current page’s link has aria-current="page". On the first page the link to the page before is text marked aria-disabled="true", as is the link to the page after on the last.

use hypersig::{Page, Route, Signals};
use hypersig_ui::{PaginationText, pagination};
use serde::{Deserialize, Serialize};

#[derive(Signals, Serialize, Deserialize)]
struct Catalog {}

hypersig::routes! {
    fn pages(Router<()>);
    const PRODUCTS: Route<u32> = "/products/{page}" => page;
}

let pager = pagination::<Catalog>(5, 10, |page| PRODUCTS.link_with(&page), &PaginationText::default());
let html = pager.render();
assert!(html.contains(r#"href="/products/5" aria-current="page""#));
assert!(html.contains(r#"href="/products/4""#) && !html.contains(r#"href="/products/3""#));

§Panics

Panics if current is 0 or above count.