@pingux/astro 2.119.0-alpha.1 → 2.119.0-alpha.3
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/lib/cjs/components/Button/Buttons.styles.d.ts +40 -0
- package/lib/cjs/components/Button/Buttons.styles.js +4 -0
- package/lib/cjs/components/ListView/ListView.stories.d.ts +3 -0
- package/lib/cjs/components/ListView/ListView.stories.js +2 -1
- package/lib/cjs/components/NavBar/NavBar.stories.d.ts +1 -0
- package/lib/cjs/components/NavBar/NavBar.stories.js +272 -107
- package/lib/cjs/{styles/themeOverrides → components/NavBar}/stories/NavBar.chromatic.stories.js +53 -53
- package/lib/cjs/components/NavBar/stories/NavBarNextGenComponent.js +191 -0
- package/lib/cjs/{styles/themeOverrides/nextGenDarkMode → components/NavBar}/stories/NextGenDarkNavStory.chomatic.stories.js +2 -2
- package/lib/cjs/{styles/themes/next-gen → components/NavBar}/stories/NextGenNavBar.chromatic.stories.js +1 -1
- package/lib/cjs/components/NavBarSection/NavBarItem.js +3 -1
- package/lib/cjs/components/NavBarSection/NavBarItemHeader.js +9 -6
- package/lib/cjs/components/NavBarSection/NavBarItemHeader.test.d.ts +1 -0
- package/lib/cjs/components/NavBarSection/NavBarItemHeader.test.js +86 -0
- package/lib/cjs/components/Pagination/Pagination.d.ts +4 -0
- package/lib/cjs/components/Pagination/Pagination.js +78 -0
- package/lib/cjs/components/Pagination/Pagination.mdx +68 -0
- package/lib/cjs/components/Pagination/Pagination.stories.d.ts +39 -0
- package/lib/cjs/components/Pagination/Pagination.stories.js +159 -0
- package/lib/cjs/components/Pagination/Pagination.styles.d.ts +17 -0
- package/lib/cjs/components/Pagination/Pagination.styles.js +27 -0
- package/lib/cjs/components/Pagination/Pagination.test.d.ts +1 -0
- package/lib/cjs/components/Pagination/Pagination.test.js +208 -0
- package/lib/cjs/components/Pagination/PaginationProvider.d.ts +4 -0
- package/lib/cjs/components/Pagination/PaginationProvider.js +38 -0
- package/lib/cjs/components/Pagination/index.d.ts +2 -0
- package/lib/cjs/components/Pagination/index.js +33 -0
- package/lib/cjs/context/PaginationContext/index.d.ts +10 -0
- package/lib/cjs/context/PaginationContext/index.js +20 -0
- package/lib/cjs/hooks/index.d.ts +2 -0
- package/lib/cjs/hooks/index.js +14 -0
- package/lib/cjs/hooks/usePagination/index.d.ts +1 -0
- package/lib/cjs/hooks/usePagination/index.js +14 -0
- package/lib/cjs/hooks/usePagination/usePagination.d.ts +682 -0
- package/lib/cjs/hooks/usePagination/usePagination.js +178 -0
- package/lib/cjs/hooks/usePaginationState/index.d.ts +1 -0
- package/lib/cjs/hooks/usePaginationState/index.js +14 -0
- package/lib/cjs/hooks/usePaginationState/usePaginationState.d.ts +4 -0
- package/lib/cjs/hooks/usePaginationState/usePaginationState.js +18 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.js +24 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/buttons.d.ts +3 -0
- package/lib/cjs/styles/themeOverrides/nextGenDarkMode/variants/buttons.js +3 -0
- package/lib/cjs/styles/themes/next-gen/convertedComponentList.d.ts +4 -0
- package/lib/cjs/styles/themes/next-gen/convertedComponentList.js +8 -3
- package/lib/cjs/styles/themes/next-gen/next-gen.d.ts +30 -0
- package/lib/cjs/styles/themes/next-gen/variants/button.d.ts +17 -0
- package/lib/cjs/styles/themes/next-gen/variants/button.js +7 -1
- package/lib/cjs/styles/themes/next-gen/variants/links.d.ts +9 -0
- package/lib/cjs/styles/themes/next-gen/variants/links.js +12 -1
- package/lib/cjs/styles/themes/next-gen/variants/navbar.d.ts +4 -0
- package/lib/cjs/styles/themes/next-gen/variants/navbar.js +11 -7
- package/lib/cjs/styles/themes/next-gen/variants/variants.d.ts +4 -0
- package/lib/cjs/styles/variants/variants.js +3 -1
- package/lib/cjs/types/pagination.d.ts +46 -0
- package/lib/cjs/types/pagination.js +6 -0
- package/lib/cjs/utils/devUtils/shouldReturnComingSoon.js +8 -2
- package/lib/components/Button/Buttons.styles.js +4 -0
- package/lib/components/ListView/ListView.stories.js +1 -1
- package/lib/components/NavBar/NavBar.stories.js +196 -32
- package/lib/{styles/themeOverrides → components/NavBar}/stories/NavBar.chromatic.stories.js +2 -2
- package/lib/components/NavBar/stories/NavBarNextGenComponent.js +182 -0
- package/lib/{styles/themeOverrides/nextGenDarkMode → components/NavBar}/stories/NextGenDarkNavStory.chomatic.stories.js +2 -2
- package/lib/{styles/themes/next-gen → components/NavBar}/stories/NextGenNavBar.chromatic.stories.js +1 -1
- package/lib/components/NavBarSection/NavBarItem.js +4 -2
- package/lib/components/NavBarSection/NavBarItemHeader.js +7 -4
- package/lib/components/NavBarSection/NavBarItemHeader.test.js +83 -0
- package/lib/components/Pagination/Pagination.js +64 -0
- package/lib/components/Pagination/Pagination.mdx +68 -0
- package/lib/components/Pagination/Pagination.stories.js +141 -0
- package/lib/components/Pagination/Pagination.styles.js +19 -0
- package/lib/components/Pagination/Pagination.test.js +205 -0
- package/lib/components/Pagination/PaginationProvider.js +24 -0
- package/lib/components/Pagination/index.js +2 -0
- package/lib/context/PaginationContext/index.js +11 -0
- package/lib/hooks/index.js +2 -0
- package/lib/hooks/usePagination/index.js +1 -0
- package/lib/hooks/usePagination/usePagination.js +170 -0
- package/lib/hooks/usePaginationState/index.js +1 -0
- package/lib/hooks/usePaginationState/usePaginationState.js +10 -0
- package/lib/index.js +3 -0
- package/lib/styles/themeOverrides/nextGenDarkMode/variants/buttons.js +3 -0
- package/lib/styles/themes/next-gen/convertedComponentList.js +6 -2
- package/lib/styles/themes/next-gen/variants/button.js +7 -1
- package/lib/styles/themes/next-gen/variants/links.js +12 -1
- package/lib/styles/themes/next-gen/variants/navbar.js +11 -7
- package/lib/styles/variants/variants.js +3 -1
- package/lib/types/pagination.js +1 -0
- package/lib/utils/devUtils/shouldReturnComingSoon.js +9 -3
- package/package.json +1 -1
- package/lib/cjs/recipes/NextGen/NavBarNextGen.stories.d.ts +0 -6
- package/lib/cjs/recipes/NextGen/NavBarNextGen.stories.js +0 -19
- package/lib/cjs/styles/themes/next-gen/stories/NavBarNextGenComponent.js +0 -191
- package/lib/recipes/NextGen/NavBarNextGen.stories.js +0 -9
- package/lib/styles/themes/next-gen/stories/NavBarNextGenComponent.js +0 -182
- /package/lib/cjs/{styles/themes/next-gen → components/NavBar}/stories/NavBarNextGenComponent.d.ts +0 -0
- /package/lib/cjs/{styles/themeOverrides/nextGenDarkMode → components/NavBar}/stories/NextGenDarkNavStory.chomatic.stories.d.ts +0 -0
- /package/lib/cjs/{styles/themes/next-gen → components/NavBar}/stories/NextGenNavBar.chromatic.stories.d.ts +0 -0
@@ -26,6 +26,7 @@ var NavBarSectionItemHeader = function NavBarSectionItemHeader(_ref2) {
|
|
26
26
|
heading = item.heading;
|
27
27
|
var navBarState = useNavBarContext();
|
28
28
|
var _useGetTheme = useGetTheme(),
|
29
|
+
isOnyx = _useGetTheme.themeState.isOnyx,
|
29
30
|
icons = _useGetTheme.icons;
|
30
31
|
var MenuDown = icons.MenuDown,
|
31
32
|
MenuUp = icons.MenuUp;
|
@@ -61,7 +62,7 @@ var NavBarSectionItemHeader = function NavBarSectionItemHeader(_ref2) {
|
|
61
62
|
"data-testid": heading
|
62
63
|
}, icon && ___EmotionJSX(Icon, {
|
63
64
|
icon: icon,
|
64
|
-
size:
|
65
|
+
size: isOnyx ? 'icon-200' : 'sm',
|
65
66
|
sx: {
|
66
67
|
mr: 'sm',
|
67
68
|
color: getIconColor(),
|
@@ -78,7 +79,7 @@ var NavBarSectionItemHeader = function NavBarSectionItemHeader(_ref2) {
|
|
78
79
|
}
|
79
80
|
}, ___EmotionJSX(Icon, {
|
80
81
|
icon: isExpanded ? MenuUp : MenuDown,
|
81
|
-
size: navStyles.navBarItemHeaderIconSize,
|
82
|
+
size: isOnyx ? 'icon-100' : navStyles.navBarItemHeaderIconSize,
|
82
83
|
sx: {
|
83
84
|
color: getIconColor(),
|
84
85
|
fill: getIconColor()
|
@@ -96,6 +97,8 @@ var NavBarPrimaryItemHeader = function NavBarPrimaryItemHeader(_ref3) {
|
|
96
97
|
customIcon = item.customIcon;
|
97
98
|
var navBarState = useNavBarContext();
|
98
99
|
var navStyles = navBarState.navStyles;
|
100
|
+
var _useGetTheme2 = useGetTheme(),
|
101
|
+
isOnyx = _useGetTheme2.themeState.isOnyx;
|
99
102
|
return ___EmotionJSX(Box, {
|
100
103
|
variant: navStyles.navBarItemHeader,
|
101
104
|
className: className,
|
@@ -103,7 +106,7 @@ var NavBarPrimaryItemHeader = function NavBarPrimaryItemHeader(_ref3) {
|
|
103
106
|
"data-testid": heading
|
104
107
|
}, icon && ___EmotionJSX(Icon, {
|
105
108
|
icon: icon,
|
106
|
-
size:
|
109
|
+
size: isOnyx ? 'icon-200' : 'sm',
|
107
110
|
sx: {
|
108
111
|
mr: 'sm',
|
109
112
|
color: 'neutral.95',
|
@@ -123,7 +126,7 @@ var NavBarPrimaryItemHeader = function NavBarPrimaryItemHeader(_ref3) {
|
|
123
126
|
}
|
124
127
|
}, customIcon && ___EmotionJSX(Icon, {
|
125
128
|
icon: customIcon,
|
126
|
-
size:
|
129
|
+
size: isOnyx ? 'icon-200' : 'sm',
|
127
130
|
sx: {
|
128
131
|
color: 'neutral.95',
|
129
132
|
fill: 'neutral.95'
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
2
|
+
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
3
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
4
|
+
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
5
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
6
|
+
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
7
|
+
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
8
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
9
|
+
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
11
|
+
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; }
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
13
|
+
import React from 'react';
|
14
|
+
import ViewDashboard from '@pingux/mdi-react/ViewDashboardIcon';
|
15
|
+
import { useGetTheme } from '../../hooks';
|
16
|
+
import { render, screen } from '../../utils/testUtils/testWrapper';
|
17
|
+
import NavBar from '../NavBar';
|
18
|
+
import NavBarSection from './NavBarSection';
|
19
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
20
|
+
var data = [{
|
21
|
+
'data-id': 'dashboard-data-id',
|
22
|
+
heading: 'Dashboard',
|
23
|
+
icon: ViewDashboard,
|
24
|
+
key: 'Dashboard',
|
25
|
+
children: ['Users', 'Group', 'Populations', 'Attributes', 'Roles', 'Dashboard Unique']
|
26
|
+
}];
|
27
|
+
var mockTheme = {
|
28
|
+
themeState: {
|
29
|
+
isOnyx: false
|
30
|
+
},
|
31
|
+
icons: {
|
32
|
+
MenuDown: function MenuDown() {
|
33
|
+
return ___EmotionJSX("span", null, "MenuDown");
|
34
|
+
},
|
35
|
+
MenuUp: function MenuUp() {
|
36
|
+
return ___EmotionJSX("span", null, "MenuUp");
|
37
|
+
}
|
38
|
+
}
|
39
|
+
};
|
40
|
+
jest.mock('../../hooks/useGetTheme', function () {
|
41
|
+
return {
|
42
|
+
__esModule: true,
|
43
|
+
"default": jest.fn()
|
44
|
+
};
|
45
|
+
});
|
46
|
+
var NavBarWithSection = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
47
|
+
return ___EmotionJSX(NavBar, null, ___EmotionJSX(NavBarSection, _extends({
|
48
|
+
ref: ref
|
49
|
+
}, props, {
|
50
|
+
items: data
|
51
|
+
})));
|
52
|
+
});
|
53
|
+
var getComponent = function getComponent() {
|
54
|
+
return render(___EmotionJSX(NavBarWithSection, null));
|
55
|
+
};
|
56
|
+
describe('NavItemHeader', function () {
|
57
|
+
beforeEach(function () {
|
58
|
+
jest.clearAllMocks();
|
59
|
+
useGetTheme.mockReturnValue(mockTheme);
|
60
|
+
});
|
61
|
+
it('should render Icon', function () {
|
62
|
+
getComponent();
|
63
|
+
var icon = screen.getByTestId('Dashboard').querySelector('svg');
|
64
|
+
expect(icon).toBeInTheDocument();
|
65
|
+
expect(icon).toHaveAttribute('width', '20px');
|
66
|
+
});
|
67
|
+
});
|
68
|
+
describe('NavItemHeader', function () {
|
69
|
+
beforeEach(function () {
|
70
|
+
jest.clearAllMocks();
|
71
|
+
useGetTheme.mockReturnValue(_objectSpread(_objectSpread({}, mockTheme), {}, {
|
72
|
+
themeState: {
|
73
|
+
isOnyx: true
|
74
|
+
}
|
75
|
+
}));
|
76
|
+
});
|
77
|
+
it('should render Icon', function () {
|
78
|
+
getComponent();
|
79
|
+
var icon = screen.getByTestId('Dashboard').querySelector('svg');
|
80
|
+
expect(icon).toBeInTheDocument();
|
81
|
+
expect(icon).toHaveAttribute('width', 'icon-200');
|
82
|
+
});
|
83
|
+
});
|
@@ -0,0 +1,64 @@
|
|
1
|
+
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
3
|
+
var _excluded = ["setOffsetCount", "offsetOptions"];
|
4
|
+
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
5
|
+
import React, { forwardRef } from 'react';
|
6
|
+
import ChevronLeftIcon from '@pingux/mdi-react/ChevronLeftIcon';
|
7
|
+
import ChevronRightIcon from '@pingux/mdi-react/ChevronRightIcon';
|
8
|
+
import { useLocalOrForwardRef } from '../../hooks';
|
9
|
+
import usePagination from '../../hooks/usePagination';
|
10
|
+
import { Box, Button, Icon, IconButton, Item, Menu, OverlayProvider, PopoverMenu } from '../../index';
|
11
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
12
|
+
var RangeSelectPopover = /*#__PURE__*/forwardRef(function (props, ref) {
|
13
|
+
var state = props.state,
|
14
|
+
buttonProps = props.buttonProps;
|
15
|
+
var setOffsetCount = state.setOffsetCount,
|
16
|
+
offsetOptions = state.offsetOptions,
|
17
|
+
others = _objectWithoutProperties(state, _excluded);
|
18
|
+
var menuRef = useLocalOrForwardRef(ref);
|
19
|
+
return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(Box, {
|
20
|
+
sx: {
|
21
|
+
flexGrow: 1
|
22
|
+
}
|
23
|
+
}, ___EmotionJSX(PopoverMenu, {
|
24
|
+
ref: menuRef
|
25
|
+
}, ___EmotionJSX(Button, _extends({}, buttonProps, {
|
26
|
+
variant: "paginationMenu"
|
27
|
+
}), state.popoverButtonString), ___EmotionJSX(Menu, _extends({
|
28
|
+
onSelectionChange: setOffsetCount,
|
29
|
+
selectionMode: "single"
|
30
|
+
}, others), _mapInstanceProperty(offsetOptions).call(offsetOptions, function (option) {
|
31
|
+
return ___EmotionJSX(Item, {
|
32
|
+
key: option,
|
33
|
+
textValue: "".concat(option)
|
34
|
+
}, "Show", ' ', option, ' ', "Results");
|
35
|
+
})))));
|
36
|
+
});
|
37
|
+
var Pagination = /*#__PURE__*/forwardRef(function (props, ref) {
|
38
|
+
var _usePagination = usePagination(props),
|
39
|
+
state = _usePagination.state,
|
40
|
+
previousButtonProps = _usePagination.previousButtonProps,
|
41
|
+
nextButtonProps = _usePagination.nextButtonProps,
|
42
|
+
containerProps = _usePagination.containerProps,
|
43
|
+
offsetMenuProps = _usePagination.offsetMenuProps;
|
44
|
+
var paginationRef = useLocalOrForwardRef(ref);
|
45
|
+
return ___EmotionJSX(Box, _extends({
|
46
|
+
isRow: true,
|
47
|
+
variant: "pagination.container"
|
48
|
+
}, containerProps, {
|
49
|
+
ref: paginationRef
|
50
|
+
}), ___EmotionJSX(Box, {
|
51
|
+
variant: "pagination.wrapper",
|
52
|
+
isRow: true
|
53
|
+
}, ___EmotionJSX(RangeSelectPopover, _extends({}, offsetMenuProps, {
|
54
|
+
state: state
|
55
|
+
})), ___EmotionJSX(Box, {
|
56
|
+
variant: "pagination.iconWrapper",
|
57
|
+
isRow: true
|
58
|
+
}, ___EmotionJSX(IconButton, previousButtonProps, ___EmotionJSX(Icon, {
|
59
|
+
icon: ChevronLeftIcon
|
60
|
+
})), ___EmotionJSX(IconButton, nextButtonProps, ___EmotionJSX(Icon, {
|
61
|
+
icon: ChevronRightIcon
|
62
|
+
})))));
|
63
|
+
});
|
64
|
+
export default Pagination;
|
@@ -0,0 +1,68 @@
|
|
1
|
+
import { Meta } from '@storybook/addon-docs';
|
2
|
+
|
3
|
+
<Meta title="Components/Pagination/Pagination" />
|
4
|
+
|
5
|
+
# Pagination
|
6
|
+
|
7
|
+
The Pagination component allows users to navigate through large datasets by dividing them into smaller, more manageable pages. It provides controls for navigating between pages and selecting the number of items displayed per page.
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
- Customizable offset options to control the number of items displayed per page.
|
12
|
+
- Next/Previous navigation buttons for seamless page transitions.
|
13
|
+
- Works in both controlled and uncontrolled states.
|
14
|
+
- Integrates with `PaginationContext` for managing state.
|
15
|
+
|
16
|
+
### Required Components
|
17
|
+
|
18
|
+
This component requires the following components:
|
19
|
+
- `PaginationProvider`
|
20
|
+
- `ListView` (optional for displaying paginated data)
|
21
|
+
|
22
|
+
### Accessibility
|
23
|
+
|
24
|
+
This component adheres to the [WCAG 2.1 - 2.4.4 Link Purpose (In Context)](https://www.w3.org/WAI/WCAG21/Understanding/link-purpose-in-context.html) accessibility guidelines.
|
25
|
+
|
26
|
+
#### Keyboard Navigation
|
27
|
+
|
28
|
+
| Key | Functions |
|
29
|
+
|---------------|-----------------------------------|
|
30
|
+
| Tab | Moves focus between controls. |
|
31
|
+
| Enter | Activates the focused control. |
|
32
|
+
|
33
|
+
#### Screen Readers
|
34
|
+
|
35
|
+
This component uses the following attributes to assist screen readers:
|
36
|
+
- **`aria-label`**: Provides an accessible name for the pagination controls.
|
37
|
+
- **`aria-disabled`**: Indicates when navigation buttons are disabled.
|
38
|
+
- **`aria-live`**: Updates screen readers with changes in pagination state.
|
39
|
+
|
40
|
+
### Usage
|
41
|
+
|
42
|
+
```tsx
|
43
|
+
import { Pagination, PaginationProvider } from '@pingux/astro';
|
44
|
+
|
45
|
+
<PaginationProvider>
|
46
|
+
<Pagination totalCount={250} />
|
47
|
+
<ListView
|
48
|
+
items={animals.slice(paginationState.firstRenderedIndex, paginationState.lastRenderedIndex).map(item => ({
|
49
|
+
name: item.name,
|
50
|
+
key: item.name,
|
51
|
+
id: item.name,
|
52
|
+
}))}
|
53
|
+
>
|
54
|
+
{(item) => (
|
55
|
+
<Item key={item.name}>
|
56
|
+
<ListViewItem
|
57
|
+
data={{
|
58
|
+
text: item.name,
|
59
|
+
icon: FormSelectIcon,
|
60
|
+
}}
|
61
|
+
iconProps={{
|
62
|
+
color: 'text.secondary',
|
63
|
+
}}
|
64
|
+
/>
|
65
|
+
</Item>
|
66
|
+
)}
|
67
|
+
</ListView>
|
68
|
+
</PaginationProvider>
|
@@ -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,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/hooks/index.js
CHANGED
@@ -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';
|