@patternfly/react-core 4.171.0 → 4.174.1

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 (68) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/dist/esm/components/ContextSelector/ContextSelectorItem.d.ts +3 -1
  3. package/dist/esm/components/ContextSelector/ContextSelectorItem.d.ts.map +1 -1
  4. package/dist/esm/components/ContextSelector/ContextSelectorItem.js +7 -4
  5. package/dist/esm/components/ContextSelector/ContextSelectorItem.js.map +1 -1
  6. package/dist/esm/components/Menu/MenuItem.d.ts.map +1 -1
  7. package/dist/esm/components/Menu/MenuItem.js +3 -1
  8. package/dist/esm/components/Menu/MenuItem.js.map +1 -1
  9. package/dist/esm/components/Pagination/Navigation.d.ts +2 -0
  10. package/dist/esm/components/Pagination/Navigation.d.ts.map +1 -1
  11. package/dist/esm/components/Pagination/Navigation.js +4 -4
  12. package/dist/esm/components/Pagination/Navigation.js.map +1 -1
  13. package/dist/esm/components/Pagination/OptionsToggle.js +3 -3
  14. package/dist/esm/components/Pagination/OptionsToggle.js.map +1 -1
  15. package/dist/esm/components/Pagination/Pagination.d.ts +1 -1
  16. package/dist/esm/components/Pagination/Pagination.d.ts.map +1 -1
  17. package/dist/esm/components/Pagination/Pagination.js +27 -18
  18. package/dist/esm/components/Pagination/Pagination.js.map +1 -1
  19. package/dist/esm/components/Pagination/PaginationOptionsMenu.d.ts +1 -1
  20. package/dist/esm/components/Pagination/PaginationOptionsMenu.d.ts.map +1 -1
  21. package/dist/esm/components/Pagination/PaginationOptionsMenu.js +3 -14
  22. package/dist/esm/components/Pagination/PaginationOptionsMenu.js.map +1 -1
  23. package/dist/js/components/ContextSelector/ContextSelectorItem.d.ts +3 -1
  24. package/dist/js/components/ContextSelector/ContextSelectorItem.d.ts.map +1 -1
  25. package/dist/js/components/ContextSelector/ContextSelectorItem.js +7 -4
  26. package/dist/js/components/ContextSelector/ContextSelectorItem.js.map +1 -1
  27. package/dist/js/components/Menu/MenuItem.d.ts.map +1 -1
  28. package/dist/js/components/Menu/MenuItem.js +3 -1
  29. package/dist/js/components/Menu/MenuItem.js.map +1 -1
  30. package/dist/js/components/Pagination/Navigation.d.ts +2 -0
  31. package/dist/js/components/Pagination/Navigation.d.ts.map +1 -1
  32. package/dist/js/components/Pagination/Navigation.js +4 -4
  33. package/dist/js/components/Pagination/Navigation.js.map +1 -1
  34. package/dist/js/components/Pagination/OptionsToggle.js +3 -3
  35. package/dist/js/components/Pagination/OptionsToggle.js.map +1 -1
  36. package/dist/js/components/Pagination/Pagination.d.ts +1 -1
  37. package/dist/js/components/Pagination/Pagination.d.ts.map +1 -1
  38. package/dist/js/components/Pagination/Pagination.js +30 -21
  39. package/dist/js/components/Pagination/Pagination.js.map +1 -1
  40. package/dist/js/components/Pagination/PaginationOptionsMenu.d.ts +1 -1
  41. package/dist/js/components/Pagination/PaginationOptionsMenu.d.ts.map +1 -1
  42. package/dist/js/components/Pagination/PaginationOptionsMenu.js +3 -14
  43. package/dist/js/components/Pagination/PaginationOptionsMenu.js.map +1 -1
  44. package/dist/umd/react-core.css +343 -87
  45. package/dist/umd/react-core.js +55 -51
  46. package/dist/umd/react-core.min.css +343 -87
  47. package/dist/umd/react-core.min.js +4 -4
  48. package/package.json +6 -6
  49. package/src/components/ContextSelector/ContextSelectorItem.tsx +18 -7
  50. package/src/components/ContextSelector/__tests__/__snapshots__/ContextSelector.test.tsx.snap +5 -0
  51. package/src/components/ContextSelector/__tests__/__snapshots__/ContextSelectorMenuList.test.tsx.snap +10 -0
  52. package/src/components/ContextSelector/examples/ContextSelector.md +80 -15
  53. package/src/components/Menu/MenuItem.tsx +3 -1
  54. package/src/components/Nav/examples/Nav.md +98 -0
  55. package/src/components/Nav/examples/nav.css +1 -0
  56. package/src/components/Pagination/Navigation.tsx +11 -4
  57. package/src/components/Pagination/OptionsToggle.tsx +3 -3
  58. package/src/components/Pagination/Pagination.tsx +40 -23
  59. package/src/components/Pagination/PaginationOptionsMenu.tsx +4 -15
  60. package/src/components/Pagination/__tests__/Generated/__snapshots__/Navigation.test.tsx.snap +0 -7
  61. package/src/components/Pagination/__tests__/Generated/__snapshots__/OptionsToggle.test.tsx.snap +1 -1
  62. package/src/components/Pagination/__tests__/Generated/__snapshots__/Pagination.test.tsx.snap +3 -8
  63. package/src/components/Pagination/__tests__/Pagination.test.tsx +24 -0
  64. package/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap +187 -157
  65. package/src/components/Pagination/examples/Pagination.md +35 -0
  66. package/src/components/TextInputGroup/examples/TextInputGroup.md +4 -4
  67. package/src/demos/ComposableMenu.md +27 -6
  68. package/src/demos/TextInputGroupDemo.md +278 -0
@@ -2,6 +2,8 @@ import * as React from 'react';
2
2
  import { ToggleTemplate, ToggleTemplateProps } from './ToggleTemplate';
3
3
  import styles from '@patternfly/react-styles/css/components/Pagination/pagination';
4
4
  import { css } from '@patternfly/react-styles';
5
+
6
+ import { fillTemplate } from '../../helpers';
5
7
  import { Navigation } from './Navigation';
6
8
  import { PaginationOptionsMenu } from './PaginationOptionsMenu';
7
9
  import { getOUIAProps, OUIAProps, getDefaultOUIAId } from '../../helpers';
@@ -88,7 +90,7 @@ export interface PaginationProps extends React.HTMLProps<HTMLDivElement>, OUIAPr
88
90
  /** Additional classes for the container. */
89
91
  className?: string;
90
92
  /** Total number of items. */
91
- itemCount: number;
93
+ itemCount?: number;
92
94
  /** Position where pagination is rendered. */
93
95
  variant?: 'top' | 'bottom' | PaginationVariant;
94
96
  /** Flag indicating if pagination is disabled */
@@ -185,7 +187,6 @@ export class Pagination extends React.Component<PaginationProps, { ouiaStateId:
185
187
  itemsEnd: null,
186
188
  perPageOptions: defaultPerPageOptions,
187
189
  widgetId: 'pagination-options-menu',
188
- toggleTemplate: ToggleTemplate,
189
190
  onSetPage: () => undefined,
190
191
  onPerPageSelect: () => undefined,
191
192
  onFirstClick: () => undefined,
@@ -201,8 +202,9 @@ export class Pagination extends React.Component<PaginationProps, { ouiaStateId:
201
202
  };
202
203
 
203
204
  getLastPage() {
204
- const { itemCount, perPage } = this.props;
205
- return Math.ceil(itemCount / perPage) || 0;
205
+ const { itemCount, perPage, page } = this.props;
206
+ // when itemCount is not known let's set lastPage as page+1 as we don't know the total count
207
+ return itemCount || itemCount === 0 ? Math.ceil(itemCount / perPage) || 0 : page + 1;
206
208
  }
207
209
 
208
210
  componentDidMount() {
@@ -255,22 +257,30 @@ export class Pagination extends React.Component<PaginationProps, { ouiaStateId:
255
257
  if (!page && offset) {
256
258
  page = Math.ceil(offset / perPage);
257
259
  }
260
+ if (page === 0 && !itemCount) {
261
+ page = 1;
262
+ }
258
263
 
259
264
  const lastPage = this.getLastPage();
260
- if (page < firstPage && itemCount > 0) {
261
- page = firstPage;
262
- } else if (page > lastPage) {
263
- page = lastPage;
264
- }
265
+ let firstIndex = (page - 1) * perPage + 1;
266
+ let lastIndex = page * perPage;
267
+
268
+ if (itemCount || itemCount === 0) {
269
+ firstIndex = itemCount <= 0 ? 0 : (page - 1) * perPage + 1;
265
270
 
266
- const firstIndex = itemCount <= 0 ? 0 : (page - 1) * perPage + 1;
267
- let lastIndex;
268
- if (itemCount <= 0) {
269
- lastIndex = 0;
270
- } else {
271
- lastIndex = page === lastPage ? itemCount : page * perPage;
271
+ if (page < firstPage && itemCount > 0) {
272
+ page = firstPage;
273
+ } else if (page > lastPage) {
274
+ page = lastPage;
275
+ }
276
+
277
+ if (itemCount >= 0) {
278
+ lastIndex = page === lastPage || itemCount === 0 ? itemCount : page * perPage;
279
+ }
272
280
  }
273
281
 
282
+ const toggleTemplateProps = { firstIndex, lastIndex, itemCount, itemsTitle: titles.items, ofWord: titles.ofWord };
283
+
274
284
  return (
275
285
  <div
276
286
  ref={this.paginationRef}
@@ -288,13 +298,19 @@ export class Pagination extends React.Component<PaginationProps, { ouiaStateId:
288
298
  >
289
299
  {variant === PaginationVariant.top && (
290
300
  <div className={css(styles.paginationTotalItems)}>
291
- <ToggleTemplate
292
- firstIndex={firstIndex}
293
- lastIndex={lastIndex}
294
- itemCount={itemCount}
295
- itemsTitle={titles.items}
296
- ofWord={titles.ofWord}
297
- />
301
+ {toggleTemplate && typeof toggleTemplate === 'string' && fillTemplate(toggleTemplate, toggleTemplateProps)}
302
+ {toggleTemplate &&
303
+ typeof toggleTemplate !== 'string' &&
304
+ (toggleTemplate as (props: ToggleTemplateProps) => React.ReactElement)(toggleTemplateProps)}
305
+ {!toggleTemplate && (
306
+ <ToggleTemplate
307
+ firstIndex={firstIndex}
308
+ lastIndex={lastIndex}
309
+ itemCount={itemCount}
310
+ itemsTitle={titles.items}
311
+ ofWord={titles.ofWord}
312
+ />
313
+ )}
298
314
  </div>
299
315
  )}
300
316
  <PaginationOptionsMenu
@@ -326,8 +342,9 @@ export class Pagination extends React.Component<PaginationProps, { ouiaStateId:
326
342
  currPage={titles.currPage}
327
343
  paginationTitle={titles.paginationTitle}
328
344
  ofWord={titles.ofWord}
329
- page={itemCount <= 0 ? 0 : page}
345
+ page={itemCount && itemCount <= 0 ? 0 : page}
330
346
  perPage={perPage}
347
+ itemCount={itemCount}
331
348
  firstPage={itemsStart !== null ? itemsStart : 1}
332
349
  lastPage={lastPage}
333
350
  onSetPage={onSetPage}
@@ -4,7 +4,7 @@ import { css } from '@patternfly/react-styles';
4
4
  import { DropdownItem, DropdownDirection, DropdownWithContext, DropdownContext } from '../Dropdown';
5
5
  import CheckIcon from '@patternfly/react-icons/dist/esm/icons/check-icon';
6
6
  import { OptionsToggle } from './OptionsToggle';
7
- import { ToggleTemplateProps } from './ToggleTemplate';
7
+ import { ToggleTemplateProps, ToggleTemplate } from './ToggleTemplate';
8
8
  import { PerPageOptions, OnPerPageSelect } from './Pagination';
9
9
 
10
10
  export interface PaginationOptionsMenuProps extends React.HTMLProps<HTMLDivElement> {
@@ -41,7 +41,7 @@ export interface PaginationOptionsMenuProps extends React.HTMLProps<HTMLDivEleme
41
41
  /** The number of the last page */
42
42
  lastPage?: number;
43
43
  /** This will be shown in pagination toggle span. You can use firstIndex, lastIndex, itemCount, itemsTitle props. */
44
- toggleTemplate?: ((props: ToggleTemplateProps) => React.ReactElement) | string;
44
+ toggleTemplate: ((props: ToggleTemplateProps) => React.ReactElement) | string;
45
45
  /** Function called when user selects number of items per page. */
46
46
  onPerPageSelect?: OnPerPageSelect;
47
47
  /** Label for the English word "of" */
@@ -69,8 +69,8 @@ export class PaginationOptionsMenu extends React.Component<PaginationOptionsMenu
69
69
  firstIndex: 0,
70
70
  lastIndex: 0,
71
71
  defaultToFullPage: false,
72
- itemCount: 0,
73
72
  itemsTitle: 'items',
73
+ toggleTemplate: ToggleTemplate,
74
74
  onPerPageSelect: () => null as any
75
75
  };
76
76
 
@@ -181,18 +181,7 @@ export class PaginationOptionsMenu extends React.Component<PaginationOptionsMenu
181
181
  itemCount={itemCount}
182
182
  itemsTitle={itemsTitle}
183
183
  ofWord={ofWord}
184
- toggleTemplate={
185
- toggleTemplate
186
- ? toggleTemplate
187
- : ({ firstIndex, lastIndex, itemCount, ofWord, itemsTitle }: ToggleTemplateProps) => (
188
- <React.Fragment>
189
- <b>
190
- {firstIndex} - {lastIndex}
191
- </b>{' '}
192
- {ofWord} <b>{itemCount}</b> {itemsTitle}
193
- </React.Fragment>
194
- )
195
- }
184
+ toggleTemplate={toggleTemplate}
196
185
  parentRef={this.parentRef.current}
197
186
  isDisabled={isDisabled}
198
187
  />
@@ -53,13 +53,6 @@ exports[`Navigation should match snapshot (auto-generated) 1`] = `
53
53
  type="number"
54
54
  value={42}
55
55
  />
56
- <span
57
- aria-hidden="true"
58
- >
59
- of
60
-
61
- 0 ''s
62
- </span>
63
56
  </div>
64
57
  <div
65
58
  className="pf-c-pagination__nav-control"
@@ -11,7 +11,7 @@ exports[`OptionsToggle should match snapshot (auto-generated) 1`] = `
11
11
  aria-label="'Select'"
12
12
  className="pf-c-options-menu__toggle-button"
13
13
  id="''-toggle-0"
14
- isDisabled={true}
14
+ isDisabled={0}
15
15
  isOpen={false}
16
16
  onEnter={null}
17
17
  onToggle={[Function]}
@@ -11,19 +11,13 @@ exports[`Pagination should match snapshot (auto-generated) 1`] = `
11
11
  <div
12
12
  className="pf-c-pagination__total-items"
13
13
  >
14
- <ToggleTemplate
15
- firstIndex={1}
16
- itemCount={42}
17
- itemsTitle=""
18
- lastIndex={42}
19
- ofWord="of"
20
- />
14
+ string
21
15
  </div>
22
16
  <PaginationOptionsMenu
23
17
  className=""
24
18
  defaultToFullPage={false}
25
19
  dropDirection="up"
26
- firstIndex={1}
20
+ firstIndex={-41}
27
21
  isDisabled={false}
28
22
  itemCount={42}
29
23
  itemsPerPageTitle="Items per page"
@@ -65,6 +59,7 @@ exports[`Pagination should match snapshot (auto-generated) 1`] = `
65
59
  firstPage={1}
66
60
  isCompact={false}
67
61
  isDisabled={false}
62
+ itemCount={42}
68
63
  lastPage={1}
69
64
  ofWord="of"
70
65
  onFirstClick={[Function]}
@@ -85,6 +85,30 @@ describe('component render', () => {
85
85
  const wrapper = mount(<Pagination itemCount={40} dropDirection="up" />);
86
86
  expect(wrapper).toMatchSnapshot();
87
87
  });
88
+
89
+ test('indeterminate count (no item count)', () => {
90
+ const toggle = mount(
91
+ <Pagination />
92
+ ).find('span.pf-c-options-menu__toggle-text');
93
+ expect(toggle.find('b').at(0).text()).toBe('1 - 10');
94
+ expect(toggle).toMatchSnapshot();
95
+ });
96
+
97
+ test('toggleTemplate toggle text with function', () => {
98
+ const toggle = mount(
99
+ <Pagination toggleTemplate={({ firstIndex, lastIndex }) => (<div>{firstIndex} - {lastIndex} of many</div>)} />
100
+ ).find('span.pf-c-options-menu__toggle-text');
101
+ expect(toggle.find('div').text()).toBe('1 - 10 of many');
102
+ expect(toggle).toMatchSnapshot();
103
+ });
104
+
105
+ test('toggleTemplate toggle text with string', () => {
106
+ const toggle = mount(
107
+ <Pagination toggleTemplate={'I am a string'} />
108
+ ).find('span.pf-c-options-menu__toggle-text');
109
+ expect(toggle.text()).toBe('I am a string');
110
+ expect(toggle).toMatchSnapshot();
111
+ });
88
112
  });
89
113
 
90
114
  describe('API', () => {