Paging
The <smart-paging> component provides a flexible pagination wrapper with an InjectionToken-based extension mechanism. It renders a default PagingStandardComponent which can be replaced via PAGING_STANDARD_COMPONENT_TOKEN.
Usage
<smart-paging
[currentPage]="currentPage()"
[totalPages]="totalPages"
[pageSize]="pageSize"
[totalItems]="totalItems"
(pageChange)="onPageChange($event)"
/>
The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Components
PagingComponent (<smart-paging>)
Main wrapper component. Renders PagingStandardComponent by default, or the component provided for PAGING_STANDARD_COMPONENT_TOKEN. It creates that component once with ViewContainerRef.createComponent (not NgComponentOutlet), marks its host with data-smart-paging-host="standard" or "injected", and re-emits its pageChange as its own. On every change it hands currentPage, totalPages, pageSize, totalItems, variant and class to the rendered component with setInput, resolved to the names that component declares: a custom implementation that redeclares cssClass without the class alias still gets the classes, and an input the component does not declare is skipped.
The page is owned by the parent: bind currentPage and update it from (pageChange). goToPage emits any page from 1 to totalPages (the current one included) and ignores the rest; nextPage and previousPage do nothing on the last or first page.
PagingStandardComponent (<smart-paging-standard>)
Default concrete implementation: a <nav> with prev/next buttons (translated through the prev and next keys), numeric page buttons with '...' gaps and aria-current="page" on the active page, styled with smart: Tailwind classes including dark mode and disabled states. The class input goes on the <nav>. It renders no results summary, so pageSize and totalItems change nothing here, and variant only shows up as the data-variant attribute of the <nav>.
PagingPresetComponent (<smart-paging-preset>)
Styled variation that extends PagingBaseComponent and is a drop-in replacement for PagingStandardComponent. Register it via PAGING_STANDARD_COMPONENT_TOKEN (or register every preset at once with provideSmartPresets()) to restyle every <smart-paging>, or use the <smart-paging-preset> selector directly. Translates the Preline pagination examples into smart:-prefixed vanilla Tailwind classes with explicit dark: variants. It drives page state purely through the inherited signals/methods (pages, canGoBack, canGoForward, goToPage, nextPage, previousPage) — no Preline JS runtime is required. The variant input selects the layout:
card-footer— a "Showing X to Y of Z results" summary (built fromshowingFrom/showingTo/totalItems, so it needspageSizeandtotalItems) alongside the nav, justified between onsm+ screens;centered— the nav centered horizontally;simple— the bare nav.
The "Showing … results", "Previous" and "Next" texts of the preset are plain English, not translated. The class input goes on the outer container <div>, not on the <nav>. The per-variant class recipes are internal to the preset (not exported from @smartsoft001/angular).
PagingPresetComponent keeps the inherited cssClass input with its class alias, so class works the same on <smart-paging> and on <smart-paging-preset>. <smart-paging variant="centered"> selects the preset layout when the preset is registered, and later changes of variant reach it too.
PagingBaseComponent (abstract)
Abstract base directive for extending custom paging implementations. Provides signal-based state (currentPage, totalPages, pageSize, totalItems, variant, cssClass), computed helpers (showingFrom, showingTo, canGoBack, canGoForward, pages) and navigation methods (goToPage, nextPage, previousPage).
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
currentPage | InputSignal<number> | 1 | Current active page |
totalPages | InputSignal<number> | 1 | Total number of pages |
pageSize | InputSignal<number> | 10 | Items per page; only the preset's card-footer summary uses it |
totalItems | InputSignal<number> | 0 | Total number of items; only the preset's card-footer summary uses it |
variant | InputSignal<PagingVariant> | 'card-footer' | Layout variant, styled by the preset; the standard exposes it as data-variant |
class | InputSignal<string> | '' | External CSS classes (alias for cssClass), forwarded to the rendered paging |
Outputs
| Output | Type | Description |
|---|---|---|
pageChange | OutputEmitter<number> | Emits the requested page number (1 to totalPages) |
PAGING_STANDARD_COMPONENT_TOKEN
InjectionToken that allows replacing the default PagingStandardComponent with a custom implementation. Provide a Type<PagingBaseComponent> to override; provideSmartPresets() provides PagingPresetComponent for it together with every other preset.
Extending the base class
import {
ChangeDetectionStrategy,
Component,
signal,
ViewEncapsulation,
} from '@angular/core';
import {
PAGING_STANDARD_COMPONENT_TOKEN,
PagingBaseComponent,
PagingComponent,
} from '@smartsoft001/angular';
@Component({
selector: 'docs-custom-paging',
template: `
<nav class="docs-paging" [class]="cssClass()" aria-label="Pagination">
<p class="docs-paging__summary">
Showing {{ showingFrom() }} to {{ showingTo() }} of
{{ totalItems() }} results
</p>
<div class="docs-paging__pages">
<button
type="button"
class="docs-paging__previous"
[disabled]="!canGoBack()"
(click)="previousPage()"
>
Previous
</button>
@for (page of pages(); track $index) {
@if (page === '...') {
<span class="docs-paging__gap" aria-hidden="true">…</span>
} @else {
<button
type="button"
class="docs-paging__page"
[attr.aria-current]="page === currentPage() ? 'page' : null"
(click)="goToPage(+page)"
>
{{ page }}
</button>
}
}
<button
type="button"
class="docs-paging__next"
[disabled]="!canGoForward()"
(click)="nextPage()"
>
Next
</button>
</div>
</nav>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
// The class passed to <smart-paging> arrives in the inherited cssClass input
// (alias `class`), and every other input and the pageChange output come from
// the base class, so the component only adds its template.
export class CustomPagingComponent extends PagingBaseComponent {}
@Component({
selector: 'docs-paging-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [PagingComponent],
// The token swaps the standard paging for the custom one everywhere below
// this component, so consumers keep writing `<smart-paging>`.
providers: [
{
provide: PAGING_STANDARD_COMPONENT_TOKEN,
useValue: CustomPagingComponent,
},
],
template: `
<smart-paging
[currentPage]="currentPage()"
[totalPages]="5"
[pageSize]="10"
[totalItems]="48"
(pageChange)="currentPage.set($event)"
/>
`,
})
export class PagingCustomExampleComponent {
readonly currentPage = signal(1);
}
Source
The component lives in packages/shared/angular/src/lib/components/paging and is documented for Claude Code by the angular-components-paging skill.
SmartPaging renders pagination controls: previous / next buttons around a page list with '...' gaps (all pages up to 7, otherwise the first, the last and the neighbours of the current one), and, in the preset's card-footer variant, a "Showing x to y of z results" summary. The page is owned by the parent: pass currentPage and update it from onPageChange(page). Navigation beyond the first or last page is ignored; clicking the current page still reports it.
Usage
import { useState } from 'react';
import { SmartPaging } from '@smartsoft001/react';
const PAGE_SIZE = 10;
const TOTAL_ITEMS = 97;
const TOTAL_PAGES = Math.ceil(TOTAL_ITEMS / PAGE_SIZE);
export function PagingUsageExample() {
// The page is owned by the parent: onPageChange reports the requested page.
const [currentPage, setCurrentPage] = useState(1);
return (
<SmartPaging
currentPage={currentPage}
totalPages={TOTAL_PAGES}
pageSize={PAGE_SIZE}
totalItems={TOTAL_ITEMS}
onPageChange={setCurrentPage}
/>
);
}
The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Exports
All from @smartsoft001/react.
| Export | Kind | What it is |
|---|---|---|
SmartPaging | component | Renders the implementation registered as components.paging on SmartProvider, SmartPagingStandard by default. |
SmartPagingPreset | component | Styled paging variation (preset). |
SmartPagingStandard | component | The default paging rendering: translated prev / next buttons around the page list. |
usePaging | hook | The behaviour every paging variant shares: the "showing x to y" range, the page list with '...' gaps (all pages up to 7, otherwise the first, the last and the neighbours of the current one), and the guarded navigation that reports the requested page through onPageChange. |
The preset's class helpers (getPagingContainerClasses, getPagingNavClasses, getPagingPageClasses, PAGING_ELLIPSIS_CLASSES, PAGING_RESULTS_CLASSES, PAGING_PAGE_LIST_CLASSES, PAGING_NAV_BUTTON_CLASSES) and their SmartPagingPresetVariant type (the same union as PagingVariant) are exported too, for a custom implementation that wants the preset look.
Props and Types
SmartPagingProps
| Prop | Type | Default | Description |
|---|---|---|---|
currentPage? | number | 1 | The current page, 1-based. |
totalPages? | number | 1 | Number of pages. |
pageSize? | number | 10 | Items per page, for the preset's card-footer summary. |
totalItems? | number | 0 | Total number of items, for the preset's card-footer summary. |
variant? | PagingVariant | 'card-footer' | The layout (preset); the standard exposes it as data-variant. |
className? | string | — | Classes on the root: the standard's <nav>, the preset's <div>. |
onPageChange? | (page: number) => void | — | Called with the requested page. |
Related types
PagingVariant:'card-footer' \| 'centered' \| 'simple'— Layout variant:'card-footer'(results summary alongside the nav),'centered'or'simple'.
Replacing the Implementation
SmartPaging renders the component registered under the 'paging' key of SmartProvider's components, and SmartPagingStandard when nothing is registered there. Every SmartPaging below the provider then renders the registered component, which receives the same props.
SmartPagingPreset is the styled (preset) implementation: register it under the 'paging' key of SmartProvider's components, render it directly in place of SmartPaging, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.
The usePaging hook
The behaviour every paging variant shares: the "showing x to y" range, the page list with '...' gaps (all pages up to 7, otherwise the first, the last and the neighbours of the current one), and the guarded navigation that reports the requested page through onPageChange. The page itself stays owned by the parent (currentPage).
| Returns | Type | Description |
|---|---|---|
currentPage | number | currentPage with its default. |
totalPages | number | totalPages with its default. |
pageSize | number | pageSize with its default. |
totalItems | number | totalItems with its default. |
variant | PagingVariant | variant with its default. |
showingFrom | number | First item number of the current page. |
showingTo | number | Last item number of the current page. |
canGoBack | boolean | currentPage > 1. |
canGoForward | boolean | currentPage < totalPages. |
pages | (number | "...")[] | The page numbers to render, with '...' gaps. |
goToPage | (page: number) => void | Reports a page through onPageChange (ignored when out of range). |
nextPage | () => void | Reports the next page. |
previousPage | () => void | Reports the previous page. |
import { useState } from 'react';
import {
cn,
SmartPaging,
SmartPagingProps,
SmartProvider,
usePaging,
} from '@smartsoft001/react';
export function CustomPaging(props: SmartPagingProps) {
// usePaging keeps the shared behaviour: the range, the page list with gaps
// and the guarded navigation that reports the page through onPageChange.
const {
currentPage,
totalItems,
showingFrom,
showingTo,
canGoBack,
canGoForward,
pages,
goToPage,
nextPage,
previousPage,
} = usePaging(props);
return (
<nav className={cn('docs-paging', props.className)} aria-label="Pagination">
<p className="docs-paging__summary">
Showing {showingFrom} to {showingTo} of {totalItems} results
</p>
<div className="docs-paging__pages">
<button
type="button"
className="docs-paging__previous"
disabled={!canGoBack}
onClick={previousPage}
>
Previous
</button>
{pages.map((page, index) =>
page === '...' ? (
<span key={index} className="docs-paging__gap" aria-hidden="true">
…
</span>
) : (
<button
key={index}
type="button"
className="docs-paging__page"
aria-current={page === currentPage ? 'page' : undefined}
onClick={() => goToPage(page)}
>
{page}
</button>
),
)}
<button
type="button"
className="docs-paging__next"
disabled={!canGoForward}
onClick={nextPage}
>
Next
</button>
</div>
</nav>
);
}
// A module constant: a new object on every render would change the context.
const components = { paging: CustomPaging };
export function PagingCustomExample() {
const [currentPage, setCurrentPage] = useState(1);
// Every SmartPaging below the provider renders CustomPaging.
return (
<SmartProvider components={components}>
<SmartPaging
currentPage={currentPage}
totalPages={5}
pageSize={10}
totalItems={48}
onPageChange={setCurrentPage}
/>
</SmartProvider>
);
}
Styling
SmartPagingStandardrenders translated prev / next buttons and the page list, without a summary (pageSize,totalItemsandvariantchange nothing visible there);SmartPagingPresetrenders the three layouts withsmart:dark:variants, but its "Showing x to y of z results", "Previous" and "Next" texts are not translated.
Source
The component lives in packages/shared/react/src/lib/components/paging and is documented for Claude Code by the react-components-paging skill.