Pagination
Previous and next controls for stepping through a long list one page at a time, with an optional label describing the range currently on screen.
Preview
Code
Example.jsx
import { useState } from 'react';
import { Card, Box, BlockStack, InlineStack, Divider, Text, Badge, Pagination } from '@shopify/polaris';
const ORDERS = [
{ id: '1054', customer: 'Amelia Cortez', total: '$128.40', status: 'Paid' },
{ id: '1053', customer: 'Ravi Patel', total: '$64.00', status: 'Paid' },
{ id: '1052', customer: 'Joan Vermeer', total: '$212.75', status: 'Pending' },
{ id: '1051', customer: 'Tomas Nowak', total: '$39.99', status: 'Paid' },
{ id: '1050', customer: 'Grace Okafor', total: '$310.20', status: 'Refunded' },
{ id: '1049', customer: 'Lena Fischer', total: '$88.10', status: 'Paid' },
{ id: '1048', customer: 'Marco Silva', total: '$145.00', status: 'Pending' },
{ id: '1047', customer: 'Nadia Haddad', total: '$27.50', status: 'Paid' },
{ id: '1046', customer: 'Peter Lund', total: '$402.65', status: 'Paid' },
{ id: '1045', customer: 'Yuki Tanaka', total: '$73.30', status: 'Refunded' },
{ id: '1044', customer: 'Sofia Rossi', total: '$56.90', status: 'Paid' },
{ id: '1043', customer: 'Daniel Brooks', total: '$189.05', status: 'Pending' },
];
const PAGE_SIZE = 4;
const TOTAL_PAGES = Math.ceil(ORDERS.length / PAGE_SIZE);
const STATUS_TONE = { Paid: 'success', Pending: 'attention', Refunded: 'warning' };
export const Example = () => {
const [page, setPage] = useState(1);
const start = (page - 1) * PAGE_SIZE;
const rows = ORDERS.slice(start, start + PAGE_SIZE);
const label = `${start + 1}-${start + rows.length} of ${ORDERS.length} orders`;
return (
<Card padding="0">
<BlockStack>
{rows.map((order, index) => (
<Box key={order.id} padding="400" borderBlockEndWidth={index === rows.length - 1 ? '0' : '025'} borderColor="border">
<InlineStack align="space-between" blockAlign="center">
<BlockStack gap="050">
<Text as="span" fontWeight="semibold">
#{order.id}
</Text>
<Text as="span" tone="subdued" variant="bodySm">
{order.customer}
</Text>
</BlockStack>
<InlineStack gap="300" blockAlign="center">
<Badge tone={STATUS_TONE[order.status]}>{order.status}</Badge>
<Text as="span" fontWeight="medium">
{order.total}
</Text>
</InlineStack>
</InlineStack>
</Box>
))}
<Divider />
<Box padding="300">
<InlineStack align="center">
<Pagination
label={label}
hasPrevious={page > 1}
onPrevious={() => setPage((current) => current - 1)}
hasNext={page < TOTAL_PAGES}
onNext={() => setPage((current) => current + 1)}
/>
</InlineStack>
</Box>
</BlockStack>
</Card>
);
};