@pingux/astro 2.119.0-alpha.2 → 2.119.0-alpha.4

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.
Files changed (67) hide show
  1. package/lib/cjs/components/Button/Buttons.styles.d.ts +40 -0
  2. package/lib/cjs/components/Button/Buttons.styles.js +4 -0
  3. package/lib/cjs/components/ListView/ListView.stories.d.ts +3 -0
  4. package/lib/cjs/components/ListView/ListView.stories.js +2 -1
  5. package/lib/cjs/components/Pagination/Pagination.d.ts +4 -0
  6. package/lib/cjs/components/Pagination/Pagination.js +78 -0
  7. package/lib/cjs/components/Pagination/Pagination.mdx +68 -0
  8. package/lib/cjs/components/Pagination/Pagination.stories.d.ts +39 -0
  9. package/lib/cjs/components/Pagination/Pagination.stories.js +159 -0
  10. package/lib/cjs/components/Pagination/Pagination.styles.d.ts +17 -0
  11. package/lib/cjs/components/Pagination/Pagination.styles.js +27 -0
  12. package/lib/cjs/components/Pagination/Pagination.test.d.ts +1 -0
  13. package/lib/cjs/components/Pagination/Pagination.test.js +208 -0
  14. package/lib/cjs/components/Pagination/PaginationProvider.d.ts +4 -0
  15. package/lib/cjs/components/Pagination/PaginationProvider.js +38 -0
  16. package/lib/cjs/components/Pagination/index.d.ts +2 -0
  17. package/lib/cjs/components/Pagination/index.js +33 -0
  18. package/lib/cjs/context/PaginationContext/index.d.ts +10 -0
  19. package/lib/cjs/context/PaginationContext/index.js +20 -0
  20. package/lib/cjs/fonts.d.ts +2 -0
  21. package/lib/cjs/fonts.js +11 -0
  22. package/lib/cjs/hooks/index.d.ts +2 -0
  23. package/lib/cjs/hooks/index.js +14 -0
  24. package/lib/cjs/hooks/usePagination/index.d.ts +1 -0
  25. package/lib/cjs/hooks/usePagination/index.js +14 -0
  26. package/lib/cjs/hooks/usePagination/usePagination.d.ts +682 -0
  27. package/lib/cjs/hooks/usePagination/usePagination.js +178 -0
  28. package/lib/cjs/hooks/usePaginationState/index.d.ts +1 -0
  29. package/lib/cjs/hooks/usePaginationState/index.js +14 -0
  30. package/lib/cjs/hooks/usePaginationState/usePaginationState.d.ts +4 -0
  31. package/lib/cjs/hooks/usePaginationState/usePaginationState.js +18 -0
  32. package/lib/cjs/index.d.ts +3 -0
  33. package/lib/cjs/index.js +24 -0
  34. package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/buttons.d.ts +3 -0
  35. package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/buttons.js +3 -0
  36. package/lib/cjs/styles/themes/next-gen/convertedComponentList.js +1 -1
  37. package/lib/cjs/styles/themes/next-gen/next-gen.d.ts +17 -0
  38. package/lib/cjs/styles/themes/next-gen/variants/button.d.ts +17 -0
  39. package/lib/cjs/styles/themes/next-gen/variants/button.js +7 -1
  40. package/lib/cjs/styles/variants/variants.js +3 -1
  41. package/lib/cjs/types/pagination.d.ts +46 -0
  42. package/lib/cjs/types/pagination.js +6 -0
  43. package/lib/components/Button/Buttons.styles.js +4 -0
  44. package/lib/components/ListView/ListView.stories.js +1 -1
  45. package/lib/components/Pagination/Pagination.js +64 -0
  46. package/lib/components/Pagination/Pagination.mdx +68 -0
  47. package/lib/components/Pagination/Pagination.stories.js +141 -0
  48. package/lib/components/Pagination/Pagination.styles.js +19 -0
  49. package/lib/components/Pagination/Pagination.test.js +205 -0
  50. package/lib/components/Pagination/PaginationProvider.js +24 -0
  51. package/lib/components/Pagination/index.js +2 -0
  52. package/lib/context/PaginationContext/index.js +11 -0
  53. package/lib/fonts.js +2 -0
  54. package/lib/hooks/index.js +2 -0
  55. package/lib/hooks/usePagination/index.js +1 -0
  56. package/lib/hooks/usePagination/usePagination.js +170 -0
  57. package/lib/hooks/usePaginationState/index.js +1 -0
  58. package/lib/hooks/usePaginationState/usePaginationState.js +10 -0
  59. package/lib/index.js +3 -0
  60. package/lib/styles/themeOverrides/nextGenDarkMode/variants/buttons.js +3 -0
  61. package/lib/styles/themes/next-gen/convertedComponentList.js +1 -1
  62. package/lib/styles/themes/next-gen/variants/button.js +7 -1
  63. package/lib/styles/variants/variants.js +3 -1
  64. package/lib/types/pagination.js +1 -0
  65. package/package.json +1 -1
  66. package/lib/cjs/fonts.jsx +0 -137
  67. package/lib/fonts.jsx +0 -137
@@ -0,0 +1,141 @@
1
+ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
2
+ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
3
+ import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
4
+ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
5
+ import React, { useState } from 'react';
6
+ import FormSelectIcon from '@pingux/mdi-react/FormSelectIcon';
7
+ import usePaginationState from '../../hooks/usePaginationState';
8
+ import { Box, Button, Item, ListView, ListViewItem, Pagination, PaginationProvider, ScrollBox } from '../../index';
9
+ import { animals } from '../ListView/ListView.stories';
10
+ import PaginationReadme from './Pagination.mdx';
11
+ import { jsx as ___EmotionJSX } from "@emotion/react";
12
+ export default {
13
+ title: 'Components/Pagination',
14
+ component: Pagination,
15
+ parameters: {
16
+ docs: {
17
+ page: function page() {
18
+ return ___EmotionJSX(PaginationReadme, null);
19
+ }
20
+ }
21
+ },
22
+ argTypes: {
23
+ totalCount: {
24
+ control: {
25
+ type: 'number'
26
+ }
27
+ },
28
+ currentPageIndex: {
29
+ control: {
30
+ type: 'number'
31
+ }
32
+ },
33
+ offsetCount: {
34
+ control: {
35
+ type: 'number'
36
+ }
37
+ },
38
+ offsetOptions: {
39
+ control: {
40
+ type: 'array'
41
+ }
42
+ },
43
+ onPageIndexChange: {},
44
+ onOffsetCountChange: {}
45
+ }
46
+ };
47
+ var ExampleComponent = function ExampleComponent() {
48
+ var _context;
49
+ var _usePaginationState = usePaginationState(),
50
+ paginationState = _usePaginationState.paginationState;
51
+ return ___EmotionJSX(ScrollBox, {
52
+ maxHeight: "400px"
53
+ }, ___EmotionJSX(ListView, {
54
+ items: _mapInstanceProperty(_context = _sliceInstanceProperty(animals).call(animals, paginationState.firstRenderedIndex, paginationState.lastRenderedIndex + 1)).call(_context, function (_item) {
55
+ return {
56
+ name: _item.name,
57
+ key: _item.name,
58
+ id: _item.name
59
+ };
60
+ })
61
+ }, function (item) {
62
+ return ___EmotionJSX(Item, {
63
+ key: item.name
64
+ }, ___EmotionJSX(ListViewItem, {
65
+ data: {
66
+ text: item.name,
67
+ icon: FormSelectIcon
68
+ },
69
+ iconProps: {
70
+ color: 'text.secondary'
71
+ }
72
+ }));
73
+ }));
74
+ };
75
+ export var Default = function Default(args) {
76
+ return ___EmotionJSX(Box, {
77
+ sx: {
78
+ maxWidth: '350px',
79
+ gap: 'sm'
80
+ }
81
+ }, ___EmotionJSX(Pagination, _extends({
82
+ totalCount: 250
83
+ }, args)));
84
+ };
85
+ export var WithListView = function WithListView() {
86
+ return ___EmotionJSX(PaginationProvider, null, ___EmotionJSX(Box, {
87
+ gap: "sm"
88
+ }, ___EmotionJSX(ExampleComponent, null), ___EmotionJSX(Pagination, {
89
+ totalCount: animals.length
90
+ })));
91
+ };
92
+ export var Controlled = function Controlled() {
93
+ var _useState = useState(24),
94
+ _useState2 = _slicedToArray(_useState, 2),
95
+ index = _useState2[0],
96
+ setIndex = _useState2[1];
97
+ var _useState3 = useState(10),
98
+ _useState4 = _slicedToArray(_useState3, 2),
99
+ offsetCount = _useState4[0],
100
+ setOffsetCount = _useState4[1];
101
+ return ___EmotionJSX(Box, {
102
+ sx: {
103
+ maxWidth: '350px',
104
+ gap: 'sm'
105
+ }
106
+ }, ___EmotionJSX(Button, {
107
+ onPress: function onPress() {
108
+ return setIndex(0);
109
+ }
110
+ }, "Reset Index"), ___EmotionJSX(Pagination, {
111
+ totalCount: 250,
112
+ currentPageIndex: index,
113
+ offsetCount: offsetCount,
114
+ onOffsetCountChange: setOffsetCount,
115
+ onPageIndexChange: function onPageIndexChange(i) {
116
+ setIndex(i);
117
+ }
118
+ }));
119
+ };
120
+ export var CustomOptions = function CustomOptions() {
121
+ var _useState5 = useState(24),
122
+ _useState6 = _slicedToArray(_useState5, 2),
123
+ index = _useState6[0],
124
+ setIndex = _useState6[1];
125
+ var testFunc = function testFunc(key) {
126
+ setIndex(key);
127
+ };
128
+ return ___EmotionJSX(Box, {
129
+ sx: {
130
+ maxWidth: '350px',
131
+ gap: 'sm'
132
+ }
133
+ }, ___EmotionJSX(Pagination, {
134
+ totalCount: 250,
135
+ currentPageIndex: index,
136
+ offsetOptions: [10, 15, 25, 50, 100],
137
+ onPageIndexChange: function onPageIndexChange(key) {
138
+ testFunc(key);
139
+ }
140
+ }));
141
+ };
@@ -0,0 +1,19 @@
1
+ var container = {
2
+ alignItems: 'center',
3
+ minWidth: '100%',
4
+ "with": '100%',
5
+ ml: 'auto',
6
+ flexGrow: 1
7
+ };
8
+ var iconWrapper = {
9
+ ml: 'md'
10
+ };
11
+ var wrapper = {
12
+ ml: 'auto',
13
+ alignItems: 'center'
14
+ };
15
+ export default {
16
+ container: container,
17
+ iconWrapper: iconWrapper,
18
+ wrapper: wrapper
19
+ };
@@ -0,0 +1,205 @@
1
+ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
+ import React from 'react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { usePaginationState } from '../../hooks';
5
+ import { Box, Text } from '../../index';
6
+ import { act, fireEvent, render, screen } from '../../utils/testUtils/testWrapper';
7
+ import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
8
+ import Pagination from './Pagination';
9
+ import PaginationProvider from './PaginationProvider';
10
+ import { jsx as ___EmotionJSX } from "@emotion/react";
11
+ var initialString = '1-10 of 250';
12
+ var mockState = {
13
+ setOffsetCount: jest.fn()
14
+ };
15
+ var changeFunction = jest.fn();
16
+ var offsetChangeFunc = jest.fn();
17
+ var nextButtonId = 'next-button';
18
+ var prevButtonId = 'prev-button';
19
+ var menuId = 'menu-id';
20
+ var offsetButtonId = 'menu-button';
21
+ var defaultProps = {
22
+ state: mockState,
23
+ onPageIndexChange: changeFunction,
24
+ containerProps: {},
25
+ totalCount: 250,
26
+ onOffsetCountChange: offsetChangeFunc,
27
+ nextButtonProps: {
28
+ 'data-testid': nextButtonId
29
+ },
30
+ previousButtonProps: {
31
+ 'data-testid': prevButtonId
32
+ },
33
+ offsetMenuProps: {
34
+ 'data-testid': menuId,
35
+ buttonProps: {
36
+ 'data-testid': offsetButtonId
37
+ }
38
+ }
39
+ };
40
+ universalComponentTests({
41
+ renderComponent: function renderComponent(props) {
42
+ return ___EmotionJSX(Pagination, _extends({}, props, defaultProps));
43
+ }
44
+ });
45
+ var ExampleComponent = function ExampleComponent() {
46
+ var _usePaginationState = usePaginationState(),
47
+ paginationState = _usePaginationState.paginationState;
48
+ return ___EmotionJSX(Box, null, ___EmotionJSX(Text, null, "Current Page Index:", ' ', paginationState.currentPageIndex), ___EmotionJSX(Text, null, "First Rendered Index:", ' ', paginationState.firstRenderedIndex), ___EmotionJSX(Text, null, "Last Rendered Index:", ' ', paginationState.lastRenderedIndex));
49
+ };
50
+ var CustomComponents = function CustomComponents() {
51
+ return ___EmotionJSX(PaginationProvider, null, ___EmotionJSX(Pagination, defaultProps), ___EmotionJSX(ExampleComponent, null));
52
+ };
53
+ describe('Pagination Component', function () {
54
+ var getComponent = function getComponent() {
55
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
56
+ return render(___EmotionJSX(Pagination, _extends({}, defaultProps, props)));
57
+ };
58
+ afterEach(function () {
59
+ jest.clearAllMocks();
60
+ offsetChangeFunc.mockClear();
61
+ changeFunction.mockClear();
62
+ });
63
+ it('should render without crashing', function () {
64
+ getComponent();
65
+ expect(screen.getByText(initialString)).toBeInTheDocument();
66
+ });
67
+ it('should call setOffsetCount when a menu item is selected', function () {
68
+ getComponent();
69
+ var popoverButton = screen.getByText(initialString);
70
+ fireEvent.click(popoverButton);
71
+ var menuItem = screen.getByText('Show 25 Results');
72
+ fireEvent.click(menuItem);
73
+ expect(offsetChangeFunc).toHaveBeenCalledWith(25);
74
+ });
75
+ it('should call setOffsetCount when a menu item is selected, but custom props', function () {
76
+ getComponent({
77
+ offsetOptions: [5, 51, 100]
78
+ });
79
+ var popoverButton = screen.getByText(initialString);
80
+ fireEvent.click(popoverButton);
81
+ var menuItem = screen.getByText('Show 51 Results');
82
+ fireEvent.click(menuItem);
83
+ expect(offsetChangeFunc).toHaveBeenCalledWith(51);
84
+ });
85
+ it('should call previousButtonProps.onClick when previous button is clicked', function () {
86
+ getComponent();
87
+ var previousButton = screen.getByTestId(prevButtonId);
88
+ fireEvent.click(previousButton);
89
+ expect(changeFunction).not.toHaveBeenCalled();
90
+ });
91
+ it('should call nextButtonProps.onClick when next button is clicked', function () {
92
+ getComponent();
93
+ var nextButton = screen.getByTestId(nextButtonId);
94
+ expect(changeFunction).not.toHaveBeenCalled();
95
+ act(function () {
96
+ userEvent.click(nextButton);
97
+ });
98
+ expect(changeFunction).toHaveBeenCalledTimes(1);
99
+ });
100
+ it('should not call change function when prev button is clicked, on first page', function () {
101
+ getComponent();
102
+ var previousButton = screen.getByTestId(prevButtonId);
103
+ expect(changeFunction).not.toHaveBeenCalled();
104
+ act(function () {
105
+ userEvent.click(previousButton);
106
+ });
107
+ expect(changeFunction).not.toHaveBeenCalled();
108
+ });
109
+ it('should not call change function when next button is clicked, on last page', function () {
110
+ getComponent({
111
+ currentPageIndex: 24
112
+ });
113
+ var nextButton = screen.getByTestId(nextButtonId);
114
+ expect(changeFunction).not.toHaveBeenCalled();
115
+ act(function () {
116
+ userEvent.click(nextButton);
117
+ });
118
+ expect(changeFunction).not.toHaveBeenCalled();
119
+ });
120
+ it('should call change function when prev button is clicked', function () {
121
+ getComponent({
122
+ currentPageIndex: 24
123
+ });
124
+ var previousButton = screen.getByTestId(prevButtonId);
125
+ expect(changeFunction).not.toHaveBeenCalled();
126
+ act(function () {
127
+ userEvent.click(previousButton);
128
+ });
129
+ expect(changeFunction).toHaveBeenCalledTimes(1);
130
+ });
131
+ it('should change offset using keyboard', function () {
132
+ getComponent();
133
+ var menuButton = screen.getByTestId(offsetButtonId);
134
+
135
+ // Focus on the next button and press Enter
136
+ userEvent.tab();
137
+ expect(menuButton).toHaveFocus();
138
+ fireEvent.keyDown(menuButton, {
139
+ key: 'Enter',
140
+ code: 13
141
+ });
142
+ fireEvent.keyUp(menuButton, {
143
+ key: 'Enter',
144
+ code: 13
145
+ });
146
+ var menuItem = screen.getByText('Show 25 Results');
147
+ expect(menuItem).toBeInTheDocument();
148
+ var menu = screen.getByRole('menu');
149
+ var menutItem = screen.queryAllByRole('menuitemradio')[1];
150
+ fireEvent.keyDown(menu, {
151
+ key: 'ArrowDown'
152
+ });
153
+ fireEvent.keyUp(menu, {
154
+ key: 'ArrowDown'
155
+ });
156
+ fireEvent.keyDown(menutItem, {
157
+ key: 'Enter',
158
+ code: 13
159
+ });
160
+ fireEvent.keyUp(menutItem, {
161
+ key: 'Enter',
162
+ code: 13
163
+ });
164
+ expect(screen.getByText('1-25 of 250')).toBeInTheDocument();
165
+ });
166
+ it('should navigate using keyboard keys', function () {
167
+ getComponent();
168
+ var nextButton = screen.getByTestId(nextButtonId);
169
+ var previousButton = screen.getByTestId(prevButtonId);
170
+ var menuButton = screen.getByTestId(offsetButtonId);
171
+
172
+ // Focus on the next button and press Enter
173
+ userEvent.tab();
174
+ expect(menuButton).toHaveFocus();
175
+ userEvent.tab();
176
+ expect(nextButton).toHaveFocus();
177
+ fireEvent.keyDown(nextButton, {
178
+ key: 'Enter',
179
+ code: 13
180
+ });
181
+ fireEvent.keyUp(nextButton, {
182
+ key: 'Enter',
183
+ code: 13
184
+ });
185
+ expect(screen.getByText('11-20 of 250')).toBeInTheDocument();
186
+ userEvent.tab({
187
+ shift: true
188
+ });
189
+ expect(previousButton).toHaveFocus();
190
+ });
191
+ it('clicking the next button changes the rendered page index string', function () {
192
+ render(___EmotionJSX(CustomComponents, null));
193
+ var nextButton = screen.getByTestId(nextButtonId);
194
+ expect(screen.getByText('Current Page Index: 0')).toBeInTheDocument();
195
+ userEvent.click(nextButton);
196
+ expect(screen.getByText('Current Page Index: 1')).toBeInTheDocument();
197
+ });
198
+ it('if fewer than a full page of items is rendered, this is reflected in the text', function () {
199
+ getComponent({
200
+ totalCount: 9,
201
+ offsetCount: 10
202
+ });
203
+ expect(screen.getByText('1-9 of 9')).toBeInTheDocument();
204
+ });
205
+ });
@@ -0,0 +1,24 @@
1
+ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
2
+ import React, { useCallback, useState } from 'react';
3
+ import { defaultState, PaginationContext } from '../../context/PaginationContext';
4
+ import { jsx as ___EmotionJSX } from "@emotion/react";
5
+ var PaginationProvider = function PaginationProvider(props) {
6
+ var children = props.children;
7
+ var _useState = useState(defaultState),
8
+ _useState2 = _slicedToArray(_useState, 2),
9
+ paginationState = _useState2[0],
10
+ setPaginationState = _useState2[1];
11
+ var setPaginationStateCallback = useCallback(function (newState) {
12
+ setPaginationState(newState);
13
+ }, []);
14
+ var contextValue = React.useMemo(function () {
15
+ return {
16
+ paginationState: paginationState,
17
+ setPaginationState: setPaginationStateCallback
18
+ };
19
+ }, [paginationState, setPaginationStateCallback]);
20
+ return ___EmotionJSX(PaginationContext.Provider, {
21
+ value: contextValue
22
+ }, children);
23
+ };
24
+ export default PaginationProvider;
@@ -0,0 +1,2 @@
1
+ export { default } from './Pagination';
2
+ export * from './Pagination';
@@ -0,0 +1,11 @@
1
+ import { createContext } from 'react';
2
+ export var defaultState = {
3
+ firstRenderedIndex: 0,
4
+ lastRenderedIndex: 0,
5
+ offsetCount: 0,
6
+ totalCount: 0,
7
+ currentPageIndex: 0
8
+ };
9
+ export var PaginationContext = /*#__PURE__*/createContext({
10
+ paginationState: defaultState
11
+ });
package/lib/fonts.js ADDED
@@ -0,0 +1,2 @@
1
+ export var pingitoFont = "\n @font-face {\n font-weight: 200;\n font-family: \"pingito\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.0/css/fonts/Pingito-Light.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 400;\n font-family: \"pingito\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.0/css/fonts/Pingito-Regular.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 600;\n font-family: \"pingito\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.0/css/fonts/Pingito-SemiBold.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 700;\n font-family: \"pingito\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.0/css/fonts/Pingito-Bold.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 900;\n font-family: \"pingito\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.0/css/fonts/Pingito-ExtraBold.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 200;\n font-style: italic;\n font-family: \"pingito\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.0/css/fonts/Pingito-ItalicLight.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 400;\n font-style: italic;\n font-family: \"pingito\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.0/css/fonts/Pingito-Italic.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 600;\n font-style: italic;\n font-family: \"pingito\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.0/css/fonts/Pingito-ItalicSemiBold.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 700;\n font-style: italic;\n font-family: \"pingito\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.0/css/fonts/Pingito-ItalicBold.ttf\");\n size-adjust: 100%;\n }\n";
2
+ export var openSansFont = "\n @font-face {\n font-weight: 200;\n font-family: \"Open Sans\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.1/fonts/OpenSans-Light.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 400;\n font-family: \"Open Sans\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.1/fonts/OpenSans-Regular.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 600;\n font-family: \"Open Sans\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.1/fonts/OpenSans-SemiBold.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 700;\n font-family: \"Open Sans\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.1/fonts/OpenSans-Bold.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 900;\n font-family: \"Open Sans\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.1/fonts/OpenSans-ExtraBold.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 200;\n font-style: italic;\n font-family: \"Open Sans\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.1/fonts/OpenSans-LightItalic.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 400;\n font-style: italic;\n font-family: \"Open Sans\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.1/fonts/OpenSans-Italic.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 600;\n font-style: italic;\n font-family: \"Open Sans\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.1/fonts/OpenSans-SemiBoldItalic.ttf\");\n size-adjust: 100%;\n }\n\n @font-face {\n font-weight: 700;\n font-style: italic;\n font-family: \"Open Sans\";\n src: url(\"https://assets.pingone.com/ux/end-user/2.19.1/fonts/OpenSans-BoldItalic.ttf\");\n size-adjust: 100%;\n }\n";
@@ -15,6 +15,8 @@ export { default as useMountTransition } from './useMountTransition';
15
15
  export { default as useNavBarPress } from './useNavBarPress';
16
16
  export { default as useOverlappingMenuHoverState } from './useOverlappingMenuHoverState';
17
17
  export { default as useOverlayPanelState } from './useOverlayPanelState';
18
+ export { default as usePagination } from './usePagination';
19
+ export { default as usePaginationState } from './usePaginationState';
18
20
  export { default as useProgressiveState } from './useProgressiveState';
19
21
  export { default as usePropWarning } from './usePropWarning';
20
22
  export { default as useRockerButton } from './useRockerButton';
@@ -0,0 +1 @@
1
+ export { default } from './usePagination';
@@ -0,0 +1,170 @@
1
+ import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
2
+ import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
3
+ import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
4
+ var _excluded = ["currentPageIndex", "nextButtonProps", "offsetCount", "offsetMenuProps", "offsetOptions", "onOffsetCountChange", "onPageIndexChange", "previousButtonProps", "totalCount"];
5
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
8
+ import _parseInt from "@babel/runtime-corejs3/core-js-stable/parse-int";
9
+ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
10
+ import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
11
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
12
+ import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
13
+ import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
14
+ import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
15
+ import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
16
+ import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
17
+ import { useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
18
+ import { PaginationContext } from '../../context/PaginationContext';
19
+ import useProgressiveState from '../useProgressiveState';
20
+ var getRangeString = function getRangeString(_ref) {
21
+ var _context, _context2;
22
+ var first = _ref.first,
23
+ last = _ref.last,
24
+ total = _ref.total;
25
+ return _concatInstanceProperty(_context = _concatInstanceProperty(_context2 = "".concat(first + 1, "-")).call(_context2, Math.min(last + 1, total), " of ")).call(_context, total);
26
+ };
27
+ var getNewIndexOnOffsetChange = function getNewIndexOnOffsetChange(_ref2) {
28
+ var first = _ref2.first,
29
+ newOffset = _ref2.newOffset;
30
+ var newLast = Math.floor(first / newOffset);
31
+ return newLast;
32
+ };
33
+ var defaultOffsetOptions = [10, 25, 50];
34
+ var usePagination = function usePagination(props) {
35
+ var currentPageIndexProp = props.currentPageIndex,
36
+ nextButtonProps = props.nextButtonProps,
37
+ offsetCountProp = props.offsetCount,
38
+ offsetMenuProps = props.offsetMenuProps,
39
+ _props$offsetOptions = props.offsetOptions,
40
+ offsetOptions = _props$offsetOptions === void 0 ? defaultOffsetOptions : _props$offsetOptions,
41
+ onOffsetCountChange = props.onOffsetCountChange,
42
+ onPageIndexChange = props.onPageIndexChange,
43
+ previousButtonProps = props.previousButtonProps,
44
+ totalCount = props.totalCount,
45
+ others = _objectWithoutProperties(props, _excluded);
46
+ var isMountedRef = useRef(false);
47
+ var initialIndexValue = currentPageIndexProp || 0;
48
+ var initialOffsetValue = offsetCountProp || 10;
49
+ var _useProgressiveState = useProgressiveState(currentPageIndexProp, initialIndexValue),
50
+ _useProgressiveState2 = _slicedToArray(_useProgressiveState, 2),
51
+ currentPageIndex = _useProgressiveState2[0],
52
+ setCurrentPageIndex = _useProgressiveState2[1];
53
+ var _useProgressiveState3 = useProgressiveState(offsetCountProp, initialOffsetValue),
54
+ _useProgressiveState4 = _slicedToArray(_useProgressiveState3, 2),
55
+ offsetCount = _useProgressiveState4[0],
56
+ setOffsetCount = _useProgressiveState4[1];
57
+ var _useState = useState(currentPageIndex),
58
+ _useState2 = _slicedToArray(_useState, 2),
59
+ firstRenderedIndex = _useState2[0],
60
+ setFirstRenderedIndex = _useState2[1];
61
+ var _useState3 = useState((currentPageIndex + 1) * offsetCount - 1),
62
+ _useState4 = _slicedToArray(_useState3, 2),
63
+ lastRenderedIndex = _useState4[0],
64
+ setLastRenderedIndex = _useState4[1];
65
+ useEffect(function () {
66
+ var calculatedLastIndex = (currentPageIndex + 1) * offsetCount - 1;
67
+ setFirstRenderedIndex(currentPageIndex * offsetCount);
68
+ setLastRenderedIndex(Math.min(calculatedLastIndex, totalCount));
69
+ }, [currentPageIndex, offsetCount, totalCount]);
70
+ useEffect(function () {
71
+ if (isMountedRef.current) {
72
+ var newIndex = getNewIndexOnOffsetChange({
73
+ newOffset: offsetCount,
74
+ first: firstRenderedIndex
75
+ });
76
+ setCurrentPageIndex(newIndex);
77
+ if (onPageIndexChange) {
78
+ onPageIndexChange(newIndex);
79
+ }
80
+ }
81
+ }, [offsetCount]);
82
+ useEffect(function () {
83
+ isMountedRef.current = true;
84
+ }, []);
85
+ var lastIndex = Math.ceil(totalCount / offsetCount);
86
+ var isFirstIndex = currentPageIndex === 0;
87
+ var isLastIndex = lastIndex - 1 === currentPageIndex;
88
+ var popoverButtonString = useMemo(function () {
89
+ return getRangeString({
90
+ first: firstRenderedIndex,
91
+ last: lastRenderedIndex,
92
+ total: totalCount
93
+ });
94
+ }, [firstRenderedIndex, lastRenderedIndex, totalCount]);
95
+ var setOffsetCountCallback = useCallback(function (keys) {
96
+ if (keys !== null && keys !== void 0 && keys.currentKey) {
97
+ setOffsetCount(_parseInt(keys.currentKey, 10));
98
+ if (onOffsetCountChange && isMountedRef.current) {
99
+ onOffsetCountChange(_parseInt(keys.currentKey, 10));
100
+ }
101
+ }
102
+ }, [setOffsetCount, onOffsetCountChange, isMountedRef]);
103
+ var paginationState = useMemo(function () {
104
+ return {
105
+ isFirstIndex: isFirstIndex,
106
+ isLastIndex: isLastIndex,
107
+ firstRenderedIndex: firstRenderedIndex,
108
+ lastRenderedIndex: lastRenderedIndex,
109
+ offsetCount: offsetCount,
110
+ totalCount: totalCount,
111
+ currentPageIndex: currentPageIndex,
112
+ popoverButtonString: popoverButtonString,
113
+ setOffsetCount: setOffsetCountCallback,
114
+ offsetOptions: offsetOptions
115
+ };
116
+ }, [isFirstIndex, isLastIndex, firstRenderedIndex, lastRenderedIndex, offsetCount, totalCount, currentPageIndex, popoverButtonString, setOffsetCountCallback, offsetOptions]);
117
+ var contextState = useMemo(function () {
118
+ return {
119
+ firstRenderedIndex: firstRenderedIndex,
120
+ lastRenderedIndex: lastRenderedIndex,
121
+ offsetCount: offsetCount,
122
+ totalCount: totalCount,
123
+ currentPageIndex: currentPageIndex
124
+ };
125
+ }, [firstRenderedIndex, lastRenderedIndex, offsetCount, totalCount, currentPageIndex]);
126
+ var _useContext = useContext(PaginationContext),
127
+ setPaginationState = _useContext.setPaginationState;
128
+ useEffect(function () {
129
+ if (setPaginationState) {
130
+ setPaginationState(_objectSpread({}, contextState));
131
+ }
132
+ }, [contextState, setPaginationState]);
133
+ var nextIndex = function nextIndex() {
134
+ if (!isLastIndex) {
135
+ setCurrentPageIndex(currentPageIndex + 1);
136
+ if (onPageIndexChange) {
137
+ onPageIndexChange(currentPageIndex + 1);
138
+ }
139
+ }
140
+ };
141
+ var previousIndex = function previousIndex() {
142
+ if (!isFirstIndex) {
143
+ setCurrentPageIndex(currentPageIndex - 1);
144
+ if (onPageIndexChange) {
145
+ onPageIndexChange(currentPageIndex - 1);
146
+ }
147
+ }
148
+ };
149
+ var nextButtonPropsSpread = _objectSpread(_objectSpread({
150
+ 'aria-label': 'Next Page'
151
+ }, nextButtonProps), {}, {
152
+ isDisabled: isLastIndex,
153
+ onPress: nextIndex
154
+ });
155
+ var previousButtonPropsSpread = _objectSpread(_objectSpread({
156
+ 'aria-label': 'Previous Page'
157
+ }, previousButtonProps), {}, {
158
+ isDisabled: isFirstIndex,
159
+ onPress: previousIndex
160
+ });
161
+ var containerProps = _objectSpread({}, others);
162
+ return {
163
+ state: paginationState,
164
+ previousButtonProps: previousButtonPropsSpread,
165
+ nextButtonProps: nextButtonPropsSpread,
166
+ containerProps: containerProps,
167
+ offsetMenuProps: offsetMenuProps
168
+ };
169
+ };
170
+ export default usePagination;
@@ -0,0 +1 @@
1
+ export { default } from './usePaginationState';
@@ -0,0 +1,10 @@
1
+ import { useContext } from 'react';
2
+ import { PaginationContext } from '../../context/PaginationContext';
3
+ var usePaginationState = function usePaginationState() {
4
+ var _useContext = useContext(PaginationContext),
5
+ paginationState = _useContext.paginationState;
6
+ return {
7
+ paginationState: paginationState
8
+ };
9
+ };
10
+ export default usePaginationState;
package/lib/index.js CHANGED
@@ -138,6 +138,8 @@ export * from './components/NumberField';
138
138
  export { default as OverlayPanel } from './components/OverlayPanel';
139
139
  export * from './components/OverlayPanel';
140
140
  export { default as PageHeader } from './components/PageHeader';
141
+ export { default as Pagination } from './components/Pagination';
142
+ export { default as PaginationProvider } from './components/Pagination/PaginationProvider';
141
143
  export { default as PanelHeader } from './components/PanelHeader';
142
144
  export { default as PanelHeaderCloseButton } from './components/PanelHeader/controls/PanelHeaderCloseButton';
143
145
  export { default as PanelHeaderMenu } from './components/PanelHeader/controls/PanelHeaderMenu';
@@ -210,6 +212,7 @@ export { default as TooltipTrigger } from './components/TooltipTrigger';
210
212
  export * from './components/TooltipTrigger';
211
213
  export { default as TreeView } from './components/TreeView';
212
214
  export * from './components/TreeView';
215
+ export { PaginationContext } from './context/PaginationContext';
213
216
  export { default as NextGenDarkTheme } from './styles/themeOverrides/nextGenDarkMode';
214
217
  export { default as OnyxDarkTheme } from './styles/themeOverrides/nextGenDarkMode';
215
218
  export { default as NextGenTheme } from './styles/themes/next-gen';
@@ -59,6 +59,9 @@ var buttons = {
59
59
  color: 'black'
60
60
  }
61
61
  },
62
+ paginationMenu: {
63
+ color: 'text.secondary'
64
+ },
62
65
  neutral: {
63
66
  color: 'gray-400'
64
67
  },
@@ -1,4 +1,4 @@
1
- var nextGenConvertedComponents = ['DataTable', 'Message', 'Button', 'Badge', 'IconButton', 'CheckboxField', 'Messages', 'PopoverMenu', 'TextField', 'PasswordField', 'SearchField', 'SelectField', 'Modal', 'RadioField', 'MultiValuesField', 'TextAreaField', 'RadioGroupField', 'Tabs', 'ProgressBar', 'NavBar', 'OverlayPanel', 'AstroProvider', 'ListView', 'NavigationHeader', 'Avatar', 'MultivaluesField', 'Text', 'Link', 'Card', 'IconWrapper', 'ComboBoxField', 'CodeView', 'Sticker Sheet', 'NextGen ListViewItem', 'Skeleton'];
1
+ var nextGenConvertedComponents = ['DataTable', 'Message', 'Button', 'Badge', 'IconButton', 'CheckboxField', 'Messages', 'PopoverMenu', 'TextField', 'PasswordField', 'SearchField', 'SelectField', 'Modal', 'RadioField', 'MultiValuesField', 'TextAreaField', 'RadioGroupField', 'Tabs', 'ProgressBar', 'NavBar', 'OverlayPanel', 'AstroProvider', 'ListView', 'NavigationHeader', 'Avatar', 'MultivaluesField', 'Text', 'Link', 'Card', 'IconWrapper', 'ComboBoxField', 'CodeView', 'Sticker Sheet', 'NextGen ListViewItem', 'Skeleton', 'Pagination'];
2
2
  export var componentSpecificNextGenBlacklist = {
3
3
  AstroProvider: ['Default', 'With Custom Theme Override'],
4
4
  Badge: ['Status Badge Variants', 'Badge With Left Slot And Icon', 'Callout Badges', 'Removable'],