Getting Started
Components
- Advanced Toast
- ArrowButton
- Arrows
- Avatar
- Backdrop
- Basic Toast
- Breadcrumb
- Button
- CardBackground
- Card
- ChatButton
- Checkbox
- Checkboxes
- Chip
- ChoiceExpander
- Clickable
- Date Field
- Dropdown
- ElasticHeight
- ExpandableCard
- Filter
- FormCheckbox
- Form Control
- Form Label
- HamburgerIcon
- Heading
- Image
- Link
- Loader
- Number Field
- Pagination
- Password
- Phone Field
- Popin
- Portal
- Prose
- Radio Group
- Radio
- Range
- Select
- SidebarLayout
- Spinner
- Switch
- Tabs
- Tag
- TextField
- ValidationMessage
Current Page: 1
'use client';
import { useState } from 'react';
import { Pagination } from '@/ui/Pagination';
export function PaginationDemo() {
const [currentPage, setCurrentPage] = useState(1);
return (
<div className="space-y-4">
<p className="text-center text-sm text-grey">Current Page: {currentPage}</p>
<Pagination
defaultPage={currentPage}
count={10}
labels={{
previous: 'Previous',
next: 'Next',
}}
onChange={setCurrentPage}
/>
</div>
);
}
Installation
npx shadcn@latest add https://develop.trident-ui.pro.clubmed/r/pagination.json
Usage
'use client';
import { useState } from 'react';
import { Pagination } from '@/docs/lib/ui/pagination';
export function Component() {
const [currentPage, setCurrentPage] = useState(1);
return (
<Pagination
defaultPage={currentPage}
count={10}
labels={{
previous: 'Previous',
next: 'Next',
}}
onChange={setCurrentPage}
/>
);
}API Reference
Pagination
| Prop | Type | Default | Description |
|---|---|---|---|
defaultPage | number | - | Required. The current page number (must be >= 1). Controls which page is visually highlighted. |
count | number | - | Required. The total number of pages available for navigation. |
onChange | (page: number) => void | - | Required. Callback function invoked when user navigates to a different page. |
labels | ScrollerLabels | {} | Required. Object containing previous and next string labels for navigation buttons. |
buttonClassName | string | "md:mr-32" | Additional CSS classes applied to the previous and next button containers. |
buttonLabelClassName | string | "md:flex" | Additional CSS classes applied to the labels within the previous and next buttons. |
className | string | undefined | Additional CSS classes applied to the root navigation element. |
paginationFactory | typeof generatePagination | generatePagination | Custom factory function to generate pagination elements. Useful for custom pagination logic. |
The component also accepts all standard HTML <nav> element attributes via HTMLAttributes<HTMLElement>.
Notes
- Responsive Design: The pagination automatically adjusts for mobile and desktop views. On mobile, fewer page buttons are shown with ellipsis indicators to save space.
- Accessibility: The component includes proper ARIA attributes including
role="navigation",aria-label="pagination navigation",aria-controls="page-content", andaria-current="page"for the active page. - Visual States: The active page is highlighted with a black circular button, while inactive pages use white circular buttons. Disabled previous/next buttons appear in grey.
- Ellipsis Display: When there are many pages, ellipsis (…) indicators appear to show there are more pages available. Different ellipsis are shown for mobile vs desktop breakpoints.
- Page Button Hiding: On mobile devices, some page buttons are automatically hidden to keep the UI compact while maintaining context of the current position.
- Navigation Buttons: Previous and next buttons include both icon and text label. The text labels are hidden on mobile but visible on desktop (controlled by
buttonLabelClassName). - Custom Pagination Logic: The
paginationFactoryprop allows you to provide a custom function for generating the pagination structure, enabling advanced use cases like server-side pagination or custom page ranges. - Data Attributes: The component has
data-name="Pagination"for testing and debugging purposes. - Client Component: This is a client component (uses "use client" directive) as it requires interactivity for page navigation.