@sereno-ds/ui 0.35.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_internal/pageRange.d.ts +23 -0
- package/dist/_internal/pageRange.js +27 -0
- package/dist/_internal/pageRange.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/navigation/Pagination.d.ts +54 -0
- package/dist/navigation/Pagination.js +117 -0
- package/dist/navigation/Pagination.js.map +1 -0
- package/dist/styles.css +21 -0
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type PageItem = number | 'start-ellipsis' | 'end-ellipsis';
|
|
2
|
+
/**
|
|
3
|
+
* Which page numbers `Pagination` shows, with an ellipsis where a run is folded away.
|
|
4
|
+
*
|
|
5
|
+
* `boundaryCount` pages stay pinned at each end and `siblingCount` pages flank the
|
|
6
|
+
* current one. The list keeps the **same length** wherever the current page is (until
|
|
7
|
+
* there are few enough pages to show them all), so the control doesn't change width as
|
|
8
|
+
* you page through, and an ellipsis only ever stands for two or more hidden pages: a
|
|
9
|
+
* gap of exactly one page shows that page's number instead, since "…" would be no
|
|
10
|
+
* shorter.
|
|
11
|
+
*
|
|
12
|
+
* ```
|
|
13
|
+
* getPageItems(1, 20) // 1 2 3 4 5 … 20
|
|
14
|
+
* getPageItems(10, 20) // 1 … 9 10 11 … 20
|
|
15
|
+
* getPageItems(20, 20) // 1 … 16 17 18 19 20
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Pure and framework-free, so it's unit-testable on its own. `page` is 1-based and
|
|
19
|
+
* clamped into range; a `pageCount` under 1 has nothing to show.
|
|
20
|
+
*/
|
|
21
|
+
declare function getPageItems(page: number, pageCount: number, siblingCount?: number, boundaryCount?: number): PageItem[];
|
|
22
|
+
|
|
23
|
+
export { type PageItem, getPageItems };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const range = (from, to) => Array.from({ length: Math.max(to - from + 1, 0) }, (_, i) => from + i);
|
|
2
|
+
function getPageItems(page, pageCount, siblingCount = 1, boundaryCount = 1) {
|
|
3
|
+
const count = Number.isFinite(pageCount) ? Math.max(0, Math.floor(pageCount)) : 0;
|
|
4
|
+
if (count === 0) return [];
|
|
5
|
+
const current = Math.min(Math.max(Math.floor(page) || 1, 1), count);
|
|
6
|
+
const siblings = Math.max(0, Math.floor(siblingCount));
|
|
7
|
+
const boundary = Math.max(0, Math.floor(boundaryCount));
|
|
8
|
+
const startPages = range(1, Math.min(boundary, count));
|
|
9
|
+
const endPages = range(Math.max(count - boundary + 1, boundary + 1), count);
|
|
10
|
+
const siblingsStart = Math.max(Math.min(current - siblings, count - boundary - siblings * 2 - 1), boundary + 2);
|
|
11
|
+
const siblingsEnd = Math.min(
|
|
12
|
+
Math.max(current + siblings, boundary + siblings * 2 + 2),
|
|
13
|
+
endPages.length > 0 ? endPages[0] - 2 : count - 1
|
|
14
|
+
);
|
|
15
|
+
return [
|
|
16
|
+
...startPages,
|
|
17
|
+
// Before the window: an ellipsis if 2+ pages are folded away, else the lone page in the gap.
|
|
18
|
+
...siblingsStart > boundary + 2 ? ["start-ellipsis"] : boundary + 1 < count - boundary ? [boundary + 1] : [],
|
|
19
|
+
...range(siblingsStart, siblingsEnd),
|
|
20
|
+
...siblingsEnd < count - boundary - 1 ? ["end-ellipsis"] : count - boundary > boundary ? [count - boundary] : [],
|
|
21
|
+
...endPages
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
getPageItems
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=pageRange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/_internal/pageRange.ts"],"sourcesContent":["export type PageItem = number | 'start-ellipsis' | 'end-ellipsis';\n\nconst range = (from: number, to: number): number[] => Array.from({ length: Math.max(to - from + 1, 0) }, (_, i) => from + i);\n\n/**\n * Which page numbers `Pagination` shows, with an ellipsis where a run is folded away.\n *\n * `boundaryCount` pages stay pinned at each end and `siblingCount` pages flank the\n * current one. The list keeps the **same length** wherever the current page is (until\n * there are few enough pages to show them all), so the control doesn't change width as\n * you page through, and an ellipsis only ever stands for two or more hidden pages: a\n * gap of exactly one page shows that page's number instead, since \"…\" would be no\n * shorter.\n *\n * ```\n * getPageItems(1, 20) // 1 2 3 4 5 … 20\n * getPageItems(10, 20) // 1 … 9 10 11 … 20\n * getPageItems(20, 20) // 1 … 16 17 18 19 20\n * ```\n *\n * Pure and framework-free, so it's unit-testable on its own. `page` is 1-based and\n * clamped into range; a `pageCount` under 1 has nothing to show.\n */\nexport function getPageItems(page: number, pageCount: number, siblingCount = 1, boundaryCount = 1): PageItem[] {\n // NaN / Infinity (say `Math.ceil(0 / 0)` from a zero page size) count as \"no pages\".\n const count = Number.isFinite(pageCount) ? Math.max(0, Math.floor(pageCount)) : 0;\n if (count === 0) return [];\n const current = Math.min(Math.max(Math.floor(page) || 1, 1), count);\n const siblings = Math.max(0, Math.floor(siblingCount));\n const boundary = Math.max(0, Math.floor(boundaryCount));\n\n const startPages = range(1, Math.min(boundary, count));\n const endPages = range(Math.max(count - boundary + 1, boundary + 1), count);\n\n // The window around the current page, pushed inward so it never overlaps the pinned\n // ends and never leaves a one-page gap next to them.\n const siblingsStart = Math.max(Math.min(current - siblings, count - boundary - siblings * 2 - 1), boundary + 2);\n const siblingsEnd = Math.min(\n Math.max(current + siblings, boundary + siblings * 2 + 2),\n endPages.length > 0 ? endPages[0] - 2 : count - 1,\n );\n\n return [\n ...startPages,\n // Before the window: an ellipsis if 2+ pages are folded away, else the lone page in the gap.\n ...(siblingsStart > boundary + 2 ? (['start-ellipsis'] as const) : boundary + 1 < count - boundary ? [boundary + 1] : []),\n ...range(siblingsStart, siblingsEnd),\n ...(siblingsEnd < count - boundary - 1 ? (['end-ellipsis'] as const) : count - boundary > boundary ? [count - boundary] : []),\n ...endPages,\n ];\n}\n"],"mappings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AQ,IAAI,CAAC;AAAA,IAC3H,GAAG;AAAA,EACL;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export { Tabs, TabsListProps, TabsPanelProps, TabsProps, TabsTabProps } from './
|
|
|
23
23
|
export { BottomNav, BottomNavItemProps, BottomNavProps } from './navigation/BottomNav.js';
|
|
24
24
|
export { SidebarNav, SidebarNavItemProps, SidebarNavProps, SidebarNavSectionProps, SidebarNavSubItemProps } from './navigation/SidebarNav.js';
|
|
25
25
|
export { Stepper, StepperProps, StepperStepProps } from './navigation/Stepper.js';
|
|
26
|
+
export { Pagination, PaginationLabels, PaginationProps } from './navigation/Pagination.js';
|
|
26
27
|
export { Alert, AlertProps } from './feedback/Alert.js';
|
|
27
28
|
export { Toast, ToastProps } from './feedback/Toast.js';
|
|
28
29
|
export { ToastApi, ToastContextValue, ToastOptions, ToastPosition, ToastProvider, ToastProviderProps, useToast } from './feedback/ToastProvider.js';
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
SidebarNav
|
|
28
28
|
} from "./navigation/SidebarNav.js";
|
|
29
29
|
import { Stepper } from "./navigation/Stepper.js";
|
|
30
|
+
import { Pagination } from "./navigation/Pagination.js";
|
|
30
31
|
import { Alert } from "./feedback/Alert.js";
|
|
31
32
|
import { Toast } from "./feedback/Toast.js";
|
|
32
33
|
import {
|
|
@@ -56,6 +57,7 @@ export {
|
|
|
56
57
|
IconButton,
|
|
57
58
|
Input,
|
|
58
59
|
Menu,
|
|
60
|
+
Pagination,
|
|
59
61
|
Radio,
|
|
60
62
|
SearchInput,
|
|
61
63
|
Select,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Sereno Design System — public component surface. See the /design-system\n// showcase for the live catalog, or the barrel smoke test for the full list.\n// Icons are passed in as props (lucide-react), never imported here; theming is\n// 100% CSS custom properties.\n\n// core\nexport { Typography, type TypographyProps, type TypographyVariant, type TypographyColor } from './core/Typography';\nexport { Button, type ButtonProps } from './core/Button';\nexport { IconButton, type IconButtonProps } from './core/IconButton';\nexport { Badge, type BadgeProps } from './core/Badge';\nexport { Card, type CardProps } from './core/Card';\nexport { Avatar, type AvatarProps } from './core/Avatar';\nexport { Brand, type BrandProps } from './core/Brand';\nexport { Menu, type MenuProps, type MenuItem, type MenuEntry, type MenuSeparator, type MenuHeading } from './core/Menu';\nexport {\n Table,\n type TableProps,\n type TableRowProps,\n type HeaderCellProps,\n type CellProps,\n type TableSort,\n type SortDirection,\n} from './core/Table';\n\n// forms\nexport { Input, type InputProps } from './forms/Input';\nexport { Textarea, type TextareaProps } from './forms/Textarea';\nexport { Select, type SelectProps, type SelectOption } from './forms/Select';\nexport { Checkbox, type CheckboxProps } from './forms/Checkbox';\nexport { Radio, type RadioProps } from './forms/Radio';\nexport { Switch, type SwitchProps } from './forms/Switch';\nexport { DateTimePicker, type DateTimePickerProps, type TimeSlot } from './forms/DateTimePicker';\nexport { DatePicker, type DatePickerProps, type DatePickerHandle } from './forms/DatePicker';\nexport { FileUpload, type FileUploadProps } from './forms/FileUpload';\nexport { AvatarUpload, type AvatarUploadProps } from './forms/AvatarUpload';\nexport { SearchInput, type SearchInputProps } from './forms/SearchInput';\n\n// navigation\nexport { TopBar, type TopBarProps, type TopBarLeadingProps, type TopBarTitleProps, type TopBarActionsProps } from './navigation/TopBar';\nexport { Tabs, type TabsProps, type TabsListProps, type TabsTabProps, type TabsPanelProps } from './navigation/Tabs';\nexport { BottomNav, type BottomNavProps, type BottomNavItemProps } from './navigation/BottomNav';\nexport {\n SidebarNav,\n type SidebarNavProps,\n type SidebarNavSectionProps,\n type SidebarNavItemProps,\n type SidebarNavSubItemProps,\n} from './navigation/SidebarNav';\nexport { Stepper, type StepperProps, type StepperStepProps } from './navigation/Stepper';\n\n// feedback\nexport { Alert, type AlertProps } from './feedback/Alert';\nexport { Toast, type ToastProps } from './feedback/Toast';\nexport {\n ToastProvider,\n useToast,\n type ToastProviderProps,\n type ToastOptions,\n type ToastApi,\n type ToastContextValue,\n type ToastPosition,\n} from './feedback/ToastProvider';\nexport { Dialog, type DialogProps, type DialogHeaderProps, type DialogBodyProps, type DialogFooterProps } from './feedback/Dialog';\nexport { Skeleton, type SkeletonProps } from './feedback/Skeleton';\nexport { EmptyState, type EmptyStateProps } from './feedback/EmptyState';\n\n// theme — the `data-theme` provider (next-themes) + the light/dark toggle\nexport { ThemeProvider } from './theme/ThemeProvider';\nexport { ThemeToggle } from './theme/ThemeToggle';\n"],"mappings":"AAMA,SAAS,kBAAsF;AAC/F,SAAS,cAAgC;AACzC,SAAS,kBAAwC;AACjD,SAAS,aAA8B;AACvC,SAAS,YAA4B;AACrC,SAAS,cAAgC;AACzC,SAAS,aAA8B;AACvC,SAAS,YAAiG;AAC1G;AAAA,EACE;AAAA,OAOK;AAGP,SAAS,aAA8B;AACvC,SAAS,gBAAoC;AAC7C,SAAS,cAAmD;AAC5D,SAAS,gBAAoC;AAC7C,SAAS,aAA8B;AACvC,SAAS,cAAgC;AACzC,SAAS,sBAA+D;AACxE,SAAS,kBAA+D;AACxE,SAAS,kBAAwC;AACjD,SAAS,oBAA4C;AACrD,SAAS,mBAA0C;AAGnD,SAAS,cAAyG;AAClH,SAAS,YAAwF;AACjG,SAAS,iBAA+D;AACxE;AAAA,EACE;AAAA,OAKK;AACP,SAAS,eAAyD;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Sereno Design System — public component surface. See the /design-system\n// showcase for the live catalog, or the barrel smoke test for the full list.\n// Icons are passed in as props (lucide-react), never imported here; theming is\n// 100% CSS custom properties.\n\n// core\nexport { Typography, type TypographyProps, type TypographyVariant, type TypographyColor } from './core/Typography';\nexport { Button, type ButtonProps } from './core/Button';\nexport { IconButton, type IconButtonProps } from './core/IconButton';\nexport { Badge, type BadgeProps } from './core/Badge';\nexport { Card, type CardProps } from './core/Card';\nexport { Avatar, type AvatarProps } from './core/Avatar';\nexport { Brand, type BrandProps } from './core/Brand';\nexport { Menu, type MenuProps, type MenuItem, type MenuEntry, type MenuSeparator, type MenuHeading } from './core/Menu';\nexport {\n Table,\n type TableProps,\n type TableRowProps,\n type HeaderCellProps,\n type CellProps,\n type TableSort,\n type SortDirection,\n} from './core/Table';\n\n// forms\nexport { Input, type InputProps } from './forms/Input';\nexport { Textarea, type TextareaProps } from './forms/Textarea';\nexport { Select, type SelectProps, type SelectOption } from './forms/Select';\nexport { Checkbox, type CheckboxProps } from './forms/Checkbox';\nexport { Radio, type RadioProps } from './forms/Radio';\nexport { Switch, type SwitchProps } from './forms/Switch';\nexport { DateTimePicker, type DateTimePickerProps, type TimeSlot } from './forms/DateTimePicker';\nexport { DatePicker, type DatePickerProps, type DatePickerHandle } from './forms/DatePicker';\nexport { FileUpload, type FileUploadProps } from './forms/FileUpload';\nexport { AvatarUpload, type AvatarUploadProps } from './forms/AvatarUpload';\nexport { SearchInput, type SearchInputProps } from './forms/SearchInput';\n\n// navigation\nexport { TopBar, type TopBarProps, type TopBarLeadingProps, type TopBarTitleProps, type TopBarActionsProps } from './navigation/TopBar';\nexport { Tabs, type TabsProps, type TabsListProps, type TabsTabProps, type TabsPanelProps } from './navigation/Tabs';\nexport { BottomNav, type BottomNavProps, type BottomNavItemProps } from './navigation/BottomNav';\nexport {\n SidebarNav,\n type SidebarNavProps,\n type SidebarNavSectionProps,\n type SidebarNavItemProps,\n type SidebarNavSubItemProps,\n} from './navigation/SidebarNav';\nexport { Stepper, type StepperProps, type StepperStepProps } from './navigation/Stepper';\nexport { Pagination, type PaginationProps, type PaginationLabels } from './navigation/Pagination';\n\n// feedback\nexport { Alert, type AlertProps } from './feedback/Alert';\nexport { Toast, type ToastProps } from './feedback/Toast';\nexport {\n ToastProvider,\n useToast,\n type ToastProviderProps,\n type ToastOptions,\n type ToastApi,\n type ToastContextValue,\n type ToastPosition,\n} from './feedback/ToastProvider';\nexport { Dialog, type DialogProps, type DialogHeaderProps, type DialogBodyProps, type DialogFooterProps } from './feedback/Dialog';\nexport { Skeleton, type SkeletonProps } from './feedback/Skeleton';\nexport { EmptyState, type EmptyStateProps } from './feedback/EmptyState';\n\n// theme — the `data-theme` provider (next-themes) + the light/dark toggle\nexport { ThemeProvider } from './theme/ThemeProvider';\nexport { ThemeToggle } from './theme/ThemeToggle';\n"],"mappings":"AAMA,SAAS,kBAAsF;AAC/F,SAAS,cAAgC;AACzC,SAAS,kBAAwC;AACjD,SAAS,aAA8B;AACvC,SAAS,YAA4B;AACrC,SAAS,cAAgC;AACzC,SAAS,aAA8B;AACvC,SAAS,YAAiG;AAC1G;AAAA,EACE;AAAA,OAOK;AAGP,SAAS,aAA8B;AACvC,SAAS,gBAAoC;AAC7C,SAAS,cAAmD;AAC5D,SAAS,gBAAoC;AAC7C,SAAS,aAA8B;AACvC,SAAS,cAAgC;AACzC,SAAS,sBAA+D;AACxE,SAAS,kBAA+D;AACxE,SAAS,kBAAwC;AACjD,SAAS,oBAA4C;AACrD,SAAS,mBAA0C;AAGnD,SAAS,cAAyG;AAClH,SAAS,YAAwF;AACjG,SAAS,iBAA+D;AACxE;AAAA,EACE;AAAA,OAKK;AACP,SAAS,eAAyD;AAClE,SAAS,kBAA+D;AAGxE,SAAS,aAA8B;AACvC,SAAS,aAA8B;AACvC;AAAA,EACE;AAAA,EACA;AAAA,OAMK;AACP,SAAS,cAAsG;AAC/G,SAAS,gBAAoC;AAC7C,SAAS,kBAAwC;AAGjD,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;","names":[]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Page navigation for a long list or a `Table`: previous / next, a run of page numbers
|
|
5
|
+
* with "…" where pages are folded away, and (optionally) first / last. A dedicated
|
|
6
|
+
* control, not a `Table` feature. The table never paginates for you; you slice the rows
|
|
7
|
+
* and pass the page in.
|
|
8
|
+
*
|
|
9
|
+
* ```tsx
|
|
10
|
+
* const [page, setPage] = React.useState(1);
|
|
11
|
+
* const pageSize = 10;
|
|
12
|
+
*
|
|
13
|
+
* <Table caption="Clients">…{rows.slice((page - 1) * pageSize, page * pageSize)}…</Table>
|
|
14
|
+
* <Pagination page={page} pageCount={Math.ceil(rows.length / pageSize)} onPageChange={setPage} />
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* **Controlled**: `page` is 1-based and lives in your state, next to the data fetching it
|
|
18
|
+
* drives. A **config API**, not a compound one, since there's nothing a consumer would
|
|
19
|
+
* author per page (same call as `Select`, see AGENTS.md). Under `--bp-sm` (560px) the
|
|
20
|
+
* numbers fold away and it becomes previous / "Page 3 of 12" / next, so it fits a phone.
|
|
21
|
+
*/
|
|
22
|
+
interface PaginationLabels {
|
|
23
|
+
/** Accessible name of the `<nav>` landmark. Give each one a distinct name if a page has several. */
|
|
24
|
+
navigation: string;
|
|
25
|
+
first: string;
|
|
26
|
+
previous: string;
|
|
27
|
+
next: string;
|
|
28
|
+
last: string;
|
|
29
|
+
/** Accessible name of a page button, e.g. "Page 3". */
|
|
30
|
+
page: (page: number) => string;
|
|
31
|
+
/** "Page 3 of 12": the compact strip on a phone, and the polite announcement after a change. */
|
|
32
|
+
status: (page: number, pageCount: number) => string;
|
|
33
|
+
}
|
|
34
|
+
interface PaginationProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange' | 'children'> {
|
|
35
|
+
/** The current page, 1-based. Out-of-range values are clamped for display. */
|
|
36
|
+
page: number;
|
|
37
|
+
/** How many pages there are in total. Renders nothing under 1. */
|
|
38
|
+
pageCount: number;
|
|
39
|
+
onPageChange: (page: number) => void;
|
|
40
|
+
/** Pages shown either side of the current one. */
|
|
41
|
+
siblingCount?: number;
|
|
42
|
+
/** Pages always shown at each end. */
|
|
43
|
+
boundaryCount?: number;
|
|
44
|
+
/** Button size. `lg` (48px) for touch-first screens. */
|
|
45
|
+
size?: 'sm' | 'md' | 'lg';
|
|
46
|
+
/** Also show first / last page buttons. */
|
|
47
|
+
showEdges?: boolean;
|
|
48
|
+
disabled?: boolean;
|
|
49
|
+
/** Override the English UI strings. */
|
|
50
|
+
labels?: Partial<PaginationLabels>;
|
|
51
|
+
}
|
|
52
|
+
declare function Pagination({ page: pageProp, pageCount: pageCountProp, onPageChange, siblingCount, boundaryCount, size, showEdges, disabled, labels: labelsProp, style, ...rest }: PaginationProps): React.JSX.Element | null;
|
|
53
|
+
|
|
54
|
+
export { Pagination, type PaginationLabels, type PaginationProps };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from "lucide-react";
|
|
5
|
+
import { sx } from "../_internal/style.js";
|
|
6
|
+
import { getPageItems } from "../_internal/pageRange.js";
|
|
7
|
+
import { IconButton } from "../core/IconButton.js";
|
|
8
|
+
const EN = {
|
|
9
|
+
navigation: "Pagination",
|
|
10
|
+
first: "First page",
|
|
11
|
+
previous: "Previous page",
|
|
12
|
+
next: "Next page",
|
|
13
|
+
last: "Last page",
|
|
14
|
+
page: (page) => `Page ${page}`,
|
|
15
|
+
status: (page, pageCount) => `Page ${page} of ${pageCount}`
|
|
16
|
+
};
|
|
17
|
+
const ICON = { sm: 16, md: 18, lg: 20 };
|
|
18
|
+
const BOX = { sm: 32, md: 40, lg: 48 };
|
|
19
|
+
const DIGITS = { sm: "var(--text-sm)", md: "var(--text-sm)", lg: "var(--text-base)" };
|
|
20
|
+
const SR_ONLY = {
|
|
21
|
+
position: "absolute",
|
|
22
|
+
width: 1,
|
|
23
|
+
height: 1,
|
|
24
|
+
padding: 0,
|
|
25
|
+
margin: -1,
|
|
26
|
+
overflow: "hidden",
|
|
27
|
+
clip: "rect(0 0 0 0)",
|
|
28
|
+
whiteSpace: "nowrap",
|
|
29
|
+
border: 0
|
|
30
|
+
};
|
|
31
|
+
function Pagination({
|
|
32
|
+
page: pageProp,
|
|
33
|
+
pageCount: pageCountProp,
|
|
34
|
+
onPageChange,
|
|
35
|
+
siblingCount = 1,
|
|
36
|
+
boundaryCount = 1,
|
|
37
|
+
size = "md",
|
|
38
|
+
showEdges = false,
|
|
39
|
+
disabled = false,
|
|
40
|
+
labels: labelsProp,
|
|
41
|
+
style,
|
|
42
|
+
...rest
|
|
43
|
+
}) {
|
|
44
|
+
const t = React.useMemo(() => ({ ...EN, ...labelsProp }), [labelsProp]);
|
|
45
|
+
const count = Number.isFinite(pageCountProp) ? Math.max(0, Math.floor(pageCountProp)) : 0;
|
|
46
|
+
if (count < 1) return null;
|
|
47
|
+
const page = Math.min(Math.max(Math.floor(pageProp) || 1, 1), count);
|
|
48
|
+
const go = (next) => {
|
|
49
|
+
if (disabled || next === page || next < 1 || next > count) return;
|
|
50
|
+
onPageChange(next);
|
|
51
|
+
};
|
|
52
|
+
const items = getPageItems(page, count, siblingCount, boundaryCount);
|
|
53
|
+
const icon = { size: ICON[size], strokeWidth: 1.75 };
|
|
54
|
+
return /* @__PURE__ */ jsxs("nav", { "aria-label": t.navigation, ...rest, style: sx({ position: "relative", ...style }), children: [
|
|
55
|
+
/* @__PURE__ */ jsxs(
|
|
56
|
+
"ul",
|
|
57
|
+
{
|
|
58
|
+
style: sx({
|
|
59
|
+
display: "flex",
|
|
60
|
+
alignItems: "center",
|
|
61
|
+
flexWrap: "wrap",
|
|
62
|
+
gap: "var(--space-1)",
|
|
63
|
+
listStyle: "none",
|
|
64
|
+
margin: 0,
|
|
65
|
+
padding: 0
|
|
66
|
+
}),
|
|
67
|
+
children: [
|
|
68
|
+
showEdges && /* @__PURE__ */ jsx("li", { className: "sereno-pagination-edge", children: /* @__PURE__ */ jsx(IconButton, { label: t.first, size, disabled: disabled || page <= 1, onClick: () => go(1), children: /* @__PURE__ */ jsx(ChevronsLeft, { ...icon }) }) }),
|
|
69
|
+
/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(IconButton, { label: t.previous, size, disabled: disabled || page <= 1, onClick: () => go(page - 1), children: /* @__PURE__ */ jsx(ChevronLeft, { ...icon }) }) }),
|
|
70
|
+
items.map(
|
|
71
|
+
(item) => typeof item === "number" ? /* @__PURE__ */ jsx("li", { className: "sereno-pagination-page", children: /* @__PURE__ */ jsx(
|
|
72
|
+
IconButton,
|
|
73
|
+
{
|
|
74
|
+
variant: item === page ? "primary" : "ghost",
|
|
75
|
+
size,
|
|
76
|
+
disabled,
|
|
77
|
+
label: t.page(item),
|
|
78
|
+
"aria-current": item === page ? "page" : void 0,
|
|
79
|
+
onClick: () => go(item),
|
|
80
|
+
children: /* @__PURE__ */ jsx(
|
|
81
|
+
"span",
|
|
82
|
+
{
|
|
83
|
+
style: sx({
|
|
84
|
+
fontFamily: "var(--font-body)",
|
|
85
|
+
fontSize: DIGITS[size],
|
|
86
|
+
fontWeight: item === page ? "var(--weight-semibold)" : "var(--weight-medium)",
|
|
87
|
+
fontVariantNumeric: "tabular-nums",
|
|
88
|
+
lineHeight: 1
|
|
89
|
+
}),
|
|
90
|
+
children: item
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
) }, item) : /* @__PURE__ */ jsx(
|
|
95
|
+
"li",
|
|
96
|
+
{
|
|
97
|
+
"aria-hidden": "true",
|
|
98
|
+
className: "sereno-pagination-ellipsis",
|
|
99
|
+
style: sx({ width: BOX[size], textAlign: "center", color: "var(--text-muted)", userSelect: "none" }),
|
|
100
|
+
children: "\u2026"
|
|
101
|
+
},
|
|
102
|
+
item
|
|
103
|
+
)
|
|
104
|
+
),
|
|
105
|
+
/* @__PURE__ */ jsx("li", { "aria-hidden": "true", className: "sereno-pagination-status", children: t.status(page, count) }),
|
|
106
|
+
/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(IconButton, { label: t.next, size, disabled: disabled || page >= count, onClick: () => go(page + 1), children: /* @__PURE__ */ jsx(ChevronRight, { ...icon }) }) }),
|
|
107
|
+
showEdges && /* @__PURE__ */ jsx("li", { className: "sereno-pagination-edge", children: /* @__PURE__ */ jsx(IconButton, { label: t.last, size, disabled: disabled || page >= count, onClick: () => go(count), children: /* @__PURE__ */ jsx(ChevronsRight, { ...icon }) }) })
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
),
|
|
111
|
+
/* @__PURE__ */ jsx("span", { role: "status", style: sx(SR_ONLY), children: t.status(page, count) })
|
|
112
|
+
] });
|
|
113
|
+
}
|
|
114
|
+
export {
|
|
115
|
+
Pagination
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=Pagination.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/navigation/Pagination.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { ChevronLeft, ChevronRight, ChevronsLeft, ChevronsRight } from 'lucide-react';\nimport { sx } from '../_internal/style';\nimport { getPageItems } from '../_internal/pageRange';\nimport { IconButton } from '../core/IconButton';\n\n/**\n * Page navigation for a long list or a `Table`: previous / next, a run of page numbers\n * with \"…\" where pages are folded away, and (optionally) first / last. A dedicated\n * control, not a `Table` feature. The table never paginates for you; you slice the rows\n * and pass the page in.\n *\n * ```tsx\n * const [page, setPage] = React.useState(1);\n * const pageSize = 10;\n *\n * <Table caption=\"Clients\">…{rows.slice((page - 1) * pageSize, page * pageSize)}…</Table>\n * <Pagination page={page} pageCount={Math.ceil(rows.length / pageSize)} onPageChange={setPage} />\n * ```\n *\n * **Controlled**: `page` is 1-based and lives in your state, next to the data fetching it\n * drives. A **config API**, not a compound one, since there's nothing a consumer would\n * author per page (same call as `Select`, see AGENTS.md). Under `--bp-sm` (560px) the\n * numbers fold away and it becomes previous / \"Page 3 of 12\" / next, so it fits a phone.\n */\nexport interface PaginationLabels {\n /** Accessible name of the `<nav>` landmark. Give each one a distinct name if a page has several. */\n navigation: string;\n first: string;\n previous: string;\n next: string;\n last: string;\n /** Accessible name of a page button, e.g. \"Page 3\". */\n page: (page: number) => string;\n /** \"Page 3 of 12\": the compact strip on a phone, and the polite announcement after a change. */\n status: (page: number, pageCount: number) => string;\n}\n\n/** English by default; pass `labels` for another locale (the DS embeds no localised copy). */\nconst EN: PaginationLabels = {\n navigation: 'Pagination',\n first: 'First page',\n previous: 'Previous page',\n next: 'Next page',\n last: 'Last page',\n page: (page) => `Page ${page}`,\n status: (page, pageCount) => `Page ${page} of ${pageCount}`,\n};\n\nexport interface PaginationProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange' | 'children'> {\n /** The current page, 1-based. Out-of-range values are clamped for display. */\n page: number;\n /** How many pages there are in total. Renders nothing under 1. */\n pageCount: number;\n onPageChange: (page: number) => void;\n /** Pages shown either side of the current one. */\n siblingCount?: number;\n /** Pages always shown at each end. */\n boundaryCount?: number;\n /** Button size. `lg` (48px) for touch-first screens. */\n size?: 'sm' | 'md' | 'lg';\n /** Also show first / last page buttons. */\n showEdges?: boolean;\n disabled?: boolean;\n /** Override the English UI strings. */\n labels?: Partial<PaginationLabels>;\n}\n\nconst ICON = { sm: 16, md: 18, lg: 20 } as const;\n/** `IconButton`'s own square sizes. The ellipsis is given the same width, so it takes exactly a page button's room. */\nconst BOX = { sm: 32, md: 40, lg: 48 } as const;\nconst DIGITS = { sm: 'var(--text-sm)', md: 'var(--text-sm)', lg: 'var(--text-base)' } as const;\n\n/** Visually hidden, still read by assistive tech (same idea as the Table's `<caption>`). */\nconst SR_ONLY = {\n position: 'absolute',\n width: 1,\n height: 1,\n padding: 0,\n margin: -1,\n overflow: 'hidden',\n clip: 'rect(0 0 0 0)',\n whiteSpace: 'nowrap',\n border: 0,\n} as const;\n\nexport function Pagination({\n page: pageProp,\n pageCount: pageCountProp,\n onPageChange,\n siblingCount = 1,\n boundaryCount = 1,\n size = 'md',\n showEdges = false,\n disabled = false,\n labels: labelsProp,\n style,\n ...rest\n}: PaginationProps) {\n const t = React.useMemo<PaginationLabels>(() => ({ ...EN, ...labelsProp }), [labelsProp]);\n\n // NaN / Infinity (say `Math.ceil(0 / 0)` from a zero page size) count as \"no pages\".\n const count = Number.isFinite(pageCountProp) ? Math.max(0, Math.floor(pageCountProp)) : 0;\n if (count < 1) return null;\n const page = Math.min(Math.max(Math.floor(pageProp) || 1, 1), count);\n\n const go = (next: number) => {\n if (disabled || next === page || next < 1 || next > count) return;\n onPageChange(next);\n };\n\n const items = getPageItems(page, count, siblingCount, boundaryCount);\n const icon = { size: ICON[size], strokeWidth: 1.75 } as const;\n\n return (\n <nav aria-label={t.navigation} {...rest} style={sx({ position: 'relative', ...style })}>\n <ul\n style={sx({\n display: 'flex',\n alignItems: 'center',\n flexWrap: 'wrap',\n gap: 'var(--space-1)',\n listStyle: 'none',\n margin: 0,\n padding: 0,\n })}\n >\n {showEdges && (\n <li className=\"sereno-pagination-edge\">\n <IconButton label={t.first} size={size} disabled={disabled || page <= 1} onClick={() => go(1)}>\n <ChevronsLeft {...icon} />\n </IconButton>\n </li>\n )}\n <li>\n <IconButton label={t.previous} size={size} disabled={disabled || page <= 1} onClick={() => go(page - 1)}>\n <ChevronLeft {...icon} />\n </IconButton>\n </li>\n\n {items.map((item) =>\n typeof item === 'number' ? (\n <li key={item} className=\"sereno-pagination-page\">\n {/* An `IconButton`, not a `Button`: a fixed square, so \"9\" and \"10\" take the same room\n and the control does not change width as you page. The number is just its content. */}\n <IconButton\n variant={item === page ? 'primary' : 'ghost'}\n size={size}\n disabled={disabled}\n label={t.page(item)}\n aria-current={item === page ? 'page' : undefined}\n onClick={() => go(item)}\n >\n <span\n style={sx({\n fontFamily: 'var(--font-body)',\n fontSize: DIGITS[size],\n fontWeight: item === page ? 'var(--weight-semibold)' : 'var(--weight-medium)',\n fontVariantNumeric: 'tabular-nums',\n lineHeight: 1,\n })}\n >\n {item}\n </span>\n </IconButton>\n </li>\n ) : (\n <li\n key={item}\n aria-hidden=\"true\"\n className=\"sereno-pagination-ellipsis\"\n style={sx({ width: BOX[size], textAlign: 'center', color: 'var(--text-muted)', userSelect: 'none' })}\n >\n …\n </li>\n ),\n )}\n\n {/* Phone-width stand-in for the numbers (shown by styles.css under --bp-sm). The\n announcement below is what assistive tech reads, so this one is hidden from it. */}\n <li aria-hidden=\"true\" className=\"sereno-pagination-status\">\n {t.status(page, count)}\n </li>\n\n <li>\n <IconButton label={t.next} size={size} disabled={disabled || page >= count} onClick={() => go(page + 1)}>\n <ChevronRight {...icon} />\n </IconButton>\n </li>\n {showEdges && (\n <li className=\"sereno-pagination-edge\">\n <IconButton label={t.last} size={size} disabled={disabled || page >= count} onClick={() => go(count)}>\n <ChevronsRight {...icon} />\n </IconButton>\n </li>\n )}\n </ul>\n\n {/* Announces the new page after a change. Without it a screen-reader user who presses\n \"Next\" hears nothing, since focus stays on the button and only the list changed. */}\n <span role=\"status\" style={sx(SR_ONLY)}>\n {t.status(page, count)}\n </span>\n </nav>\n );\n}\n"],"mappings":";AAsHM,SAcQ,KAdR;AApHN,YAAY,WAAW;AACvB,SAAS,aAAa,cAAc,cAAc,qBAAqB;AACvE,SAAS,UAAU;AACnB,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAmC3B,MAAM,KAAuB;AAAA,EAC3B,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,UAAU;AAAA,EACV,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM,CAAC,SAAS,QAAQ,IAAI;AAAA,EAC5B,QAAQ,CAAC,MAAM,cAAc,QAAQ,IAAI,OAAO,SAAS;AAC3D;AAqBA,MAAM,OAAO,EAAE,IAAI,IAAI,IAAI,IAAI,IAAI,GAAG;AAEtC,MAAM,MAAM,EAAE,IAAI,IAAI,IAAI,IAAI,IAAI,GAAG;AACrC,MAAM,SAAS,EAAE,IAAI,kBAAkB,IAAI,kBAAkB,IAAI,mBAAmB;AAGpF,MAAM,UAAU;AAAA,EACd,UAAU;AAAA,EACV,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA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,QAAG,WAAU,0BACZ,8BAAC,cAAW,OAAO,EAAE,MAAM,MAAY,UAAU,YAAY,QAAQ,OAAO,SAAS,MAAM,GAAG,KAAK,GACjG,8BAAC,iBAAe,GAAG,MAAM,GAC3B,GACF;AAAA;AAAA;AAAA,IAEJ;AAAA,IAIA,oBAAC,UAAK,MAAK,UAAS,OAAO,GAAG,OAAO,GAClC,YAAE,OAAO,MAAM,KAAK,GACvB;AAAA,KACF;AAEJ;","names":[]}
|
package/dist/styles.css
CHANGED
|
@@ -206,6 +206,27 @@
|
|
|
206
206
|
border-radius: var(--radius-sm);
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
+
/* ── Pagination ─────────────────────────────────────────────────────────────
|
|
210
|
+
The one thing an inline style can't do: fold the numbered pages away on a phone.
|
|
211
|
+
Under --bp-sm the page numbers, ellipses and first / last buttons hide and the
|
|
212
|
+
"Page X of Y" status shows between previous and next. 560px is --bp-sm written
|
|
213
|
+
out, since a media query can't read a custom property (Menu's PHONE_W is the same
|
|
214
|
+
number, and `@sereno-ds/tokens/breakpoints` exports it for JS). */
|
|
215
|
+
.sereno-pagination-status {
|
|
216
|
+
display: none;
|
|
217
|
+
padding: 0 var(--space-2);
|
|
218
|
+
font-family: var(--font-body);
|
|
219
|
+
font-size: var(--text-sm);
|
|
220
|
+
color: var(--text-secondary);
|
|
221
|
+
white-space: nowrap;
|
|
222
|
+
}
|
|
223
|
+
@media (max-width: 560px) {
|
|
224
|
+
.sereno-pagination-page,
|
|
225
|
+
.sereno-pagination-ellipsis,
|
|
226
|
+
.sereno-pagination-edge { display: none; }
|
|
227
|
+
.sereno-pagination-status { display: block; }
|
|
228
|
+
}
|
|
229
|
+
|
|
209
230
|
/* ── Dialog ────────────────────────────────────────────────────────────────
|
|
210
231
|
Header ✕ button — hover/focus states that can't be inline. */
|
|
211
232
|
.sereno-dialog-close:hover { background: var(--interactive-ghost-hover); color: var(--text-primary); }
|