@molecule/app-pagination-bar-svelte

Feature · pagination-bar · App (browser) · v1.1.1 · Apache-2.0

Svelte PaginationBar with page-window, size-select, and "Showing X of Y" text

npm install @molecule/app-pagination-bar-svelte

npm · Source on GitHub

How it works

@molecule/app-pagination-bar-svelte is a ready-made pagination-bar feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

<script lang="ts">
  import { PaginationBar } from '@molecule/app-pagination-bar-svelte'

  let { total }: { total: number } = $props()
  let page = $state(1)
  let pageSize = $state(10)
</script>

<PaginationBar
  {page}
  totalPages={Math.max(1, Math.ceil(total / pageSize))}
  {pageSize}
  {total}
  onPageChange={(next) => (page = next)}
  pageSizeOptions={[10, 25, 50]}
  onPageSizeChange={(size) => {
    pageSize = size
    page = 1
  }}
/>

Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte

Reference

Svelte PaginationBar — page-window + "Showing X of Y" text + optional page-size selector.

Built on Button and Select from @molecule/app-ui-svelte so it inherits the wired ClassMap styling. Apps drive the i18n noun via the showingKey prop ("Showing 1 to 10 of 123 tags" vs. "…orders") — the key takes start, end, and total interpolation values. It is the Svelte counterpart of @molecule/app-pagination-bar-react: the same props (React names) and the same DOM for the same input.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

<script lang="ts">
  import { PaginationBar } from '@molecule/app-pagination-bar-svelte'

  let { total }: { total: number } = $props()
  let page = $state(1)
  let pageSize = $state(10)
</script>

<PaginationBar
  {page}
  totalPages={Math.max(1, Math.ceil(total / pageSize))}
  {pageSize}
  {total}
  onPageChange={(next) => (page = next)}
  pageSizeOptions={[10, 25, 50]}
  onPageSizeChange={(size) => {
    pageSize = size
    page = 1
  }}
/>

Type

feature

Installation

npm install @molecule/app-pagination-bar-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte

API

Interfaces

PaginationBarProps

Props accepted by the PaginationBar component.

interface PaginationBarProps {
  /** Current page (1-indexed). */
  page: number
  /** Total page count (>= 1). */
  totalPages: number
  /** Items per page. */
  pageSize: number
  /** Total item count across all pages. */
  total: number
  /** Called when the user changes page. */
  onPageChange: (page: number) => void
  /** Called when the user changes page-size (when allowed via `pageSizeOptions`). */
  onPageSizeChange?: (size: number) => void
  /** Available page-size options. When omitted, the size selector is hidden. */
  pageSizeOptions?: number[]
  /** i18n key for the "Showing X to Y of Z items" text — takes interpolation vars `start`, `end`, `total`. */
  showingKey?: string
  /** Default English fallback for the showing text. */
  showingDefault?: string
  /** Extra classes on the outer wrapper. */
  className?: string
}

Constants

PaginationBar

const PaginationBar: LegacyComponentType

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-svelte ^3.5.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-svelte ^1.1.0
  • svelte ^5.0.0

Runtime Dependencies

  • @molecule/app-svelte
  • @molecule/app-ui
  • @molecule/app-ui-svelte
  • svelte

Companion locale bond: @molecule/app-locales-pagination-bar (keys pagination.previous, pagination.next, pagination.pageSize, plus your showingKey). The page-size Select is hidden unless BOTH pageSizeOptions and onPageSizeChange are supplied; when shown it wires the Select's typed onValueChange and parses the selected value to a number, so onPageSizeChange always receives a real page size (e.g. 25), never NaN. Requires the Svelte binding's i18n context and a wired ClassMap bond. Distinct from @molecule/app-ui-svelte's lower-level Pagination (page window only — no showing-text or size selector).

Translations

Translation strings are provided by @molecule/app-locales-pagination-bar.