Pagination
Navigate bounded result pages with current, previous, next, and compact range items.
Default
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let defaultPagination =
fvePagination {
_ariaLabel "Results pages"
fvePaginationContent {
fvePaginationItem {
_page 1
_ariaCurrent "page"
}
fvePaginationItem {
_page 2
_href "/components/pagination/page?page=2"
}
}
}On this page
Installation
Copy this component and its required dependencies into the consumer-owned Components project.
dotnet fve add pagination --config src/Acme.Components/fve.jsonNo additional JavaScript import is required.
The CLI resolves dependencies and preserves consumer-authored files. See Installation for project initialization, Tailwind, the shared runtime, and building/loading your app entry.
Usage
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
let defaultPagination =
fvePagination {
_ariaLabel "Results pages"
fvePaginationContent {
fvePaginationItem {
_page 1
_ariaCurrent "page"
}
fvePaginationItem {
_page 2
_href "/components/pagination/page?page=2"
}
}
}Page navigation
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
type PaginationDestination = PaginationPage of int
let paginationDestinationUrl (PaginationPage page) =
$"/components/pagination/page?page={page}"
let paginationConfig (variant: PaginationVariant) requestedPage =
let currentPage = Math.Clamp(requestedPage, 1, 8)
let pageItem page =
fvePaginationItem {
_page page
if page = currentPage then
_ariaCurrent "page"
else
_href (paginationDestinationUrl (PaginationPage page))
}
let middlePages = [ max 2 (currentPage - 1) .. min 7 (currentPage + 1) ]
let firstResult = (currentPage - 1) * 25 + 1
let lastResult = min 184 (currentPage * 25)
fvePagination {
_ariaLabel "Results pages"
_variant variant
fvePaginationPrevious {
if currentPage > 1 then
_href (paginationDestinationUrl (PaginationPage(currentPage - 1)))
}
fvePaginationContent {
pageItem 1
if List.head middlePages > 2 then
fvePaginationEllipsis { () }
for page in middlePages do
pageItem page
if List.last middlePages < 7 then
fvePaginationEllipsis { () }
pageItem 8
}
fvePaginationNext {
if currentPage < 8 then
_href (paginationDestinationUrl (PaginationPage(currentPage + 1)))
}
fvePaginationSummary { $"Showing {firstResult}–{lastResult} of 184 items" }
}
let paginationPreview requestedPage =
paginationConfig PaginationVariant.Full requestedPageNumbers only
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
type PaginationDestination = PaginationPage of int
let paginationDestinationUrl (PaginationPage page) =
$"/components/pagination/page?page={page}"
let paginationConfig (variant: PaginationVariant) requestedPage =
let currentPage = Math.Clamp(requestedPage, 1, 8)
let pageItem page =
fvePaginationItem {
_page page
if page = currentPage then
_ariaCurrent "page"
else
_href (paginationDestinationUrl (PaginationPage page))
}
let middlePages = [ max 2 (currentPage - 1) .. min 7 (currentPage + 1) ]
let firstResult = (currentPage - 1) * 25 + 1
let lastResult = min 184 (currentPage * 25)
fvePagination {
_ariaLabel "Results pages"
_variant variant
fvePaginationPrevious {
if currentPage > 1 then
_href (paginationDestinationUrl (PaginationPage(currentPage - 1)))
}
fvePaginationContent {
pageItem 1
if List.head middlePages > 2 then
fvePaginationEllipsis { () }
for page in middlePages do
pageItem page
if List.last middlePages < 7 then
fvePaginationEllipsis { () }
pageItem 8
}
fvePaginationNext {
if currentPage < 8 then
_href (paginationDestinationUrl (PaginationPage(currentPage + 1)))
}
fvePaginationSummary { $"Showing {firstResult}–{lastResult} of 184 items" }
}
let paginationVariantPreview variant requestedPage = paginationConfig variant requestedPagePrevious and next only
open System
open FSharp.ViewEngine
open Acme.Components
open type Html
open type Svg
open type Datastar
type PaginationDestination = PaginationPage of int
let paginationDestinationUrl (PaginationPage page) =
$"/components/pagination/page?page={page}"
let paginationConfig (variant: PaginationVariant) requestedPage =
let currentPage = Math.Clamp(requestedPage, 1, 8)
let pageItem page =
fvePaginationItem {
_page page
if page = currentPage then
_ariaCurrent "page"
else
_href (paginationDestinationUrl (PaginationPage page))
}
let middlePages = [ max 2 (currentPage - 1) .. min 7 (currentPage + 1) ]
let firstResult = (currentPage - 1) * 25 + 1
let lastResult = min 184 (currentPage * 25)
fvePagination {
_ariaLabel "Results pages"
_variant variant
fvePaginationPrevious {
if currentPage > 1 then
_href (paginationDestinationUrl (PaginationPage(currentPage - 1)))
}
fvePaginationContent {
pageItem 1
if List.head middlePages > 2 then
fvePaginationEllipsis { () }
for page in middlePages do
pageItem page
if List.last middlePages < 7 then
fvePaginationEllipsis { () }
pageItem 8
}
fvePaginationNext {
if currentPage < 8 then
_href (paginationDestinationUrl (PaginationPage(currentPage + 1)))
}
fvePaginationSummary { $"Showing {firstResult}–{lastResult} of 184 items" }
}
let paginationVariantPreview variant requestedPage = paginationConfig variant requestedPageAPI reference
type PaginationVariant =
| Full
| NumbersOnly
| PreviousNextOnly
module PaginationDsl =
val fvePagination : ComponentElementBuilder
val fvePaginationContent : ComponentElementBuilder
val fvePaginationItem : ComponentElementBuilder
val fvePaginationEllipsis : ComponentElementBuilder
val fvePaginationPrevious : ComponentElementBuilder
val fvePaginationNext : ComponentElementBuilder
val fvePaginationSummary : ComponentElementBuilder
module PaginationAttributes =
val Html._variant.Static : value:PaginationVariant -> HtmlAttribute
val Html._page.Static : value:int -> HtmlAttribute