Mixins / foldkit-mixins-ui

Pagination

namespace · packages/mixins-ui/src/pagination.ts:1

export * as Pagination from './pagination.js'

In the guides

Members

Pagination.configure

function · packages/mixins-ui/src/pagination.ts:281

function configure<const Names extends string = never>(
  config: Presets<PaginationPreset, Names>,
): {
  readonly view: <Outer>(
    options: PaginationView<Outer> & PresetOption<Names>,
    h: HtmlBuilder<Outer>,
  ) => Html
}

The application's own Pagination: base for every use, presets chosen at a use with preset, and the call over both.

Pagination.itemsOf

function · packages/mixins-ui/src/pagination.ts:55

function itemsOf(
  page: number,
  pageCount: number,
  window?: PaginationWindow,
): ReadonlyArray<PaginationItem>

The stops to draw: every page while they fit, otherwise the first and last boundaries, the current with siblings either side, and an ellipsis for each run between. A run of one page draws that page, since an ellipsis would take its room and hide it. Pure, so the window is testable without drawing.

Pagination.PaginationIcons

interface · packages/mixins-ui/src/pagination.ts:120

interface PaginationIcons {
  readonly first?: Html | undefined
  readonly previous?: Html | undefined
  readonly next?: Html | undefined
  readonly last?: Html | undefined
}

Drawings for the four stops, shown in place of their words, which stay each button's accessible name.

Pagination.PaginationItem

type · packages/mixins-ui/src/pagination.ts:38

type PaginationItem = number | 'ellipsis'

One numbered stop, or a collapsed run of them.

Pagination.PaginationPerPage

interface · packages/mixins-ui/src/pagination.ts:128

interface PaginationPerPage<Message> {
  readonly sizes: ReadonlyArray<number>
  readonly onPerPage: (perPage: number) => Message
}

The rows a page may show, for a select of them; its value is the range's perPage.

Pagination.PaginationPreset

type · packages/mixins-ui/src/pagination.ts:272

type PaginationPreset = Pick<
  PaginationView<never>,
  'style' | 'words' | 'numbered' | 'ends' | 'icons' | 'siblings' | 'boundaries'
> & {
  readonly mixins?: MixinList<never>
}

What a Pagination is given once: its look, words, windows and stops. The page and its Messages are each use's.

Pagination.PaginationRange

interface · packages/mixins-ui/src/pagination.ts:136

interface PaginationRange<Message = never> {
  readonly total: number
  readonly perPage: number
  readonly choose?: PaginationPerPage<Message> | undefined
}

The rows a page shows, from 1, and how many there are in all: what summary says.

Pagination.PaginationSlots

const · packages/mixins-ui/src/pagination.ts:14

const PaginationSlots: Slots.Contract<{ readonly root: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly [Attr.AttrToken<"role">, Attr.AttrToken<"aria-label">], readonly Slot.RequirementName[], boolean>; readonly summary: Slot.UnnamedSlot<Capability.Capability<"Container", readonly [Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>]>, readonly Slot.EventName[], readonly Slot.AttributeName[], readonly Slot.RequirementName[], boolean>; readonly first: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly Slot.EventName[], readonly [Attr.AttrToken<"aria-label">], readonly Slot.RequirementName[], boolean>; readonly prev: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly Slot.EventName[], readonly [Attr.AttrToken<"aria-label">], readonly Slot.RequirementName[], boolean>; readonly next: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly Slot.EventName[], readonly [Attr.AttrToken<"aria-label">], readonly Slot.RequirementName[], boolean>; readonly last: Slot.UnnamedSlot<Capability.Capability<"Interactive", readonly [Capability.Capability<"Base", readonly []>]>, readonly Slot.EventName[], readonly [Attr.AttrToken<"aria-label">] …;

Page navigation publishes its regions as slots; it owns no state, only the controlled page it is given. The application moves the page in onPage; this draws where it is. A single page — or none — has nowhere to go, so it draws no stops; with a range it still draws the summary and the page-size choice, since choosing a size above the row count must leave a way back.

Pagination.PaginationView

interface · packages/mixins-ui/src/pagination.ts:150

interface PaginationView<Message> extends PaginationWindow {
  readonly page: number
  readonly pageCount: number
  readonly onPage: (page: number) => Message
  readonly words?: Partial<PaginationWords> | undefined
  readonly numbered?: boolean | undefined
  readonly icons?: PaginationIcons | undefined
  readonly ends?: boolean | undefined
  readonly range?: PaginationRange<Message> | undefined
  readonly style?: NamedStyle<typeof PaginationSlots> | undefined
  readonly mixins?: MixinList<Message> | undefined
}

Page navigation in one call: the controlled page, how many there are, what choosing one causes, a style for its slots, and mixins beside the style. No upstream component stands behind it.

Pagination.PaginationWindow

interface · packages/mixins-ui/src/pagination.ts:41

interface PaginationWindow {
  readonly siblings?: number | undefined
  readonly boundaries?: number | undefined
}

How many stops stand around the current page and at each end.

Pagination.PaginationWords

interface · packages/mixins-ui/src/pagination.ts:83

interface PaginationWords {
  readonly label: string
  readonly first: string
  readonly previous: string
  readonly next: string
  readonly last: string
  readonly stop: string
  readonly ellipsis: string
  readonly ofCount: string
  readonly perPage: string
  readonly summary: string
}

Everything a pagination says, as text with {blanks}.

Pagination.summaryOf

function · packages/mixins-ui/src/pagination.ts:171

function summaryOf<Message>(
  page: number,
  range: PaginationRange<Message>,
  text?: string,
): string

The first and last row page page shows, and the total: "11–20 of 97".

Pagination.view

function · packages/mixins-ui/src/pagination.ts:183

function view<Message>(
  options: PaginationView<Message>,
  h: HtmlBuilder<Message>,
): Html

Pagination.words

const · packages/mixins-ui/src/pagination.ts:103

const words = {
  label,
  first,
  previous,
  next,
  last,
  stop,
  ellipsis,
  ofCount,
  perPage,
  summary,
}

The defaults, in English.