@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.
- package/CHANGELOG.md +41 -0
- package/dist/esm/components/ContextSelector/ContextSelectorItem.d.ts +3 -1
- package/dist/esm/components/ContextSelector/ContextSelectorItem.d.ts.map +1 -1
- package/dist/esm/components/ContextSelector/ContextSelectorItem.js +7 -4
- package/dist/esm/components/ContextSelector/ContextSelectorItem.js.map +1 -1
- package/dist/esm/components/Menu/MenuItem.d.ts.map +1 -1
- package/dist/esm/components/Menu/MenuItem.js +3 -1
- package/dist/esm/components/Menu/MenuItem.js.map +1 -1
- package/dist/esm/components/Pagination/Navigation.d.ts +2 -0
- package/dist/esm/components/Pagination/Navigation.d.ts.map +1 -1
- package/dist/esm/components/Pagination/Navigation.js +4 -4
- package/dist/esm/components/Pagination/Navigation.js.map +1 -1
- package/dist/esm/components/Pagination/OptionsToggle.js +3 -3
- package/dist/esm/components/Pagination/OptionsToggle.js.map +1 -1
- package/dist/esm/components/Pagination/Pagination.d.ts +1 -1
- package/dist/esm/components/Pagination/Pagination.d.ts.map +1 -1
- package/dist/esm/components/Pagination/Pagination.js +27 -18
- package/dist/esm/components/Pagination/Pagination.js.map +1 -1
- package/dist/esm/components/Pagination/PaginationOptionsMenu.d.ts +1 -1
- package/dist/esm/components/Pagination/PaginationOptionsMenu.d.ts.map +1 -1
- package/dist/esm/components/Pagination/PaginationOptionsMenu.js +3 -14
- package/dist/esm/components/Pagination/PaginationOptionsMenu.js.map +1 -1
- package/dist/js/components/ContextSelector/ContextSelectorItem.d.ts +3 -1
- package/dist/js/components/ContextSelector/ContextSelectorItem.d.ts.map +1 -1
- package/dist/js/components/ContextSelector/ContextSelectorItem.js +7 -4
- package/dist/js/components/ContextSelector/ContextSelectorItem.js.map +1 -1
- package/dist/js/components/Menu/MenuItem.d.ts.map +1 -1
- package/dist/js/components/Menu/MenuItem.js +3 -1
- package/dist/js/components/Menu/MenuItem.js.map +1 -1
- package/dist/js/components/Pagination/Navigation.d.ts +2 -0
- package/dist/js/components/Pagination/Navigation.d.ts.map +1 -1
- package/dist/js/components/Pagination/Navigation.js +4 -4
- package/dist/js/components/Pagination/Navigation.js.map +1 -1
- package/dist/js/components/Pagination/OptionsToggle.js +3 -3
- package/dist/js/components/Pagination/OptionsToggle.js.map +1 -1
- package/dist/js/components/Pagination/Pagination.d.ts +1 -1
- package/dist/js/components/Pagination/Pagination.d.ts.map +1 -1
- package/dist/js/components/Pagination/Pagination.js +30 -21
- package/dist/js/components/Pagination/Pagination.js.map +1 -1
- package/dist/js/components/Pagination/PaginationOptionsMenu.d.ts +1 -1
- package/dist/js/components/Pagination/PaginationOptionsMenu.d.ts.map +1 -1
- package/dist/js/components/Pagination/PaginationOptionsMenu.js +3 -14
- package/dist/js/components/Pagination/PaginationOptionsMenu.js.map +1 -1
- package/dist/umd/react-core.css +343 -87
- package/dist/umd/react-core.js +55 -51
- package/dist/umd/react-core.min.css +343 -87
- package/dist/umd/react-core.min.js +4 -4
- package/package.json +6 -6
- package/src/components/ContextSelector/ContextSelectorItem.tsx +18 -7
- package/src/components/ContextSelector/__tests__/__snapshots__/ContextSelector.test.tsx.snap +5 -0
- package/src/components/ContextSelector/__tests__/__snapshots__/ContextSelectorMenuList.test.tsx.snap +10 -0
- package/src/components/ContextSelector/examples/ContextSelector.md +80 -15
- package/src/components/Menu/MenuItem.tsx +3 -1
- package/src/components/Nav/examples/Nav.md +98 -0
- package/src/components/Nav/examples/nav.css +1 -0
- package/src/components/Pagination/Navigation.tsx +11 -4
- package/src/components/Pagination/OptionsToggle.tsx +3 -3
- package/src/components/Pagination/Pagination.tsx +40 -23
- package/src/components/Pagination/PaginationOptionsMenu.tsx +4 -15
- package/src/components/Pagination/__tests__/Generated/__snapshots__/Navigation.test.tsx.snap +0 -7
- package/src/components/Pagination/__tests__/Generated/__snapshots__/OptionsToggle.test.tsx.snap +1 -1
- package/src/components/Pagination/__tests__/Generated/__snapshots__/Pagination.test.tsx.snap +3 -8
- package/src/components/Pagination/__tests__/Pagination.test.tsx +24 -0
- package/src/components/Pagination/__tests__/__snapshots__/Pagination.test.tsx.snap +187 -157
- package/src/components/Pagination/examples/Pagination.md +35 -0
- package/src/components/TextInputGroup/examples/TextInputGroup.md +4 -4
- package/src/demos/ComposableMenu.md +27 -6
- 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
|
|
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
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
|
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
|
/>
|
package/src/components/Pagination/__tests__/Generated/__snapshots__/OptionsToggle.test.tsx.snap
CHANGED
|
@@ -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={
|
|
14
|
+
isDisabled={0}
|
|
15
15
|
isOpen={false}
|
|
16
16
|
onEnter={null}
|
|
17
17
|
onToggle={[Function]}
|
package/src/components/Pagination/__tests__/Generated/__snapshots__/Pagination.test.tsx.snap
CHANGED
|
@@ -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
|
-
|
|
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={
|
|
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', () => {
|