@molecule/app-pagination-bar-angular
Feature · pagination-bar · App (browser) · v1.1.1 · Apache-2.0
Angular PaginationBar with page-window, size-select, and "Showing X of Y" text
npm install @molecule/app-pagination-bar-angularHow it works
@molecule/app-pagination-bar-angular 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.
import { Component, signal } from '@angular/core'
import { PaginationBar } from '@molecule/app-pagination-bar-angular'
@Component({
selector: 'app-order-list',
standalone: true,
imports: [PaginationBar],
template: `
<div
mol-pagination-bar
[page]="page()"
[totalPages]="totalPages()"
[pageSize]="pageSize()"
[total]="total()"
[onPageChange]="setPage"
[pageSizeOptions]="[10, 25, 50]"
[onPageSizeChange]="changePageSize"
></div>
`,
})
export class OrderList {
readonly total = signal(123)
readonly page = signal(1)
readonly pageSize = signal(10)
readonly totalPages = () => Math.max(1, Math.ceil(this.total() / this.pageSize()))
readonly setPage = (next: number) => this.page.set(next)
readonly changePageSize = (size: number) => {
this.pageSize.set(size)
this.page.set(1)
}
}Works with: @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular
Reference
Angular PaginationBar — page-window + "Showing X of Y" text + optional page-size selector.
Built on the Button and Select components from
@molecule/app-ui-angular so it inherits the wired ClassMap styling. Apps
drive the i18n noun via the showingKey input ("Showing 1 to 10 of 123
tags" vs. "…orders") — the key takes start, end, and total
interpolation values. It is the Angular 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.tsJSDoc, not this file.
Quick Start
import { Component, signal } from '@angular/core'
import { PaginationBar } from '@molecule/app-pagination-bar-angular'
@Component({
selector: 'app-order-list',
standalone: true,
imports: [PaginationBar],
template: `
<div
mol-pagination-bar
[page]="page()"
[totalPages]="totalPages()"
[pageSize]="pageSize()"
[total]="total()"
[onPageChange]="setPage"
[pageSizeOptions]="[10, 25, 50]"
[onPageSizeChange]="changePageSize"
></div>
`,
})
export class OrderList {
readonly total = signal(123)
readonly page = signal(1)
readonly pageSize = signal(10)
readonly totalPages = () => Math.max(1, Math.ceil(this.total() / this.pageSize()))
readonly setPage = (next: number) => this.page.set(next)
readonly changePageSize = (size: number) => {
this.pageSize.set(size)
this.page.set(1)
}
}
Type
feature
Installation
npm install @molecule/app-pagination-bar-angular @angular/common @angular/core @angular/platform-browser @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
API
Interfaces
PaginationBarProps
Props accepted by PaginationBar — the same props
@molecule/app-pagination-bar-react accepts. The callback props are inputs
of the same (React) name, so a host template binds them with
[onPageChange].
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
}
Classes
PaginationBar
PaginationBar component.
Paginator with a [showing text, prev, page-window, next, size-select]
layout. The host IS the outer <div> (div[mol-pagination-bar]), matching
React's root exactly. The "Showing X to Y of Z items" text is driven by an
i18n key so apps can specialize the noun ("tags", "orders", "transactions").
The page-size selector is hidden unless pageSizeOptions + onPageSizeChange
are supplied.
This is the Angular counterpart of @molecule/app-pagination-bar-react: the
same props (React names) and the same DOM for the same input.
@Component({
selector: 'div[mol-pagination-bar]',
standalone: true,
imports: [Button, Select],
inputs: [
'page',
'totalPages',
'pageSize',
'total',
'onPageChange',
'onPageSizeChange',
'pageSizeOptions',
'showingKey',
'showingDefault',
'className',
],
host: {
'[class]': 'classes()',
},
template: `<p [class]="cm().textSize('sm')">{{ summary() }}</p>
<div [class]="cm().flex({ align: 'center', gap: 'xs' })">
<button
mol-button
[variant]="'ghost'"
[size]="'sm'"
[disabled]="page === 1"
[attr.aria-label]="previousLabel()"
(click)="previous()"
>
‹
</button>
@for (entry of pageWindow(); track $index) {
@if (entry === '...') {
<span [class]="cm().sp('px', 2)">…</span>
} @else {
<button
mol-button
[variant]="entry === page ? 'solid' : 'ghost'"
[color]="'primary'"
[size]="'sm'"
[attr.aria-current]="entry === page ? 'page' : null"
(click)="goTo(entry)"
>
{{ entry }}
</button>
}
}
<button
mol-button
[variant]="'ghost'"
[size]="'sm'"
[disabled]="page === totalPages"
[attr.aria-label]="nextLabel()"
(click)="next()"
>
›
</button>
</div>
@if (pageSizeOptions && onPageSizeChange) {
<div
mol-select
[options]="selectOptions()"
[value]="pageSizeText()"
[attr.aria-label]="pageSizeLabel()"
(valueChange)="changeSize($event)"
></div>
}`,
})
export class PaginationBar {
/** Current page (1-indexed). */
page = 1
/** Total page count (>= 1). */
totalPages = 1
/** Items per page. */
pageSize = 10
/** Total item count across all pages. */
total = 0
/** 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 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
/**
* Reactive translation, read in the injection context. Its `t` reads the
* locale, so the view re-renders the text on a locale switch.
*/
private readonly i18n = useTranslation()
/**
* The current class map.
* @returns The UIClassMap.
*/
cm(): UIClassMap {
return getClassMap()
}
/**
* Computes the wrapper class list.
* @returns The class string.
*/
classes(): string {
return this.cm().cn(
this.cm().flex({ justify: 'between', align: 'center', gap: 'md', wrap: 'wrap' }),
this.className,
)
}
/**
* The visible page-number window.
* @returns The page numbers and `'...'` sentinels.
*/
pageWindow(): (number | '...')[] {
return buildWindow(this.page, this.totalPages)
}
/**
* The translated "Showing X to Y of Z items" text.
* @returns The text.
*/
summary(): string {
const start = this.total === 0 ? 0 : (this.page - 1) * this.pageSize + 1
const end = Math.min(this.page * this.pageSize, this.total)
return this.i18n.t(
this.showingKey ?? 'pagination.showing',
{ start, end, total: this.total.toLocaleString() },
{ defaultValue: this.showingDefault ?? 'Showing {{start}} to {{end}} of {{total}} items' },
)
}
/**
* The Previous button's accessible label.
* @returns The translated label.
*/
previousLabel(): string {
return this.i18n.t('pagination.previous', {}, { defaultValue: 'Previous page' })
}
/**
* The Next button's accessible label.
* @returns The translated label.
*/
nextLabel(): string {
return this.i18n.t('pagination.next', {}, { defaultValue: 'Next page' })
}
/**
* The page-size selector's accessible label.
* @returns The translated label.
*/
pageSizeLabel(): string {
return this.i18n.t('pagination.pageSize', {}, { defaultValue: 'Page size' })
}
/**
* The current page size as the select's string value.
* @returns The value.
*/
pageSizeText(): string {
return String(this.pageSize)
}
/**
* The option entries for the page-size selector.
* @returns One `{ value, label }` per configured page size.
*/
selectOptions(): { value: string; label: string }[] {
return (this.pageSizeOptions ?? []).map((n) => ({ value: String(n), label: String(n) }))
}
/**
* Moves to the previous page (never below 1).
*/
previous(): void {
this.onPageChange?.(Math.max(1, this.page - 1))
}
/**
* Moves to the next page (never past the last).
*/
next(): void {
this.onPageChange?.(Math.min(this.totalPages, this.page + 1))
}
/**
* Moves to a page-number entry, ignoring the ellipsis sentinel.
*
* @param page - A page number, or `'...'`.
*/
goTo(page: number | '...'): void {
if (typeof page === 'number') this.onPageChange?.(page)
}
/**
* Passes the selected page size on as a number, never `NaN`.
*
* @param value - The selected option's value.
*/
changeSize(value: string): void {
this.onPageSizeChange?.(Number(value))
}
}
Injection Notes
Requirements
Peer dependencies:
@angular/common^22.0.0@angular/core^22.0.0@angular/platform-browser^22.0.0@molecule/app-angular^3.5.0 || ^4.0.0@molecule/app-ui^1.0.1@molecule/app-ui-angular^1.1.0
Runtime Dependencies
@angular/common@angular/core@angular/platform-browser@molecule/app-angular@molecule/app-ui@molecule/app-ui-angular
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 valueChange output and parses the selected value to a
number, so onPageSizeChange always receives a real page size (e.g. 25),
never NaN. Requires the binding's i18n providers and a wired ClassMap
bond. Distinct from @molecule/app-ui-angular's lower-level Pagination
(page window only — no showing-text or size selector).
Translations
Translation strings are provided by @molecule/app-locales-pagination-bar.