import type { Meta, StoryObj } from '@storybook/react'; import { Pagination, PaginationContent, PaginationEllipsis, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, } from './pagination'; import { usePagination } from './use-pagination'; import React, { useState } from 'react'; import { ChevronLeft, ChevronRight } from 'lucide-react'; type PaginationStoryProps = React.ComponentProps & { activePage?: number; }; const meta: Meta = { title: 'UI/Pagination', component: Pagination, render: args => , argTypes: { activePage: { control: { type: 'number', min: 1, max: 3 }, description: 'The current active page.', defaultValue: 2, }, }, }; export default meta; type Story = StoryObj; export const Default: Story = { args: { activePage: 2, }, render: ({ activePage, ...args }) => ( 1 2 3 ), }; export const Controlled: Story = { render: () => { const [page, setPage] = useState(1); const total = 5; return ( setPage(p => Math.max(1, p - 1))} className={ page === 1 ? 'pointer-events-none text-muted-foreground' : 'cursor-pointer' } /> {Array.from({ length: total }).map((_, i) => ( setPage(i + 1)} className="cursor-pointer" > {i + 1} ))} setPage(p => Math.min(total, p + 1))} className={ page === total ? 'pointer-events-none text-muted-foreground' : 'cursor-pointer' } /> ); }, }; /** * ## usePagination — Headless Hook * * Use `usePagination` when you need page state, ellipsis logic, and slice * indices but want to render a completely custom pagination UI — or when you * need to drive a data-fetch without any visual pagination bar at all. * * The hook computes `items` (an ordered list of page numbers + ellipsis * markers) so you never have to calculate which pages to show manually. * * ```tsx * import { usePagination } from '@xertica/ui/pagination'; * * const { currentPage, totalPages, items, next, prev, goTo, canGoPrev, canGoNext } = * usePagination({ totalItems: 200, pageSize: 20 }); * ``` */ export const HeadlessHook: Story = { name: 'usePagination (headless)', render: () => { const { currentPage, totalPages, items, next, prev, goTo, canGoPrev, canGoNext, startIndex, endIndex, } = usePagination({ totalItems: 237, pageSize: 20, siblingCount: 1 }); return (
{/* Data slice info */}

Showing items{' '} {startIndex + 1}–{endIndex} {' '} of 237

{/* Fully custom pagination bar */}
{items.map(item => item.type === 'ellipsis' ? ( … ) : ( ) )}

Page {currentPage} of {totalPages}

); }, };