import { DesignPagination } from "@/components/ui/design-pagination";| Prop | Type | Default | Description |
|---|---|---|---|
currentPage* | number | - | Current page number (1-indexed) |
totalPages* | number | - | Total number of pages |
onPageChange* | (page: number) => void | - | Callback when page changes |
previousText | string | "Previous" | Tooltip for Previous button (i18n) |
nextText | string | "Next" | Tooltip for Next button (i18n) |
showInfo | boolean | true | Show info text (e.g., '1-50 of 500') |
startIndex | number | - | Start index for info text (auto-calculated if not provided) |
endIndex | number | - | End index for info text (auto-calculated if not provided) |
totalItems | number | - | Total items count for info text |
infoText | string | - | Custom info text format with {start}, {end}, {total} placeholders |
size | "default" | "small" | "default" | Size variant for compact layouts |
className | string | - | Additional className for container |
const [currentPage, setCurrentPage] = useState(1);
const PAGE_SIZE = 50;
const totalPages = Math.ceil(items.length / PAGE_SIZE);
<DesignPagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={setCurrentPage}
/><DesignPagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={setCurrentPage}
startIndex={(currentPage - 1) * PAGE_SIZE + 1}
endIndex={Math.min(currentPage * PAGE_SIZE, totalItems)}
totalItems={totalItems}
/>const t = useTranslations("common");
<DesignPagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={setCurrentPage}
previousText={t("pagination.previous")}
nextText={t("pagination.next")}
infoText={t("pagination.showing", { start: "{start}", end: "{end}", total: "{total}" })}
/><DesignPagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={setCurrentPage}
size="small"
/><DesignPagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={setCurrentPage}
showInfo={false}
/>Use with showInfo=true and calculated indices
const PAGE_SIZE = 50;
const totalPages = Math.ceil(data.length / PAGE_SIZE);
const paginatedData = data.slice((currentPage - 1) * PAGE_SIZE, currentPage * PAGE_SIZE);
<DesignPagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={(page) => {
setCurrentPage(page);
// Optionally scroll to top of table
}}
startIndex={(currentPage - 1) * PAGE_SIZE + 1}
endIndex={Math.min(currentPage * PAGE_SIZE, data.length)}
totalItems={data.length}
/>Reset page to 1 when filters change
// Reset pagination when filters change
useEffect(() => {
setCurrentPage(1);
}, [searchQuery, filters]);
<DesignPagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={setCurrentPage}
/>Place pagination below cards with spacing
<div className="grid grid-cols-3 gap-4">
{paginatedItems.map(item => <Card key={item.id} {...item} />)}
</div>
<div className="mt-6 pt-4 border-t">
<DesignPagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={setCurrentPage}
/>
</div>Component is responsive by default (stacks on mobile)
{/* Info text and controls stack on mobile, side-by-side on desktop */}
<DesignPagination
currentPage={currentPage}
totalPages={totalPages}
onPageChange={setCurrentPage}
/>Always reset to page 1 when filters/search change
useEffect(() => {
setCurrentPage(1);
}, [searchQuery, sortField, filters]);Provide accurate startIndex/endIndex for info text
<DesignPagination
startIndex={(currentPage - 1) * PAGE_SIZE + 1}
endIndex={Math.min(currentPage * PAGE_SIZE, totalItems)}
totalItems={totalItems}
/>Use i18n props for internationalization
<DesignPagination
previousText={t("pagination.previous")}
nextText={t("pagination.next")}
/>Don't show pagination when there's only one page (auto-hidden)
// Component automatically returns null when totalPages <= 1
// No need to conditionally render
// Nav buttons are disabled (not hidden) at boundaries to prevent layout shiftDon't forget to slice data when using pagination
// Wrong - showing all data
{data.map(item => ...)}
// Correct - slice data based on currentPage
const paginatedData = data.slice(
(currentPage - 1) * PAGE_SIZE,
currentPage * PAGE_SIZE
);
{paginatedData.map(item => ...)}Interactive examples showing pagination behavior
First page - Previous button disabled
Both Previous and Next buttons enabled, ellipsis shown
Next button disabled
When totalPages <= 7, all pages shown
Smaller variant for dense layouts
Click to navigate between pages
How page numbers are displayed for different positions
Near Start (page 1-4): Shows 1 2 3 4 5 ... 20
Middle (page 5-16): Shows 1 ... 9 10 11 ... 20
Near End (page 17-20): Shows 1 ... 16 17 18 19 20