@opengovsg/oui 0.0.0-snapshot-20250812083020 → 0.0.0-snapshot-20250813172831
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/cjs/badge/badge.cjs +4 -4
- package/dist/cjs/badge/use-badge.cjs +6 -6
- package/dist/cjs/banner/banner.cjs +3 -3
- package/dist/cjs/button/button.cjs +4 -4
- package/dist/cjs/calendar/calendar-bottom-content.cjs +2 -2
- package/dist/cjs/calendar/calendar-header.cjs +2 -2
- package/dist/cjs/calendar/calendar-month-day-selector.cjs +4 -4
- package/dist/cjs/calendar/calendar.cjs +4 -4
- package/dist/cjs/calendar/hooks/use-calendar-selectors.cjs +4 -4
- package/dist/cjs/calendar/utils.cjs +3 -3
- package/dist/cjs/checkbox/checkbox-group-style-context.cjs +16 -0
- package/dist/cjs/checkbox/checkbox.cjs +94 -0
- package/dist/cjs/checkbox/index.cjs +12 -0
- package/dist/cjs/combo-box/combo-box-fuzzy.cjs +6 -6
- package/dist/cjs/combo-box/combo-box-item.cjs +2 -2
- package/dist/cjs/combo-box/combo-box.cjs +4 -4
- package/dist/cjs/date-field/date-field.cjs +3 -3
- package/dist/cjs/date-picker/date-picker.cjs +3 -3
- package/dist/cjs/date-range-picker/date-range-picker.cjs +5 -5
- package/dist/cjs/govt-banner/govt-banner.cjs +3 -3
- package/dist/cjs/hooks/use-callback-ref.cjs +4 -4
- package/dist/cjs/hooks/use-controllable-state.cjs +2 -2
- package/dist/cjs/index.cjs +56 -39
- package/dist/cjs/input/input.cjs +2 -2
- package/dist/cjs/menu/menu.cjs +7 -7
- package/dist/cjs/node_modules/.pnpm/@react-aria_focus@3.20.5_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/focus/dist/useFocusRing.cjs +45 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/context.cjs +21 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/textSelection.cjs +72 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/useFocus.cjs +60 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/useFocusVisible.cjs +210 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/useFocusWithin.cjs +100 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/useHover.cjs +152 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/usePress.cjs +676 -0
- package/dist/cjs/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/utils.cjs +160 -0
- package/dist/cjs/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_check_private_redeclaration.cjs +9 -0
- package/dist/cjs/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_apply_descriptor_get.cjs +9 -0
- package/dist/cjs/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_apply_descriptor_set.cjs +16 -0
- package/dist/cjs/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_extract_field_descriptor.cjs +9 -0
- package/dist/cjs/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_private_field_get.cjs +11 -0
- package/dist/cjs/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_private_field_init.cjs +10 -0
- package/dist/cjs/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_private_field_set.cjs +12 -0
- package/dist/cjs/node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/Icon.cjs +4 -4
- package/dist/cjs/node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/createLucideIcon.cjs +3 -3
- package/dist/cjs/node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/chevrons-right.cjs +22 -0
- package/dist/cjs/node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/ellipsis.cjs +23 -0
- package/dist/cjs/node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/minus.cjs +19 -0
- package/dist/cjs/pagination/hooks/use-pagination.cjs +117 -0
- package/dist/cjs/pagination/index.cjs +17 -0
- package/dist/cjs/pagination/pagination-cursor.cjs +18 -0
- package/dist/cjs/pagination/pagination-item.cjs +18 -0
- package/dist/cjs/pagination/pagination.cjs +263 -0
- package/dist/cjs/pagination/use-pagination-item.cjs +87 -0
- package/dist/cjs/pagination/use-pagination.cjs +251 -0
- package/dist/cjs/range-calendar/range-calendar.cjs +6 -6
- package/dist/cjs/ripple/use-ripple.cjs +4 -4
- package/dist/cjs/select/select.cjs +3 -3
- package/dist/cjs/spinner/use-spinner.cjs +3 -3
- package/dist/cjs/system/react-utils/context.cjs +3 -3
- package/dist/cjs/system/react-utils/dom-props.cjs +186 -0
- package/dist/cjs/system/react-utils/filter-dom-props.cjs +46 -0
- package/dist/cjs/system/react-utils/index.cjs +2 -0
- package/dist/cjs/system/react-utils/refs.cjs +3 -3
- package/dist/cjs/system/utils.cjs +3 -3
- package/dist/cjs/tabs/tabs.cjs +2 -2
- package/dist/cjs/tag-field/tag-field-item.cjs +2 -2
- package/dist/cjs/tag-field/tag-field-list.cjs +4 -4
- package/dist/cjs/tag-field/tag-field-root.cjs +14 -14
- package/dist/cjs/tag-field/tag-field-state-context.cjs +2 -2
- package/dist/cjs/tag-field/tag-field-tag-list.cjs +3 -3
- package/dist/cjs/tag-field/tag-field-trigger.cjs +2 -2
- package/dist/cjs/tag-field/tag-field.cjs +4 -4
- package/dist/cjs/tag-field/use-tag-field-state.cjs +6 -6
- package/dist/cjs/tag-field/use-tag-field.cjs +4 -4
- package/dist/cjs/text-area/text-area.cjs +2 -2
- package/dist/cjs/toggle/toggle.cjs +3 -3
- package/dist/esm/button/button.js +1 -1
- package/dist/esm/calendar/calendar-month-day-selector.js +2 -2
- package/dist/esm/checkbox/checkbox-group-style-context.js +13 -0
- package/dist/esm/checkbox/checkbox.js +91 -0
- package/dist/esm/checkbox/index.js +3 -0
- package/dist/esm/combo-box/combo-box.js +1 -1
- package/dist/esm/date-picker/date-picker.js +1 -1
- package/dist/esm/date-range-picker/date-range-picker.js +2 -2
- package/dist/esm/index.js +19 -12
- package/dist/esm/menu/menu.js +1 -1
- package/dist/esm/node_modules/.pnpm/@react-aria_focus@3.20.5_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/focus/dist/useFocusRing.js +43 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/context.js +19 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/textSelection.js +69 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/useFocus.js +58 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/useFocusVisible.js +205 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/useFocusWithin.js +98 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/useHover.js +150 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/usePress.js +674 -0
- package/dist/esm/node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/utils.js +155 -0
- package/dist/esm/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_check_private_redeclaration.js +7 -0
- package/dist/esm/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_apply_descriptor_get.js +7 -0
- package/dist/esm/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_apply_descriptor_set.js +14 -0
- package/dist/esm/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_extract_field_descriptor.js +7 -0
- package/dist/esm/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_private_field_get.js +9 -0
- package/dist/esm/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_private_field_init.js +8 -0
- package/dist/esm/node_modules/.pnpm/@swc_helpers@0.5.17/node_modules/@swc/helpers/esm/_class_private_field_set.js +10 -0
- package/dist/esm/node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/chevrons-right.js +17 -0
- package/dist/esm/node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/ellipsis.js +18 -0
- package/dist/esm/node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/minus.js +14 -0
- package/dist/esm/pagination/hooks/use-pagination.js +114 -0
- package/dist/esm/pagination/index.js +6 -0
- package/dist/esm/pagination/pagination-cursor.js +16 -0
- package/dist/esm/pagination/pagination-item.js +16 -0
- package/dist/esm/pagination/pagination.js +261 -0
- package/dist/esm/pagination/use-pagination-item.js +85 -0
- package/dist/esm/pagination/use-pagination.js +248 -0
- package/dist/esm/select/select.js +1 -1
- package/dist/esm/system/react-utils/dom-props.js +183 -0
- package/dist/esm/system/react-utils/filter-dom-props.js +44 -0
- package/dist/esm/system/react-utils/index.js +1 -0
- package/dist/esm/tag-field/tag-field.js +2 -2
- package/dist/types/checkbox/checkbox-group-style-context.d.ts +6 -0
- package/dist/types/checkbox/checkbox-group-style-context.d.ts.map +1 -0
- package/dist/types/checkbox/checkbox.d.ts +19 -0
- package/dist/types/checkbox/checkbox.d.ts.map +1 -0
- package/dist/types/checkbox/index.d.ts +3 -0
- package/dist/types/checkbox/index.d.ts.map +1 -0
- package/dist/types/index.d.mts +2 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/pagination/hooks/use-pagination.d.ts +51 -0
- package/dist/types/pagination/hooks/use-pagination.d.ts.map +1 -0
- package/dist/types/pagination/index.d.ts +7 -0
- package/dist/types/pagination/index.d.ts.map +1 -0
- package/dist/types/pagination/pagination-cursor.d.ts +9 -0
- package/dist/types/pagination/pagination-cursor.d.ts.map +1 -0
- package/dist/types/pagination/pagination-item.d.ts +5 -0
- package/dist/types/pagination/pagination-item.d.ts.map +1 -0
- package/dist/types/pagination/pagination.d.ts +5 -0
- package/dist/types/pagination/pagination.d.ts.map +1 -0
- package/dist/types/pagination/use-pagination-item.d.ts +51 -0
- package/dist/types/pagination/use-pagination-item.d.ts.map +1 -0
- package/dist/types/pagination/use-pagination.d.ts +353 -0
- package/dist/types/pagination/use-pagination.d.ts.map +1 -0
- package/dist/types/system/react-utils/context.d.ts.map +1 -1
- package/dist/types/system/react-utils/dom-props.d.ts +3 -0
- package/dist/types/system/react-utils/dom-props.d.ts.map +1 -0
- package/dist/types/system/react-utils/filter-dom-props.d.ts +39 -0
- package/dist/types/system/react-utils/filter-dom-props.d.ts.map +1 -0
- package/dist/types/system/react-utils/index.d.ts +1 -0
- package/dist/types/system/react-utils/index.d.ts.map +1 -1
- package/package.json +8 -6
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
|
+
import { useCallback, createElement } from 'react';
|
|
5
|
+
import { useLocale } from '@react-aria/i18n';
|
|
6
|
+
import { cn, dataAttr } from '@opengovsg/oui-theme';
|
|
7
|
+
import { forwardRef } from '../system/utils.js';
|
|
8
|
+
import { PaginationItemType } from './hooks/use-pagination.js';
|
|
9
|
+
import { PaginationCursor } from './pagination-cursor.js';
|
|
10
|
+
import { PaginationItem } from './pagination-item.js';
|
|
11
|
+
import { usePagination } from './use-pagination.js';
|
|
12
|
+
import ChevronLeft from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/chevron-left.js';
|
|
13
|
+
import Ellipsis from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/ellipsis.js';
|
|
14
|
+
import ChevronsRight from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/chevrons-right.js';
|
|
15
|
+
|
|
16
|
+
const Pagination = forwardRef((props, ref) => {
|
|
17
|
+
const {
|
|
18
|
+
Component,
|
|
19
|
+
dotsJump,
|
|
20
|
+
slots,
|
|
21
|
+
classNames,
|
|
22
|
+
total,
|
|
23
|
+
range,
|
|
24
|
+
loop,
|
|
25
|
+
activePage,
|
|
26
|
+
disableCursorAnimation,
|
|
27
|
+
disableAnimation,
|
|
28
|
+
renderItem: renderItemProp,
|
|
29
|
+
onNext,
|
|
30
|
+
onPrevious,
|
|
31
|
+
setPage,
|
|
32
|
+
getItemAriaLabel,
|
|
33
|
+
getItemRef,
|
|
34
|
+
getBaseProps,
|
|
35
|
+
getWrapperProps,
|
|
36
|
+
getItemProps,
|
|
37
|
+
getCursorProps
|
|
38
|
+
} = usePagination({ ...props, ref });
|
|
39
|
+
const { direction } = useLocale();
|
|
40
|
+
const isRTL = direction === "rtl";
|
|
41
|
+
const renderChevronIcon = useCallback(
|
|
42
|
+
(key) => {
|
|
43
|
+
if (key === PaginationItemType.PREV && !isRTL || key === PaginationItemType.NEXT && isRTL) {
|
|
44
|
+
return /* @__PURE__ */ jsx(ChevronLeft, {});
|
|
45
|
+
}
|
|
46
|
+
return /* @__PURE__ */ jsx(
|
|
47
|
+
ChevronLeft,
|
|
48
|
+
{
|
|
49
|
+
className: slots.chevronNext({
|
|
50
|
+
class: classNames?.chevronNext
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
[isRTL, slots, classNames?.chevronNext]
|
|
56
|
+
);
|
|
57
|
+
const renderPrevItem = useCallback(() => {
|
|
58
|
+
return /* @__PURE__ */ jsx(
|
|
59
|
+
PaginationItem,
|
|
60
|
+
{
|
|
61
|
+
className: slots.prev({
|
|
62
|
+
class: classNames?.prev
|
|
63
|
+
}),
|
|
64
|
+
"data-slot": "prev",
|
|
65
|
+
getAriaLabel: getItemAriaLabel,
|
|
66
|
+
isDisabled: props.isDisabled || !loop && activePage === 1,
|
|
67
|
+
value: PaginationItemType.PREV,
|
|
68
|
+
onPress: onPrevious,
|
|
69
|
+
children: renderChevronIcon(PaginationItemType.PREV)
|
|
70
|
+
},
|
|
71
|
+
PaginationItemType.PREV
|
|
72
|
+
);
|
|
73
|
+
}, [
|
|
74
|
+
slots,
|
|
75
|
+
classNames?.prev,
|
|
76
|
+
getItemAriaLabel,
|
|
77
|
+
props.isDisabled,
|
|
78
|
+
loop,
|
|
79
|
+
activePage,
|
|
80
|
+
onPrevious,
|
|
81
|
+
renderChevronIcon
|
|
82
|
+
]);
|
|
83
|
+
const renderNextItem = useCallback(() => {
|
|
84
|
+
return /* @__PURE__ */ jsx(
|
|
85
|
+
PaginationItem,
|
|
86
|
+
{
|
|
87
|
+
className: slots.next({
|
|
88
|
+
class: cn(classNames?.next)
|
|
89
|
+
}),
|
|
90
|
+
"data-slot": "next",
|
|
91
|
+
getAriaLabel: getItemAriaLabel,
|
|
92
|
+
isDisabled: props.isDisabled || !loop && activePage === total,
|
|
93
|
+
value: PaginationItemType.NEXT,
|
|
94
|
+
onPress: onNext,
|
|
95
|
+
children: renderChevronIcon(PaginationItemType.NEXT)
|
|
96
|
+
},
|
|
97
|
+
PaginationItemType.NEXT
|
|
98
|
+
);
|
|
99
|
+
}, [
|
|
100
|
+
slots,
|
|
101
|
+
classNames?.next,
|
|
102
|
+
getItemAriaLabel,
|
|
103
|
+
props.isDisabled,
|
|
104
|
+
loop,
|
|
105
|
+
activePage,
|
|
106
|
+
total,
|
|
107
|
+
onNext,
|
|
108
|
+
renderChevronIcon
|
|
109
|
+
]);
|
|
110
|
+
const renderItem = useCallback(
|
|
111
|
+
(value, index) => {
|
|
112
|
+
const isBefore = index < range.indexOf(activePage);
|
|
113
|
+
if (renderItemProp && typeof renderItemProp === "function") {
|
|
114
|
+
let page = typeof value == "number" ? value : index;
|
|
115
|
+
if (value === PaginationItemType.NEXT) {
|
|
116
|
+
page = activePage + 1;
|
|
117
|
+
}
|
|
118
|
+
if (value === PaginationItemType.PREV) {
|
|
119
|
+
page = activePage - 1;
|
|
120
|
+
}
|
|
121
|
+
if (value === PaginationItemType.DOTS) {
|
|
122
|
+
page = isBefore ? activePage - dotsJump >= 1 ? activePage - dotsJump : 1 : activePage + dotsJump <= total ? activePage + dotsJump : total;
|
|
123
|
+
}
|
|
124
|
+
const itemChildren = {
|
|
125
|
+
[PaginationItemType.PREV]: renderChevronIcon(PaginationItemType.PREV),
|
|
126
|
+
[PaginationItemType.NEXT]: renderChevronIcon(PaginationItemType.NEXT),
|
|
127
|
+
[PaginationItemType.DOTS]: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
128
|
+
/* @__PURE__ */ jsx(
|
|
129
|
+
Ellipsis,
|
|
130
|
+
{
|
|
131
|
+
className: slots?.ellipsis({ class: classNames?.ellipsis })
|
|
132
|
+
}
|
|
133
|
+
),
|
|
134
|
+
/* @__PURE__ */ jsx(
|
|
135
|
+
ChevronsRight,
|
|
136
|
+
{
|
|
137
|
+
className: slots?.forwardIcon({
|
|
138
|
+
class: classNames?.forwardIcon
|
|
139
|
+
}),
|
|
140
|
+
"data-before": dataAttr(isBefore)
|
|
141
|
+
}
|
|
142
|
+
)
|
|
143
|
+
] })
|
|
144
|
+
};
|
|
145
|
+
return renderItemProp({
|
|
146
|
+
value,
|
|
147
|
+
index,
|
|
148
|
+
key: `${value}-${index}`,
|
|
149
|
+
page,
|
|
150
|
+
total,
|
|
151
|
+
children: typeof value === "number" ? value : itemChildren[value],
|
|
152
|
+
activePage,
|
|
153
|
+
dotsJump,
|
|
154
|
+
isBefore,
|
|
155
|
+
isActive: value === activePage,
|
|
156
|
+
isPrevious: value === activePage - 1,
|
|
157
|
+
isNext: value === activePage + 1,
|
|
158
|
+
isFirst: value === 1,
|
|
159
|
+
isLast: value === total,
|
|
160
|
+
onNext,
|
|
161
|
+
onPrevious,
|
|
162
|
+
setPage,
|
|
163
|
+
onPress: () => setPage(page),
|
|
164
|
+
ref: typeof value === "number" ? (node) => getItemRef(node, value) : void 0,
|
|
165
|
+
className: slots.item({ class: classNames?.item }),
|
|
166
|
+
getAriaLabel: getItemAriaLabel
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
if (value === PaginationItemType.PREV) {
|
|
170
|
+
return renderPrevItem();
|
|
171
|
+
}
|
|
172
|
+
if (value === PaginationItemType.NEXT) {
|
|
173
|
+
return renderNextItem();
|
|
174
|
+
}
|
|
175
|
+
if (value === PaginationItemType.DOTS) {
|
|
176
|
+
return /* @__PURE__ */ jsxs(
|
|
177
|
+
PaginationItem,
|
|
178
|
+
{
|
|
179
|
+
className: slots.item({
|
|
180
|
+
class: cn(classNames?.item, "group")
|
|
181
|
+
}),
|
|
182
|
+
isDisabled: props.isDisabled,
|
|
183
|
+
"data-slot": "item",
|
|
184
|
+
getAriaLabel: getItemAriaLabel,
|
|
185
|
+
value,
|
|
186
|
+
onPress: () => isBefore ? setPage(
|
|
187
|
+
activePage - dotsJump >= 1 ? activePage - dotsJump : 1
|
|
188
|
+
) : setPage(
|
|
189
|
+
activePage + dotsJump <= total ? activePage + dotsJump : total
|
|
190
|
+
),
|
|
191
|
+
children: [
|
|
192
|
+
/* @__PURE__ */ jsx(
|
|
193
|
+
Ellipsis,
|
|
194
|
+
{
|
|
195
|
+
className: slots?.ellipsis({ class: classNames?.ellipsis })
|
|
196
|
+
}
|
|
197
|
+
),
|
|
198
|
+
/* @__PURE__ */ jsx(
|
|
199
|
+
ChevronsRight,
|
|
200
|
+
{
|
|
201
|
+
className: slots?.forwardIcon({ class: classNames?.forwardIcon }),
|
|
202
|
+
"data-before": dataAttr(isRTL ? !isBefore : isBefore)
|
|
203
|
+
}
|
|
204
|
+
)
|
|
205
|
+
]
|
|
206
|
+
},
|
|
207
|
+
PaginationItemType.DOTS + isBefore
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
return /* @__PURE__ */ createElement(
|
|
211
|
+
PaginationItem,
|
|
212
|
+
{
|
|
213
|
+
...getItemProps({ value }),
|
|
214
|
+
key: value,
|
|
215
|
+
getAriaLabel: getItemAriaLabel
|
|
216
|
+
},
|
|
217
|
+
value
|
|
218
|
+
);
|
|
219
|
+
},
|
|
220
|
+
[
|
|
221
|
+
range,
|
|
222
|
+
activePage,
|
|
223
|
+
renderItemProp,
|
|
224
|
+
getItemProps,
|
|
225
|
+
getItemAriaLabel,
|
|
226
|
+
renderChevronIcon,
|
|
227
|
+
slots,
|
|
228
|
+
classNames?.ellipsis,
|
|
229
|
+
classNames?.forwardIcon,
|
|
230
|
+
classNames?.item,
|
|
231
|
+
total,
|
|
232
|
+
dotsJump,
|
|
233
|
+
onNext,
|
|
234
|
+
onPrevious,
|
|
235
|
+
setPage,
|
|
236
|
+
getItemRef,
|
|
237
|
+
renderPrevItem,
|
|
238
|
+
renderNextItem,
|
|
239
|
+
props.isDisabled,
|
|
240
|
+
isRTL
|
|
241
|
+
]
|
|
242
|
+
);
|
|
243
|
+
if (props.isCompact) {
|
|
244
|
+
return /* @__PURE__ */ jsx(Component, { ...getBaseProps(), children: /* @__PURE__ */ jsxs("ul", { ...getWrapperProps(), children: [
|
|
245
|
+
renderPrevItem(),
|
|
246
|
+
/* @__PURE__ */ jsxs("li", { className: slots.item({ class: classNames?.item }), children: [
|
|
247
|
+
"Page ",
|
|
248
|
+
activePage,
|
|
249
|
+
" of ",
|
|
250
|
+
total
|
|
251
|
+
] }),
|
|
252
|
+
renderNextItem()
|
|
253
|
+
] }) });
|
|
254
|
+
}
|
|
255
|
+
return /* @__PURE__ */ jsx(Component, { ...getBaseProps(), children: /* @__PURE__ */ jsxs("ul", { ...getWrapperProps(), children: [
|
|
256
|
+
!disableCursorAnimation && !disableAnimation && /* @__PURE__ */ jsx(PaginationCursor, { ...getCursorProps() }),
|
|
257
|
+
range.map(renderItem)
|
|
258
|
+
] }) });
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
export { Pagination };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { useFocusRing as $f7dceffc5ad7768b$export$4e328f61c538687f } from '../node_modules/.pnpm/@react-aria_focus@3.20.5_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/focus/dist/useFocusRing.js';
|
|
5
|
+
import { useRouter, mergeProps, chain, shouldClientNavigate } from '@react-aria/utils';
|
|
6
|
+
import { useHover as $6179b936705e76d3$export$ae780daf29e6d456 } from '../node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/useHover.js';
|
|
7
|
+
import { usePress as $f6c31cce2adf654f$export$45712eceda6fad21 } from '../node_modules/.pnpm/@react-aria_interactions@3.25.3_react-dom@19.0.0_react@19.0.0__react@19.0.0/node_modules/@react-aria/interactions/dist/usePress.js';
|
|
8
|
+
import { cn, dataAttr } from '@opengovsg/oui-theme';
|
|
9
|
+
import { filterDOMProps } from '../system/react-utils/filter-dom-props.js';
|
|
10
|
+
import { useDomRef } from '../system/react-utils/refs.js';
|
|
11
|
+
|
|
12
|
+
function usePaginationItem(props) {
|
|
13
|
+
const {
|
|
14
|
+
as,
|
|
15
|
+
ref,
|
|
16
|
+
value,
|
|
17
|
+
children,
|
|
18
|
+
isActive,
|
|
19
|
+
isDisabled,
|
|
20
|
+
onPress,
|
|
21
|
+
onClick,
|
|
22
|
+
getAriaLabel,
|
|
23
|
+
className,
|
|
24
|
+
...otherProps
|
|
25
|
+
} = props;
|
|
26
|
+
const isLink = !!props?.href;
|
|
27
|
+
const Component = as || isLink ? "a" : "li";
|
|
28
|
+
const shouldFilterDOMProps = typeof Component === "string";
|
|
29
|
+
const domRef = useDomRef(ref);
|
|
30
|
+
const router = useRouter();
|
|
31
|
+
const ariaLabel = useMemo(
|
|
32
|
+
() => isActive ? `${getAriaLabel?.(value)} active` : getAriaLabel?.(value),
|
|
33
|
+
[isActive, getAriaLabel, value]
|
|
34
|
+
);
|
|
35
|
+
const { isPressed, pressProps } = $f6c31cce2adf654f$export$45712eceda6fad21({
|
|
36
|
+
isDisabled,
|
|
37
|
+
onPress
|
|
38
|
+
});
|
|
39
|
+
const { focusProps, isFocused, isFocusVisible } = $f7dceffc5ad7768b$export$4e328f61c538687f({});
|
|
40
|
+
const { isHovered, hoverProps } = $6179b936705e76d3$export$ae780daf29e6d456({ isDisabled });
|
|
41
|
+
const getItemProps = (props2 = {}) => {
|
|
42
|
+
return {
|
|
43
|
+
ref: domRef,
|
|
44
|
+
role: "button",
|
|
45
|
+
tabIndex: isDisabled ? -1 : 0,
|
|
46
|
+
"aria-label": ariaLabel,
|
|
47
|
+
"aria-current": dataAttr(isActive),
|
|
48
|
+
"aria-disabled": dataAttr(isDisabled),
|
|
49
|
+
"data-disabled": dataAttr(isDisabled),
|
|
50
|
+
"data-active": dataAttr(isActive),
|
|
51
|
+
"data-focus": dataAttr(isFocused),
|
|
52
|
+
"data-hover": dataAttr(isHovered),
|
|
53
|
+
"data-pressed": dataAttr(isPressed),
|
|
54
|
+
"data-focus-visible": dataAttr(isFocusVisible),
|
|
55
|
+
...mergeProps(
|
|
56
|
+
props2,
|
|
57
|
+
pressProps,
|
|
58
|
+
focusProps,
|
|
59
|
+
hoverProps,
|
|
60
|
+
filterDOMProps(otherProps, {
|
|
61
|
+
enabled: shouldFilterDOMProps
|
|
62
|
+
})
|
|
63
|
+
),
|
|
64
|
+
className: cn(className, props2.className),
|
|
65
|
+
onClick: (e) => {
|
|
66
|
+
chain(pressProps?.onClick, onClick)(e);
|
|
67
|
+
if (!router.isNative && e.currentTarget instanceof HTMLAnchorElement && e.currentTarget.href && // If props are applied to a router Link component, it may have already prevented default.
|
|
68
|
+
!e.isDefaultPrevented() && shouldClientNavigate(e.currentTarget, e) && props2.href) {
|
|
69
|
+
e.preventDefault();
|
|
70
|
+
router.open(e.currentTarget, e, props2.href, props2.routerOptions);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
Component,
|
|
77
|
+
children,
|
|
78
|
+
ariaLabel,
|
|
79
|
+
isFocused,
|
|
80
|
+
isFocusVisible,
|
|
81
|
+
getItemProps
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { usePaginationItem };
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
import { useRef, useCallback, useEffect } from 'react';
|
|
4
|
+
import scrollIntoView from 'scroll-into-view-if-needed';
|
|
5
|
+
import { useDeepCompareMemo } from 'use-deep-compare';
|
|
6
|
+
import { useIntersectionObserver } from 'usehooks-ts';
|
|
7
|
+
import { paginationStyles, cn, dataAttr } from '@opengovsg/oui-theme';
|
|
8
|
+
import { mapPropsVariants } from '../system/utils.js';
|
|
9
|
+
import { usePagination as usePagination$1, PaginationItemType } from './hooks/use-pagination.js';
|
|
10
|
+
import { useDomRef } from '../system/react-utils/refs.js';
|
|
11
|
+
|
|
12
|
+
const CURSOR_TRANSITION_TIMEOUT = 300;
|
|
13
|
+
function usePagination(originalProps) {
|
|
14
|
+
const [props, variantProps] = mapPropsVariants(
|
|
15
|
+
originalProps,
|
|
16
|
+
paginationStyles.variantKeys
|
|
17
|
+
);
|
|
18
|
+
const {
|
|
19
|
+
as,
|
|
20
|
+
ref,
|
|
21
|
+
classNames,
|
|
22
|
+
dotsJump = 5,
|
|
23
|
+
loop = false,
|
|
24
|
+
showControls = false,
|
|
25
|
+
total = 1,
|
|
26
|
+
initialPage = 1,
|
|
27
|
+
page,
|
|
28
|
+
siblings,
|
|
29
|
+
boundaries,
|
|
30
|
+
onChange,
|
|
31
|
+
className,
|
|
32
|
+
renderItem,
|
|
33
|
+
getItemAriaLabel: getItemAriaLabelProp,
|
|
34
|
+
...otherProps
|
|
35
|
+
} = props;
|
|
36
|
+
const Component = as || "nav";
|
|
37
|
+
const domRef = useDomRef(ref);
|
|
38
|
+
const cursorRef = useRef(null);
|
|
39
|
+
const itemsRef = useRef(null);
|
|
40
|
+
const cursorTimer = useRef(null);
|
|
41
|
+
const disableAnimation = originalProps?.disableAnimation ?? false;
|
|
42
|
+
const disableCursorAnimation = originalProps?.disableCursorAnimation ?? disableAnimation ?? false;
|
|
43
|
+
function getItemsRefMap() {
|
|
44
|
+
if (!itemsRef.current) {
|
|
45
|
+
itemsRef.current = /* @__PURE__ */ new Map();
|
|
46
|
+
}
|
|
47
|
+
return itemsRef.current;
|
|
48
|
+
}
|
|
49
|
+
function getItemRef(node, value) {
|
|
50
|
+
const map = getItemsRefMap();
|
|
51
|
+
if (node) {
|
|
52
|
+
map.set(value, node);
|
|
53
|
+
} else {
|
|
54
|
+
map.delete(value);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const scrollTo = useCallback(
|
|
58
|
+
(value, skipAnimation) => {
|
|
59
|
+
const map = getItemsRefMap();
|
|
60
|
+
const node = map.get(value);
|
|
61
|
+
if (!node || !cursorRef.current) return;
|
|
62
|
+
if (cursorTimer.current) {
|
|
63
|
+
clearTimeout(cursorTimer.current);
|
|
64
|
+
}
|
|
65
|
+
scrollIntoView(node, {
|
|
66
|
+
scrollMode: "always",
|
|
67
|
+
behavior: "smooth",
|
|
68
|
+
block: "start",
|
|
69
|
+
inline: "start",
|
|
70
|
+
boundary: domRef.current
|
|
71
|
+
});
|
|
72
|
+
const { offsetLeft } = node;
|
|
73
|
+
if (skipAnimation) {
|
|
74
|
+
cursorRef.current.setAttribute("data-moving", "false");
|
|
75
|
+
cursorRef.current.style.transform = `translateX(${offsetLeft}px) scale(1)`;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
cursorRef.current.setAttribute("data-moving", "true");
|
|
79
|
+
cursorRef.current.style.transform = `translateX(${offsetLeft}px) scale(1.1)`;
|
|
80
|
+
cursorTimer.current = setTimeout(() => {
|
|
81
|
+
if (cursorRef.current) {
|
|
82
|
+
cursorRef.current.style.transform = `translateX(${offsetLeft}px) scale(1)`;
|
|
83
|
+
}
|
|
84
|
+
cursorTimer.current = setTimeout(() => {
|
|
85
|
+
cursorRef.current?.setAttribute("data-moving", "false");
|
|
86
|
+
if (cursorTimer.current) {
|
|
87
|
+
clearTimeout(cursorTimer.current);
|
|
88
|
+
}
|
|
89
|
+
}, CURSOR_TRANSITION_TIMEOUT);
|
|
90
|
+
}, CURSOR_TRANSITION_TIMEOUT);
|
|
91
|
+
},
|
|
92
|
+
[domRef]
|
|
93
|
+
);
|
|
94
|
+
const { range, activePage, setPage, previous, next, first, last } = usePagination$1({
|
|
95
|
+
page,
|
|
96
|
+
total,
|
|
97
|
+
initialPage,
|
|
98
|
+
siblings,
|
|
99
|
+
boundaries,
|
|
100
|
+
showControls,
|
|
101
|
+
onChange
|
|
102
|
+
});
|
|
103
|
+
const [setRef, isVisible] = useIntersectionObserver();
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (domRef.current) {
|
|
106
|
+
setRef(domRef.current);
|
|
107
|
+
}
|
|
108
|
+
}, [domRef, setRef]);
|
|
109
|
+
const activePageRef = useRef(activePage);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (activePage && !disableAnimation && isVisible) {
|
|
112
|
+
scrollTo(activePage, activePage === activePageRef.current);
|
|
113
|
+
}
|
|
114
|
+
activePageRef.current = activePage;
|
|
115
|
+
}, [
|
|
116
|
+
page,
|
|
117
|
+
activePage,
|
|
118
|
+
disableAnimation,
|
|
119
|
+
disableCursorAnimation,
|
|
120
|
+
isVisible,
|
|
121
|
+
originalProps.dotsJump,
|
|
122
|
+
originalProps.isCompact,
|
|
123
|
+
originalProps.showControls,
|
|
124
|
+
scrollTo
|
|
125
|
+
]);
|
|
126
|
+
const slots = useDeepCompareMemo(
|
|
127
|
+
() => paginationStyles({
|
|
128
|
+
...variantProps,
|
|
129
|
+
disableAnimation,
|
|
130
|
+
disableCursorAnimation
|
|
131
|
+
}),
|
|
132
|
+
[variantProps, disableCursorAnimation, disableAnimation]
|
|
133
|
+
);
|
|
134
|
+
const baseStyles = cn(classNames?.base, className);
|
|
135
|
+
const onNext = () => {
|
|
136
|
+
if (loop && activePage === total) {
|
|
137
|
+
return first();
|
|
138
|
+
}
|
|
139
|
+
return next();
|
|
140
|
+
};
|
|
141
|
+
const onPrevious = () => {
|
|
142
|
+
if (loop && activePage === 1) {
|
|
143
|
+
return last();
|
|
144
|
+
}
|
|
145
|
+
return previous();
|
|
146
|
+
};
|
|
147
|
+
const getBaseProps = (props2 = {}) => {
|
|
148
|
+
return {
|
|
149
|
+
ref: domRef,
|
|
150
|
+
role: "navigation",
|
|
151
|
+
"aria-label": props2["aria-label"] || "pagination navigation",
|
|
152
|
+
"data-slot": "base",
|
|
153
|
+
"data-controls": dataAttr(showControls),
|
|
154
|
+
"data-loop": dataAttr(loop),
|
|
155
|
+
"data-dots-jump": dotsJump,
|
|
156
|
+
"data-total": total,
|
|
157
|
+
"data-active-page": activePage,
|
|
158
|
+
className: slots.base({ class: cn(baseStyles, props2?.className) }),
|
|
159
|
+
...otherProps,
|
|
160
|
+
...props2
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
const getWrapperProps = (props2 = {}) => {
|
|
164
|
+
return {
|
|
165
|
+
"data-slot": "wrapper",
|
|
166
|
+
"data-disabled": dataAttr(variantProps.isDisabled),
|
|
167
|
+
role: "none",
|
|
168
|
+
className: slots.wrapper({
|
|
169
|
+
class: cn(classNames?.wrapper, props2?.className)
|
|
170
|
+
}),
|
|
171
|
+
...props2
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
const getItemAriaLabel = (page2) => {
|
|
175
|
+
if (!page2) return;
|
|
176
|
+
if (getItemAriaLabelProp) {
|
|
177
|
+
return getItemAriaLabelProp(page2);
|
|
178
|
+
}
|
|
179
|
+
switch (page2) {
|
|
180
|
+
case PaginationItemType.DOTS:
|
|
181
|
+
return "dots element";
|
|
182
|
+
case PaginationItemType.PREV:
|
|
183
|
+
return "previous page button";
|
|
184
|
+
case PaginationItemType.NEXT:
|
|
185
|
+
return "next page button";
|
|
186
|
+
case "first":
|
|
187
|
+
return "first page button";
|
|
188
|
+
case "last":
|
|
189
|
+
return "last page button";
|
|
190
|
+
default:
|
|
191
|
+
return `pagination item ${page2}`;
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
const getItemProps = (props2 = {}) => {
|
|
195
|
+
return {
|
|
196
|
+
ref: (node) => getItemRef(node, props2.value),
|
|
197
|
+
"aria-disabled": dataAttr(variantProps.isDisabled),
|
|
198
|
+
"data-disabled": dataAttr(variantProps.isDisabled),
|
|
199
|
+
"data-slot": "item",
|
|
200
|
+
isActive: props2.value === activePage,
|
|
201
|
+
className: slots.item({
|
|
202
|
+
class: cn(classNames?.item, props2?.className)
|
|
203
|
+
}),
|
|
204
|
+
onPress: () => {
|
|
205
|
+
if (props2.value !== activePage) {
|
|
206
|
+
setPage(props2.value);
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
...props2
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
const getCursorProps = (props2 = {}) => {
|
|
213
|
+
return {
|
|
214
|
+
ref: cursorRef,
|
|
215
|
+
activePage,
|
|
216
|
+
"data-slot": "cursor",
|
|
217
|
+
className: slots.cursor({
|
|
218
|
+
class: cn(classNames?.cursor, props2?.className)
|
|
219
|
+
}),
|
|
220
|
+
...props2
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
return {
|
|
224
|
+
Component,
|
|
225
|
+
showControls,
|
|
226
|
+
dotsJump,
|
|
227
|
+
slots,
|
|
228
|
+
classNames,
|
|
229
|
+
loop,
|
|
230
|
+
total,
|
|
231
|
+
range,
|
|
232
|
+
activePage,
|
|
233
|
+
getItemRef,
|
|
234
|
+
disableAnimation,
|
|
235
|
+
disableCursorAnimation,
|
|
236
|
+
setPage,
|
|
237
|
+
onPrevious,
|
|
238
|
+
onNext,
|
|
239
|
+
renderItem,
|
|
240
|
+
getBaseProps,
|
|
241
|
+
getWrapperProps,
|
|
242
|
+
getItemProps,
|
|
243
|
+
getCursorProps,
|
|
244
|
+
getItemAriaLabel
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export { CURSOR_TRANSITION_TIMEOUT, usePagination };
|
|
@@ -4,11 +4,11 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
4
4
|
import { useMemo } from 'react';
|
|
5
5
|
import { Provider, Select as Select$1, SelectValue, Virtualizer, ListLayout, ListBox } from 'react-aria-components';
|
|
6
6
|
import { selectStyles, composeRenderProps } from '@opengovsg/oui-theme';
|
|
7
|
-
import { Popover } from '../popover/popover.js';
|
|
8
7
|
import { mapPropsVariants } from '../system/utils.js';
|
|
9
8
|
import { SelectVariantContext } from './select-variant-context.js';
|
|
10
9
|
import { Label, Description, FieldError } from '../field/field.js';
|
|
11
10
|
import ChevronDown from '../node_modules/.pnpm/lucide-react@0.475.0_react@19.0.0/node_modules/lucide-react/dist/esm/icons/chevron-down.js';
|
|
11
|
+
import { Popover } from '../popover/popover.js';
|
|
12
12
|
import { Button } from '../button/button.js';
|
|
13
13
|
|
|
14
14
|
const calculateEstimatedRowHeight = (size) => {
|