@patternfly/react-core 4.172.0 → 4.174.2
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 +38 -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 +440 -90
- package/dist/umd/react-core.js +57 -51
- package/dist/umd/react-core.min.css +509 -159
- 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/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/DateTimePicker.md +103 -0
- package/src/demos/TextInputGroupDemo.md +278 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.174.2",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -34,16 +34,16 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.
|
|
38
|
-
"@patternfly/react-styles": "^4.
|
|
39
|
-
"@patternfly/react-tokens": "^4.
|
|
37
|
+
"@patternfly/react-icons": "^4.25.2",
|
|
38
|
+
"@patternfly/react-styles": "^4.24.2",
|
|
39
|
+
"@patternfly/react-tokens": "^4.26.2",
|
|
40
40
|
"focus-trap": "6.2.2",
|
|
41
41
|
"react-dropzone": "10.2.2",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
43
43
|
"tslib": "^2.0.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@patternfly/patternfly": "4.
|
|
46
|
+
"@patternfly/patternfly": "4.159.0",
|
|
47
47
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
48
48
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
49
49
|
"@rollup/plugin-replace": "^3.0.0",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "e3eb3038c1f23818774f99280f2a4485ee4a2be2"
|
|
64
64
|
}
|
|
@@ -16,6 +16,8 @@ export interface ContextSelectorItemProps {
|
|
|
16
16
|
index: number;
|
|
17
17
|
/** Internal callback for ref tracking */
|
|
18
18
|
sendRef: (index: number, current: any) => void;
|
|
19
|
+
/** Link href, indicates item should render as anchor tag */
|
|
20
|
+
href?: string;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
export class ContextSelectorItem extends React.Component<ContextSelectorItemProps> {
|
|
@@ -26,10 +28,11 @@ export class ContextSelectorItem extends React.Component<ContextSelectorItemProp
|
|
|
26
28
|
isDisabled: false,
|
|
27
29
|
onClick: (): any => undefined,
|
|
28
30
|
index: undefined as number,
|
|
29
|
-
sendRef: () => {}
|
|
31
|
+
sendRef: () => {},
|
|
32
|
+
href: null as string
|
|
30
33
|
};
|
|
31
34
|
|
|
32
|
-
ref: React.RefObject<HTMLButtonElement> = React.createRef();
|
|
35
|
+
ref: React.RefObject<HTMLButtonElement & HTMLAnchorElement> = React.createRef();
|
|
33
36
|
|
|
34
37
|
componentDidMount() {
|
|
35
38
|
/* eslint-disable-next-line */
|
|
@@ -38,13 +41,19 @@ export class ContextSelectorItem extends React.Component<ContextSelectorItemProp
|
|
|
38
41
|
|
|
39
42
|
render() {
|
|
40
43
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
41
|
-
const { className, children, onClick, isDisabled, index, sendRef, ...props } = this.props;
|
|
44
|
+
const { className, children, onClick, isDisabled, index, sendRef, href, ...props } = this.props;
|
|
45
|
+
const Component = href ? 'a' : 'button';
|
|
46
|
+
const isDisabledLink = href && isDisabled;
|
|
42
47
|
return (
|
|
43
48
|
<ContextSelectorContext.Consumer>
|
|
44
49
|
{({ onSelect }) => (
|
|
45
50
|
<li role="none">
|
|
46
|
-
<
|
|
47
|
-
className={css(
|
|
51
|
+
<Component
|
|
52
|
+
className={css(
|
|
53
|
+
styles.contextSelectorMenuListItem,
|
|
54
|
+
isDisabledLink && styles.modifiers.disabled,
|
|
55
|
+
className
|
|
56
|
+
)}
|
|
48
57
|
ref={this.ref}
|
|
49
58
|
onClick={event => {
|
|
50
59
|
if (!isDisabled) {
|
|
@@ -52,11 +61,13 @@ export class ContextSelectorItem extends React.Component<ContextSelectorItemProp
|
|
|
52
61
|
onSelect(event, children);
|
|
53
62
|
}
|
|
54
63
|
}}
|
|
55
|
-
disabled={isDisabled}
|
|
64
|
+
disabled={isDisabled && !href}
|
|
65
|
+
href={href}
|
|
66
|
+
{...(isDisabledLink && { 'aria-disabled': true, tabIndex: -1 })}
|
|
56
67
|
{...props}
|
|
57
68
|
>
|
|
58
69
|
{children}
|
|
59
|
-
</
|
|
70
|
+
</Component>
|
|
60
71
|
</li>
|
|
61
72
|
)}
|
|
62
73
|
</ContextSelectorContext.Consumer>
|
package/src/components/ContextSelector/__tests__/__snapshots__/ContextSelector.test.tsx.snap
CHANGED
|
@@ -97,6 +97,7 @@ exports[`Renders ContextSelector open 1`] = `
|
|
|
97
97
|
|
|
98
98
|
<ContextSelectorItem
|
|
99
99
|
className=""
|
|
100
|
+
href={null}
|
|
100
101
|
isDisabled={false}
|
|
101
102
|
key="0"
|
|
102
103
|
onClick={[Function]}
|
|
@@ -106,6 +107,7 @@ exports[`Renders ContextSelector open 1`] = `
|
|
|
106
107
|
</ContextSelectorItem>
|
|
107
108
|
<ContextSelectorItem
|
|
108
109
|
className=""
|
|
110
|
+
href={null}
|
|
109
111
|
isDisabled={false}
|
|
110
112
|
key="1"
|
|
111
113
|
onClick={[Function]}
|
|
@@ -115,6 +117,7 @@ exports[`Renders ContextSelector open 1`] = `
|
|
|
115
117
|
</ContextSelectorItem>
|
|
116
118
|
<ContextSelectorItem
|
|
117
119
|
className=""
|
|
120
|
+
href={null}
|
|
118
121
|
isDisabled={false}
|
|
119
122
|
key="2"
|
|
120
123
|
onClick={[Function]}
|
|
@@ -124,6 +127,7 @@ exports[`Renders ContextSelector open 1`] = `
|
|
|
124
127
|
</ContextSelectorItem>
|
|
125
128
|
<ContextSelectorItem
|
|
126
129
|
className=""
|
|
130
|
+
href={null}
|
|
127
131
|
isDisabled={false}
|
|
128
132
|
key="3"
|
|
129
133
|
onClick={[Function]}
|
|
@@ -133,6 +137,7 @@ exports[`Renders ContextSelector open 1`] = `
|
|
|
133
137
|
</ContextSelectorItem>
|
|
134
138
|
<ContextSelectorItem
|
|
135
139
|
className=""
|
|
140
|
+
href={null}
|
|
136
141
|
isDisabled={false}
|
|
137
142
|
key="4"
|
|
138
143
|
onClick={[Function]}
|
package/src/components/ContextSelector/__tests__/__snapshots__/ContextSelectorMenuList.test.tsx.snap
CHANGED
|
@@ -8,6 +8,7 @@ exports[`Renders ContextSelectorMenuList closed 1`] = `
|
|
|
8
8
|
>
|
|
9
9
|
<ContextSelectorItem
|
|
10
10
|
className=""
|
|
11
|
+
href={null}
|
|
11
12
|
index={0}
|
|
12
13
|
isDisabled={false}
|
|
13
14
|
key=".$0"
|
|
@@ -18,6 +19,7 @@ exports[`Renders ContextSelectorMenuList closed 1`] = `
|
|
|
18
19
|
</ContextSelectorItem>
|
|
19
20
|
<ContextSelectorItem
|
|
20
21
|
className=""
|
|
22
|
+
href={null}
|
|
21
23
|
index={1}
|
|
22
24
|
isDisabled={false}
|
|
23
25
|
key=".$1"
|
|
@@ -28,6 +30,7 @@ exports[`Renders ContextSelectorMenuList closed 1`] = `
|
|
|
28
30
|
</ContextSelectorItem>
|
|
29
31
|
<ContextSelectorItem
|
|
30
32
|
className=""
|
|
33
|
+
href={null}
|
|
31
34
|
index={2}
|
|
32
35
|
isDisabled={false}
|
|
33
36
|
key=".$2"
|
|
@@ -38,6 +41,7 @@ exports[`Renders ContextSelectorMenuList closed 1`] = `
|
|
|
38
41
|
</ContextSelectorItem>
|
|
39
42
|
<ContextSelectorItem
|
|
40
43
|
className=""
|
|
44
|
+
href={null}
|
|
41
45
|
index={3}
|
|
42
46
|
isDisabled={false}
|
|
43
47
|
key=".$3"
|
|
@@ -48,6 +52,7 @@ exports[`Renders ContextSelectorMenuList closed 1`] = `
|
|
|
48
52
|
</ContextSelectorItem>
|
|
49
53
|
<ContextSelectorItem
|
|
50
54
|
className=""
|
|
55
|
+
href={null}
|
|
51
56
|
index={4}
|
|
52
57
|
isDisabled={false}
|
|
53
58
|
key=".$4"
|
|
@@ -67,6 +72,7 @@ exports[`Renders ContextSelectorMenuList open 1`] = `
|
|
|
67
72
|
>
|
|
68
73
|
<ContextSelectorItem
|
|
69
74
|
className=""
|
|
75
|
+
href={null}
|
|
70
76
|
index={0}
|
|
71
77
|
isDisabled={false}
|
|
72
78
|
key=".$0"
|
|
@@ -77,6 +83,7 @@ exports[`Renders ContextSelectorMenuList open 1`] = `
|
|
|
77
83
|
</ContextSelectorItem>
|
|
78
84
|
<ContextSelectorItem
|
|
79
85
|
className=""
|
|
86
|
+
href={null}
|
|
80
87
|
index={1}
|
|
81
88
|
isDisabled={false}
|
|
82
89
|
key=".$1"
|
|
@@ -87,6 +94,7 @@ exports[`Renders ContextSelectorMenuList open 1`] = `
|
|
|
87
94
|
</ContextSelectorItem>
|
|
88
95
|
<ContextSelectorItem
|
|
89
96
|
className=""
|
|
97
|
+
href={null}
|
|
90
98
|
index={2}
|
|
91
99
|
isDisabled={false}
|
|
92
100
|
key=".$2"
|
|
@@ -97,6 +105,7 @@ exports[`Renders ContextSelectorMenuList open 1`] = `
|
|
|
97
105
|
</ContextSelectorItem>
|
|
98
106
|
<ContextSelectorItem
|
|
99
107
|
className=""
|
|
108
|
+
href={null}
|
|
100
109
|
index={3}
|
|
101
110
|
isDisabled={false}
|
|
102
111
|
key=".$3"
|
|
@@ -107,6 +116,7 @@ exports[`Renders ContextSelectorMenuList open 1`] = `
|
|
|
107
116
|
</ContextSelectorItem>
|
|
108
117
|
<ContextSelectorItem
|
|
109
118
|
className=""
|
|
119
|
+
href={null}
|
|
110
120
|
index={4}
|
|
111
121
|
isDisabled={false}
|
|
112
122
|
key=".$4"
|
|
@@ -18,6 +18,20 @@ class SimpleContextSelector extends React.Component {
|
|
|
18
18
|
constructor(props) {
|
|
19
19
|
super(props);
|
|
20
20
|
this.items = [
|
|
21
|
+
{
|
|
22
|
+
text: 'Link',
|
|
23
|
+
href: '#'
|
|
24
|
+
},
|
|
25
|
+
'Action',
|
|
26
|
+
{
|
|
27
|
+
text: 'Disabled link',
|
|
28
|
+
href: '#',
|
|
29
|
+
isDisabled: true
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
text: 'Disabled action',
|
|
33
|
+
isDisabled: true
|
|
34
|
+
},
|
|
21
35
|
'My project',
|
|
22
36
|
'OpenShift cluster',
|
|
23
37
|
'Production Ansible',
|
|
@@ -32,7 +46,7 @@ class SimpleContextSelector extends React.Component {
|
|
|
32
46
|
|
|
33
47
|
this.state = {
|
|
34
48
|
isOpen: false,
|
|
35
|
-
selected: this.items[0],
|
|
49
|
+
selected: this.items[0].text || this.items[0],
|
|
36
50
|
searchValue: '',
|
|
37
51
|
filteredItems: this.items
|
|
38
52
|
};
|
|
@@ -58,7 +72,10 @@ class SimpleContextSelector extends React.Component {
|
|
|
58
72
|
const filtered =
|
|
59
73
|
this.state.searchValue === ''
|
|
60
74
|
? this.items
|
|
61
|
-
: this.items.filter(
|
|
75
|
+
: this.items.filter(item => {
|
|
76
|
+
const str = item.text ? item.text : item;
|
|
77
|
+
return str.toLowerCase().indexOf(this.state.searchValue.toLowerCase()) !== -1;
|
|
78
|
+
});
|
|
62
79
|
|
|
63
80
|
this.setState({ filteredItems: filtered || [] });
|
|
64
81
|
};
|
|
@@ -77,9 +94,10 @@ class SimpleContextSelector extends React.Component {
|
|
|
77
94
|
onSearchButtonClick={this.onSearchButtonClick}
|
|
78
95
|
screenReaderLabel="Selected Project:"
|
|
79
96
|
>
|
|
80
|
-
{filteredItems.map((item, index) =>
|
|
81
|
-
|
|
82
|
-
|
|
97
|
+
{filteredItems.map((item, index) => {
|
|
98
|
+
const { text = null, href = null, isDisabled } = item;
|
|
99
|
+
return (<ContextSelectorItem key={index} href={href} isDisabled={isDisabled}>{text || item}</ContextSelectorItem>);
|
|
100
|
+
})}
|
|
83
101
|
</ContextSelector>
|
|
84
102
|
);
|
|
85
103
|
}
|
|
@@ -92,7 +110,27 @@ class SimpleContextSelector extends React.Component {
|
|
|
92
110
|
import React from 'react';
|
|
93
111
|
import { ContextSelector, ContextSelectorItem } from '@patternfly/react-core';
|
|
94
112
|
|
|
113
|
+
interface Item {
|
|
114
|
+
text: string;
|
|
115
|
+
href?: string;
|
|
116
|
+
isDisabled?: boolean;
|
|
117
|
+
}
|
|
118
|
+
|
|
95
119
|
const items = [
|
|
120
|
+
{
|
|
121
|
+
text: 'Link',
|
|
122
|
+
href: '#'
|
|
123
|
+
},
|
|
124
|
+
'Action',
|
|
125
|
+
{
|
|
126
|
+
text: 'Disabled link',
|
|
127
|
+
href: '#',
|
|
128
|
+
isDisabled: true
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
text: 'Disabled action',
|
|
132
|
+
isDisabled: true
|
|
133
|
+
},
|
|
96
134
|
'My Project',
|
|
97
135
|
'OpenShift Cluster',
|
|
98
136
|
'Production Ansible',
|
|
@@ -106,8 +144,9 @@ const items = [
|
|
|
106
144
|
];
|
|
107
145
|
|
|
108
146
|
const PlainTextContextSelector: React.FunctionComponent = () => {
|
|
147
|
+
const firstItemText = typeof items[0] === 'string' ? items[0] : items[0].text;
|
|
109
148
|
const [isOpen, setOpen] = React.useState(false);
|
|
110
|
-
const [selected, setSelected] = React.useState(
|
|
149
|
+
const [selected, setSelected] = React.useState(firstItemText);
|
|
111
150
|
const [searchValue, setSearchValue] = React.useState('');
|
|
112
151
|
const [filteredItems, setFilteredItems] = React.useState(items);
|
|
113
152
|
|
|
@@ -126,7 +165,12 @@ const PlainTextContextSelector: React.FunctionComponent = () => {
|
|
|
126
165
|
|
|
127
166
|
function onSearchButtonClick(event: React.SyntheticEvent<HTMLButtonElement>) {
|
|
128
167
|
const filtered =
|
|
129
|
-
searchValue === ''
|
|
168
|
+
searchValue === ''
|
|
169
|
+
? items
|
|
170
|
+
: items.filter(item => {
|
|
171
|
+
const str = (typeof item === 'string') ? item : item.text;
|
|
172
|
+
return str.toLowerCase().indexOf(searchValue.toLowerCase()) !== -1;
|
|
173
|
+
});
|
|
130
174
|
|
|
131
175
|
setFilteredItems(filtered || []);
|
|
132
176
|
};
|
|
@@ -143,9 +187,12 @@ const PlainTextContextSelector: React.FunctionComponent = () => {
|
|
|
143
187
|
isPlain
|
|
144
188
|
isText
|
|
145
189
|
>
|
|
146
|
-
{filteredItems.map((item, index) =>
|
|
147
|
-
|
|
148
|
-
|
|
190
|
+
{filteredItems.map((item, index) => {
|
|
191
|
+
const [text, href = null, isDisabled = false] = (typeof item === 'string')
|
|
192
|
+
? [item, null, false]
|
|
193
|
+
: [item.text, item.href, item.isDisabled];
|
|
194
|
+
return <ContextSelectorItem key={index} href={href} isDisabled={isDisabled}>{text}</ContextSelectorItem>;
|
|
195
|
+
})}
|
|
149
196
|
</ContextSelector>
|
|
150
197
|
);
|
|
151
198
|
};
|
|
@@ -161,6 +208,20 @@ class FooterContextSelector extends React.Component {
|
|
|
161
208
|
constructor(props) {
|
|
162
209
|
super(props);
|
|
163
210
|
this.items = [
|
|
211
|
+
{
|
|
212
|
+
text: 'Link',
|
|
213
|
+
href: '#'
|
|
214
|
+
},
|
|
215
|
+
'Action',
|
|
216
|
+
{
|
|
217
|
+
text: 'Disabled link',
|
|
218
|
+
href: '#',
|
|
219
|
+
isDisabled: true
|
|
220
|
+
},
|
|
221
|
+
{
|
|
222
|
+
text: 'Disabled action',
|
|
223
|
+
isDisabled: true
|
|
224
|
+
},
|
|
164
225
|
'My project',
|
|
165
226
|
'OpenShift cluster',
|
|
166
227
|
'Production Ansible',
|
|
@@ -175,7 +236,7 @@ class FooterContextSelector extends React.Component {
|
|
|
175
236
|
|
|
176
237
|
this.state = {
|
|
177
238
|
isOpen: false,
|
|
178
|
-
selected: this.items[0],
|
|
239
|
+
selected: this.items[0].text || this.items[0],
|
|
179
240
|
searchValue: '',
|
|
180
241
|
filteredItems: this.items
|
|
181
242
|
};
|
|
@@ -201,7 +262,10 @@ class FooterContextSelector extends React.Component {
|
|
|
201
262
|
const filtered =
|
|
202
263
|
this.state.searchValue === ''
|
|
203
264
|
? this.items
|
|
204
|
-
: this.items.filter(
|
|
265
|
+
: this.items.filter(item => {
|
|
266
|
+
const str = item.text ? item.text : item;
|
|
267
|
+
return str.toLowerCase().indexOf(this.state.searchValue.toLowerCase()) !== -1;
|
|
268
|
+
});
|
|
205
269
|
|
|
206
270
|
this.setState({ filteredItems: filtered || [] });
|
|
207
271
|
};
|
|
@@ -225,9 +289,10 @@ class FooterContextSelector extends React.Component {
|
|
|
225
289
|
</ContextSelectorFooter>
|
|
226
290
|
}
|
|
227
291
|
>
|
|
228
|
-
{filteredItems.map((item, index) =>
|
|
229
|
-
|
|
230
|
-
|
|
292
|
+
{filteredItems.map((item, index) => {
|
|
293
|
+
const { text = null, href = null, isDisabled } = item;
|
|
294
|
+
return (<ContextSelectorItem key={index} href={href} isDisabled={isDisabled}>{text || item}</ContextSelectorItem>);
|
|
295
|
+
})}
|
|
231
296
|
</ContextSelector>
|
|
232
297
|
);
|
|
233
298
|
}
|
|
@@ -217,7 +217,9 @@ export const MenuItem: React.FunctionComponent<MenuItemProps> = ({
|
|
|
217
217
|
if (Component === 'a') {
|
|
218
218
|
additionalProps = {
|
|
219
219
|
href: to,
|
|
220
|
-
'aria-disabled': isDisabled ? true : null
|
|
220
|
+
'aria-disabled': isDisabled ? true : null,
|
|
221
|
+
// prevent invalid 'disabled' attribute on <a> tags
|
|
222
|
+
disabled: null
|
|
221
223
|
};
|
|
222
224
|
} else if (Component === 'button') {
|
|
223
225
|
additionalProps = {
|
|
@@ -17,6 +17,8 @@ export interface NavigationProps extends React.HTMLProps<HTMLElement> {
|
|
|
17
17
|
isDisabled?: boolean;
|
|
18
18
|
/** Flag indicating if the pagination is compact */
|
|
19
19
|
isCompact?: boolean;
|
|
20
|
+
/** Total number of items. */
|
|
21
|
+
itemCount?: number;
|
|
20
22
|
/** The number of the last page */
|
|
21
23
|
lastPage?: number;
|
|
22
24
|
/** The number of first page where pagination starts */
|
|
@@ -140,6 +142,7 @@ export class Navigation extends React.Component<NavigationProps, NavigationState
|
|
|
140
142
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
141
143
|
onSetPage,
|
|
142
144
|
isDisabled,
|
|
145
|
+
itemCount,
|
|
143
146
|
lastPage,
|
|
144
147
|
firstPage,
|
|
145
148
|
pagesTitle,
|
|
@@ -201,16 +204,20 @@ export class Navigation extends React.Component<NavigationProps, NavigationState
|
|
|
201
204
|
className={css(styles.formControl)}
|
|
202
205
|
aria-label={currPage}
|
|
203
206
|
type="number"
|
|
204
|
-
disabled={
|
|
207
|
+
disabled={
|
|
208
|
+
isDisabled || (itemCount && page === firstPage && page === lastPage && itemCount >= 0) || page === 0
|
|
209
|
+
}
|
|
205
210
|
min={lastPage <= 0 && firstPage <= 0 ? 0 : 1}
|
|
206
211
|
max={lastPage}
|
|
207
212
|
value={userInputPage}
|
|
208
213
|
onKeyDown={event => this.onKeyDown(event, page, lastPage, onPageInput)}
|
|
209
214
|
onChange={event => this.onChange(event, lastPage)}
|
|
210
215
|
/>
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
216
|
+
{(itemCount || itemCount === 0) && (
|
|
217
|
+
<span aria-hidden="true">
|
|
218
|
+
{ofWord} {pagesTitle ? pluralize(lastPage, pagesTitle) : lastPage}
|
|
219
|
+
</span>
|
|
220
|
+
)}
|
|
214
221
|
</div>
|
|
215
222
|
)}
|
|
216
223
|
<div className={styles.paginationNavControl}>
|
|
@@ -48,7 +48,7 @@ export const OptionsToggle: React.FunctionComponent<OptionsToggleProps> = ({
|
|
|
48
48
|
ofWord = 'of',
|
|
49
49
|
firstIndex = 0,
|
|
50
50
|
lastIndex = 0,
|
|
51
|
-
itemCount
|
|
51
|
+
itemCount,
|
|
52
52
|
widgetId = '',
|
|
53
53
|
showToggle = true,
|
|
54
54
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -56,7 +56,7 @@ export const OptionsToggle: React.FunctionComponent<OptionsToggleProps> = ({
|
|
|
56
56
|
isOpen = false,
|
|
57
57
|
isDisabled = false,
|
|
58
58
|
parentRef = null,
|
|
59
|
-
toggleTemplate: ToggleTemplate
|
|
59
|
+
toggleTemplate: ToggleTemplate,
|
|
60
60
|
onEnter = null
|
|
61
61
|
}: OptionsToggleProps) => (
|
|
62
62
|
<div
|
|
@@ -86,7 +86,7 @@ export const OptionsToggle: React.FunctionComponent<OptionsToggleProps> = ({
|
|
|
86
86
|
onEnter={onEnter}
|
|
87
87
|
aria-label={optionsToggle}
|
|
88
88
|
onToggle={onToggle}
|
|
89
|
-
isDisabled={isDisabled || itemCount <= 0}
|
|
89
|
+
isDisabled={isDisabled || (itemCount && itemCount <= 0)}
|
|
90
90
|
isOpen={isOpen}
|
|
91
91
|
id={`${widgetId}-toggle-${toggleId++}`}
|
|
92
92
|
className={styles.optionsMenuToggleButton}
|
|
@@ -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]}
|