PaackEng/paack-ui/3.5.3

NOTE: the latest version is 7.23.0

UI.Paginator

UI.Paginator is a component for helping navigation in a large sample of elements. It provides navigation buttons and current location information.

A paginator does not include the logic required for taking/dropping the source of elements, and neither does the rendering of these elements. The following code applies the paginator to some simple list, and also applies paginating logic on it:

Element.column
    [ Element.width fill
    , Element.height (px 600)
    ]
    [ model.options
        |> List.drop model.pageOffset
        |> List.take 20
        |> List.map itemView
        |> Element.column
            [ Element.width fill
            , Element.height fill
            ]
    , Paginator.nonNumeric
        { onNextButtonClicked = Msg.NextPage
        , onPreviousButtonClicked = Msg.PreviousPage
        , totalCount = List.length model.options
        , offset = model.pageOffset
        , first = 0
        }
        renderConfig
    ]

Building

type alias PaginatorConfig msg =
{ onNextButtonClicked : msg
, onPreviousButtonClicked : msg
, totalCount : Int
, offset : Int
, first : Int
}

PaginatorConfig holds the configuration required to present a Paginator.

{ onNextButtonClicked = Msg.NextPage
, onPreviousButtonClicked = Msg.PreviousPage
, totalCount = List.length model.options
, offset = model.pageOffset
, first = 0
}

Rendering

nonNumeric : PaginatorConfig msg -> RenderConfig -> Element msg

Given a PaginatorConfig, renders paginator. This paginator style (non-numeric) has only the next and previous buttons. In between those, it presents the current offset.

Paginator.nonNumeric
    paginatorConfig
    renderConfig