@patternfly/react-core 4.173.0 → 4.175.0
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/Card/Card.d.ts +6 -0
- package/dist/esm/components/Card/Card.d.ts.map +1 -1
- package/dist/esm/components/Card/Card.js +2 -2
- package/dist/esm/components/Card/Card.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/esm/components/Panel/Panel.d.ts +13 -0
- package/dist/esm/components/Panel/Panel.d.ts.map +1 -0
- package/dist/esm/components/Panel/Panel.js +10 -0
- package/dist/esm/components/Panel/Panel.js.map +1 -0
- package/dist/esm/components/Panel/PanelFooter.d.ts +9 -0
- package/dist/esm/components/Panel/PanelFooter.d.ts.map +1 -0
- package/dist/esm/components/Panel/PanelFooter.js +10 -0
- package/dist/esm/components/Panel/PanelFooter.js.map +1 -0
- package/dist/esm/components/Panel/PanelHeader.d.ts +9 -0
- package/dist/esm/components/Panel/PanelHeader.d.ts.map +1 -0
- package/dist/esm/components/Panel/PanelHeader.js +10 -0
- package/dist/esm/components/Panel/PanelHeader.js.map +1 -0
- package/dist/esm/components/Panel/PanelMain.d.ts +11 -0
- package/dist/esm/components/Panel/PanelMain.d.ts.map +1 -0
- package/dist/esm/components/Panel/PanelMain.js +10 -0
- package/dist/esm/components/Panel/PanelMain.js.map +1 -0
- package/dist/esm/components/Panel/PanelMainBody.d.ts +9 -0
- package/dist/esm/components/Panel/PanelMainBody.d.ts.map +1 -0
- package/dist/esm/components/Panel/PanelMainBody.js +10 -0
- package/dist/esm/components/Panel/PanelMainBody.js.map +1 -0
- package/dist/esm/components/Panel/index.d.ts +6 -0
- package/dist/esm/components/Panel/index.d.ts.map +1 -0
- package/dist/esm/components/Panel/index.js +6 -0
- package/dist/esm/components/Panel/index.js.map +1 -0
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/js/components/Card/Card.d.ts +6 -0
- package/dist/js/components/Card/Card.d.ts.map +1 -1
- package/dist/js/components/Card/Card.js +2 -2
- package/dist/js/components/Card/Card.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/js/components/Panel/Panel.d.ts +13 -0
- package/dist/js/components/Panel/Panel.d.ts.map +1 -0
- package/dist/js/components/Panel/Panel.js +14 -0
- package/dist/js/components/Panel/Panel.js.map +1 -0
- package/dist/js/components/Panel/PanelFooter.d.ts +9 -0
- package/dist/js/components/Panel/PanelFooter.d.ts.map +1 -0
- package/dist/js/components/Panel/PanelFooter.js +14 -0
- package/dist/js/components/Panel/PanelFooter.js.map +1 -0
- package/dist/js/components/Panel/PanelHeader.d.ts +9 -0
- package/dist/js/components/Panel/PanelHeader.d.ts.map +1 -0
- package/dist/js/components/Panel/PanelHeader.js +14 -0
- package/dist/js/components/Panel/PanelHeader.js.map +1 -0
- package/dist/js/components/Panel/PanelMain.d.ts +11 -0
- package/dist/js/components/Panel/PanelMain.d.ts.map +1 -0
- package/dist/js/components/Panel/PanelMain.js +14 -0
- package/dist/js/components/Panel/PanelMain.js.map +1 -0
- package/dist/js/components/Panel/PanelMainBody.d.ts +9 -0
- package/dist/js/components/Panel/PanelMainBody.d.ts.map +1 -0
- package/dist/js/components/Panel/PanelMainBody.js +14 -0
- package/dist/js/components/Panel/PanelMainBody.js.map +1 -0
- package/dist/js/components/Panel/index.d.ts +6 -0
- package/dist/js/components/Panel/index.d.ts.map +1 -0
- package/dist/js/components/Panel/index.js +9 -0
- package/dist/js/components/Panel/index.js.map +1 -0
- package/dist/js/components/index.d.ts +1 -0
- package/dist/js/components/index.d.ts.map +1 -1
- package/dist/js/components/index.js +1 -0
- package/dist/js/components/index.js.map +1 -1
- package/dist/umd/react-core.css +523 -90
- package/dist/umd/react-core.js +975 -926
- package/dist/umd/react-core.min.css +592 -159
- package/dist/umd/react-core.min.js +2 -2
- package/package.json +6 -6
- package/src/components/Card/Card.tsx +15 -3
- package/src/components/Card/__tests__/Card.test.tsx +24 -0
- package/src/components/Card/__tests__/__snapshots__/Card.test.tsx.snap +11 -1
- package/src/components/Card/examples/Card.md +133 -26
- 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/Panel/Panel.tsx +37 -0
- package/src/components/Panel/PanelFooter.tsx +22 -0
- package/src/components/Panel/PanelHeader.tsx +22 -0
- package/src/components/Panel/PanelMain.tsx +29 -0
- package/src/components/Panel/PanelMainBody.tsx +22 -0
- package/src/components/Panel/__tests__/Panel.test.tsx +62 -0
- package/src/components/Panel/__tests__/__snapshots__/Panel.test.tsx.snap +83 -0
- package/src/components/Panel/examples/Panel.md +203 -0
- package/src/components/Panel/index.ts +5 -0
- package/src/components/TextInputGroup/examples/TextInputGroup.md +4 -4
- package/src/components/index.ts +1 -0
- 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.175.0",
|
|
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.26.0",
|
|
38
|
+
"@patternfly/react-styles": "^4.25.0",
|
|
39
|
+
"@patternfly/react-tokens": "^4.27.0",
|
|
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": "031e0e31853e92aae5dc072a24fdea96403f0472"
|
|
64
64
|
}
|
|
@@ -14,12 +14,18 @@ export interface CardProps extends React.HTMLProps<HTMLElement>, OUIAProps {
|
|
|
14
14
|
component?: keyof JSX.IntrinsicElements;
|
|
15
15
|
/** Modifies the card to include hover styles on :hover */
|
|
16
16
|
isHoverable?: boolean;
|
|
17
|
+
/** Modifies the card to include hoverable-raised styles on :hover, this styling is included by default with isSelectableRaised */
|
|
18
|
+
isHoverableRaised?: boolean;
|
|
17
19
|
/** Modifies the card to include compact styling. Should not be used with isLarge. */
|
|
18
20
|
isCompact?: boolean;
|
|
19
21
|
/** Modifies the card to include selectable styling */
|
|
20
22
|
isSelectable?: boolean;
|
|
21
23
|
/** Modifies the card to include selected styling */
|
|
22
24
|
isSelected?: boolean;
|
|
25
|
+
/** Modifies the card to include selectable-raised styling and hoverable-raised styling */
|
|
26
|
+
isSelectableRaised?: boolean;
|
|
27
|
+
/** Modifies the card to include selected-raised styling */
|
|
28
|
+
isSelectedRaised?: boolean;
|
|
23
29
|
/** Modifies the card to include flat styling */
|
|
24
30
|
isFlat?: boolean;
|
|
25
31
|
/** Modifies the card to include rounded styling */
|
|
@@ -50,9 +56,12 @@ export const Card: React.FunctionComponent<CardProps> = ({
|
|
|
50
56
|
className = '',
|
|
51
57
|
component = 'article',
|
|
52
58
|
isHoverable = false,
|
|
59
|
+
isHoverableRaised = false,
|
|
53
60
|
isCompact = false,
|
|
54
61
|
isSelectable = false,
|
|
55
62
|
isSelected = false,
|
|
63
|
+
isSelectableRaised = false,
|
|
64
|
+
isSelectedRaised = false,
|
|
56
65
|
isFlat = false,
|
|
57
66
|
isExpanded = false,
|
|
58
67
|
isRounded = false,
|
|
@@ -82,9 +91,12 @@ export const Card: React.FunctionComponent<CardProps> = ({
|
|
|
82
91
|
className={css(
|
|
83
92
|
styles.card,
|
|
84
93
|
isHoverable && styles.modifiers.hoverable,
|
|
94
|
+
isHoverableRaised && styles.modifiers.hoverableRaised,
|
|
85
95
|
isCompact && styles.modifiers.compact,
|
|
86
|
-
isSelectable && styles.modifiers.selectable,
|
|
87
|
-
isSelected && isSelectable && styles.modifiers.selected,
|
|
96
|
+
isSelectable && !isSelectableRaised && styles.modifiers.selectable,
|
|
97
|
+
isSelected && !isSelectedRaised && isSelectable && styles.modifiers.selected,
|
|
98
|
+
isSelectableRaised && styles.modifiers.selectableRaised,
|
|
99
|
+
isSelectedRaised && isSelectableRaised && styles.modifiers.selectedRaised,
|
|
88
100
|
isExpanded && styles.modifiers.expanded,
|
|
89
101
|
isFlat && styles.modifiers.flat,
|
|
90
102
|
isRounded && styles.modifiers.rounded,
|
|
@@ -93,7 +105,7 @@ export const Card: React.FunctionComponent<CardProps> = ({
|
|
|
93
105
|
isPlain && styles.modifiers.plain,
|
|
94
106
|
className
|
|
95
107
|
)}
|
|
96
|
-
tabIndex={isSelectable ? '0' : undefined}
|
|
108
|
+
tabIndex={isSelectableRaised || isSelectable ? '0' : undefined}
|
|
97
109
|
{...props}
|
|
98
110
|
{...ouiaProps}
|
|
99
111
|
>
|
|
@@ -35,6 +35,11 @@ test('card with isHoverable applied ', () => {
|
|
|
35
35
|
expect(view).toMatchSnapshot();
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
+
test('card with isHoverableRaised applied ', () => {
|
|
39
|
+
const view = shallow(<Card isHoverableRaised />).dive();
|
|
40
|
+
expect(view).toMatchSnapshot();
|
|
41
|
+
});
|
|
42
|
+
|
|
38
43
|
test('card with isCompact applied ', () => {
|
|
39
44
|
const view = shallow(<Card isCompact />).dive();
|
|
40
45
|
expect(view).toMatchSnapshot();
|
|
@@ -59,6 +64,25 @@ test('card with only isSelected applied - not change', () => {
|
|
|
59
64
|
expect(view.prop('tabIndex')).toBe(undefined);
|
|
60
65
|
});
|
|
61
66
|
|
|
67
|
+
test('card with isSelectableRaised applied ', () => {
|
|
68
|
+
const view = shallow(<Card isSelectableRaised />).dive();
|
|
69
|
+
expect(view.prop('className')).toMatch(/selectable-raised/);
|
|
70
|
+
expect(view.prop('tabIndex')).toBe('0');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test('card with isSelectableRaised and isSelectedRaised applied ', () => {
|
|
74
|
+
const view = shallow(<Card isSelectableRaised isSelectedRaised />).dive();
|
|
75
|
+
expect(view.prop('className')).toMatch(/selectable-raised/);
|
|
76
|
+
expect(view.prop('className')).toMatch(/selected-raised/);
|
|
77
|
+
expect(view.prop('tabIndex')).toBe('0');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('card with only isSelectedRaised applied - not change', () => {
|
|
81
|
+
const view = shallow(<Card isSelectedRaised />).dive();
|
|
82
|
+
expect(view.prop('className')).not.toMatch(/selected-raised/);
|
|
83
|
+
expect(view.prop('tabIndex')).toBe(undefined);
|
|
84
|
+
});
|
|
85
|
+
|
|
62
86
|
test('card with isFlat applied', () => {
|
|
63
87
|
const view = shallow(<Card isFlat />).dive();
|
|
64
88
|
expect(view.prop('className')).toMatch(/m-flat/);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
exports[`card with isCompact applied 1`] = `
|
|
4
4
|
<article
|
|
5
5
|
className="pf-c-card pf-m-compact"
|
|
6
|
-
data-ouia-component-id="OUIA-Generated-Card-
|
|
6
|
+
data-ouia-component-id="OUIA-Generated-Card-8"
|
|
7
7
|
data-ouia-component-type="PF4/Card"
|
|
8
8
|
data-ouia-safe={true}
|
|
9
9
|
id=""
|
|
@@ -20,6 +20,16 @@ exports[`card with isHoverable applied 1`] = `
|
|
|
20
20
|
/>
|
|
21
21
|
`;
|
|
22
22
|
|
|
23
|
+
exports[`card with isHoverableRaised applied 1`] = `
|
|
24
|
+
<article
|
|
25
|
+
className="pf-c-card pf-m-hoverable-raised"
|
|
26
|
+
data-ouia-component-id="OUIA-Generated-Card-7"
|
|
27
|
+
data-ouia-component-type="PF4/Card"
|
|
28
|
+
data-ouia-safe={true}
|
|
29
|
+
id=""
|
|
30
|
+
/>
|
|
31
|
+
`;
|
|
32
|
+
|
|
23
33
|
exports[`className is added to the root element 1`] = `"pf-c-card extra-class"`;
|
|
24
34
|
|
|
25
35
|
exports[`renders with PatternFly Core styles 1`] = `
|
|
@@ -31,21 +31,13 @@ import React from 'react';
|
|
|
31
31
|
import { Card, CardTitle, CardBody, CardFooter, Checkbox } from '@patternfly/react-core';
|
|
32
32
|
|
|
33
33
|
CardModifiers = () => {
|
|
34
|
-
const mods = [
|
|
35
|
-
'isHoverable',
|
|
36
|
-
'isCompact',
|
|
37
|
-
'isFlat',
|
|
38
|
-
'isRounded',
|
|
39
|
-
'isLarge',
|
|
40
|
-
'isFullHeight',
|
|
41
|
-
'isPlain',
|
|
42
|
-
];
|
|
34
|
+
const mods = ['isHoverable', 'isCompact', 'isFlat', 'isRounded', 'isLarge', 'isFullHeight', 'isPlain'];
|
|
43
35
|
const [modifiers, setModifiers] = React.useState({});
|
|
44
36
|
|
|
45
37
|
return (
|
|
46
38
|
<React.Fragment>
|
|
47
39
|
<div style={{ marginBottom: '12px' }}>
|
|
48
|
-
{mods.map(mod =>
|
|
40
|
+
{mods.map(mod => (
|
|
49
41
|
<Checkbox
|
|
50
42
|
id={mod}
|
|
51
43
|
key={mod}
|
|
@@ -53,10 +45,10 @@ CardModifiers = () => {
|
|
|
53
45
|
isChecked={modifiers[mod]}
|
|
54
46
|
onChange={checked => {
|
|
55
47
|
modifiers[mod] = checked;
|
|
56
|
-
setModifiers({...modifiers});
|
|
48
|
+
setModifiers({ ...modifiers });
|
|
57
49
|
}}
|
|
58
50
|
/>
|
|
59
|
-
)}
|
|
51
|
+
))}
|
|
60
52
|
</div>
|
|
61
53
|
<div style={{ height: '15rem' }}>
|
|
62
54
|
<Card {...modifiers}>
|
|
@@ -67,7 +59,7 @@ CardModifiers = () => {
|
|
|
67
59
|
</div>
|
|
68
60
|
</React.Fragment>
|
|
69
61
|
);
|
|
70
|
-
}
|
|
62
|
+
};
|
|
71
63
|
```
|
|
72
64
|
|
|
73
65
|
### With image and actions
|
|
@@ -120,7 +112,7 @@ class KebabDropdown extends React.Component {
|
|
|
120
112
|
this.setState({
|
|
121
113
|
hasNoOffset: checked
|
|
122
114
|
});
|
|
123
|
-
}
|
|
115
|
+
};
|
|
124
116
|
}
|
|
125
117
|
|
|
126
118
|
render() {
|
|
@@ -171,15 +163,15 @@ class KebabDropdown extends React.Component {
|
|
|
171
163
|
<CardBody>Body</CardBody>
|
|
172
164
|
<CardFooter>Footer</CardFooter>
|
|
173
165
|
</Card>
|
|
174
|
-
<div style={{marginTop:
|
|
166
|
+
<div style={{ marginTop: '20px' }}>
|
|
175
167
|
<Checkbox
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
168
|
+
label="actions hasNoOffset"
|
|
169
|
+
isChecked={this.state.hasNoOffset}
|
|
170
|
+
onChange={this.toggleOffset}
|
|
171
|
+
aria-label="remove actions offset"
|
|
172
|
+
id="toggle-actions-offset"
|
|
173
|
+
name="toggle-actions-offset"
|
|
174
|
+
/>
|
|
183
175
|
</div>
|
|
184
176
|
</>
|
|
185
177
|
);
|
|
@@ -483,6 +475,7 @@ class SelectableCard extends React.Component {
|
|
|
483
475
|
return;
|
|
484
476
|
}
|
|
485
477
|
if ([13, 32].includes(event.keyCode)) {
|
|
478
|
+
event.preventDefault();
|
|
486
479
|
const newSelected = event.currentTarget.id === this.state.selected ? null : event.currentTarget.id;
|
|
487
480
|
this.setState({
|
|
488
481
|
selected: newSelected
|
|
@@ -533,8 +526,8 @@ class SelectableCard extends React.Component {
|
|
|
533
526
|
id="first-card"
|
|
534
527
|
onKeyDown={this.onKeyDown}
|
|
535
528
|
onClick={this.onClick}
|
|
536
|
-
|
|
537
|
-
|
|
529
|
+
isSelectableRaised
|
|
530
|
+
isSelectedRaised={selected === 'first-card'}
|
|
538
531
|
>
|
|
539
532
|
<CardHeader>
|
|
540
533
|
<CardActions>
|
|
@@ -556,8 +549,8 @@ class SelectableCard extends React.Component {
|
|
|
556
549
|
id="second-card"
|
|
557
550
|
onKeyDown={this.onKeyDown}
|
|
558
551
|
onClick={this.onClick}
|
|
559
|
-
|
|
560
|
-
|
|
552
|
+
isSelectableRaised
|
|
553
|
+
isSelectedRaised={selected === 'second-card'}
|
|
561
554
|
>
|
|
562
555
|
<CardTitle>Second card</CardTitle>
|
|
563
556
|
<CardBody>This is a selectable card. Click me to select me. Click again to deselect me.</CardBody>
|
|
@@ -828,3 +821,117 @@ class ExpandableIconCard extends React.Component {
|
|
|
828
821
|
}
|
|
829
822
|
}
|
|
830
823
|
```
|
|
824
|
+
|
|
825
|
+
### Legacy selectable and selected
|
|
826
|
+
|
|
827
|
+
```js
|
|
828
|
+
import React from 'react';
|
|
829
|
+
import {
|
|
830
|
+
Card,
|
|
831
|
+
CardHeader,
|
|
832
|
+
CardActions,
|
|
833
|
+
CardTitle,
|
|
834
|
+
CardBody,
|
|
835
|
+
Dropdown,
|
|
836
|
+
DropdownToggle,
|
|
837
|
+
DropdownItem,
|
|
838
|
+
DropdownSeparator,
|
|
839
|
+
KebabToggle
|
|
840
|
+
} from '@patternfly/react-core';
|
|
841
|
+
|
|
842
|
+
class SelectableCard extends React.Component {
|
|
843
|
+
constructor(props) {
|
|
844
|
+
super(props);
|
|
845
|
+
this.state = {
|
|
846
|
+
selected: null
|
|
847
|
+
};
|
|
848
|
+
this.onKeyDown = event => {
|
|
849
|
+
if (event.target !== event.currentTarget) {
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
if ([13, 32].includes(event.keyCode)) {
|
|
853
|
+
event.preventDefault();
|
|
854
|
+
const newSelected = event.currentTarget.id === this.state.selected ? null : event.currentTarget.id;
|
|
855
|
+
this.setState({
|
|
856
|
+
selected: newSelected
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
this.onClick = event => {
|
|
861
|
+
const newSelected = event.currentTarget.id === this.state.selected ? null : event.currentTarget.id;
|
|
862
|
+
this.setState({
|
|
863
|
+
selected: newSelected
|
|
864
|
+
});
|
|
865
|
+
};
|
|
866
|
+
this.onToggle = (isOpen, event) => {
|
|
867
|
+
event.stopPropagation();
|
|
868
|
+
this.setState({
|
|
869
|
+
isOpen
|
|
870
|
+
});
|
|
871
|
+
};
|
|
872
|
+
this.onSelect = event => {
|
|
873
|
+
event.stopPropagation();
|
|
874
|
+
this.setState({
|
|
875
|
+
isOpen: !this.state.isOpen
|
|
876
|
+
});
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
render() {
|
|
880
|
+
const { selected, isOpen } = this.state;
|
|
881
|
+
const dropdownItems = [
|
|
882
|
+
<DropdownItem key="link">Link</DropdownItem>,
|
|
883
|
+
<DropdownItem key="action" component="button">
|
|
884
|
+
Action
|
|
885
|
+
</DropdownItem>,
|
|
886
|
+
<DropdownItem key="disabled link" isDisabled>
|
|
887
|
+
Disabled Link
|
|
888
|
+
</DropdownItem>,
|
|
889
|
+
<DropdownItem key="disabled action" isDisabled component="button">
|
|
890
|
+
Disabled Action
|
|
891
|
+
</DropdownItem>,
|
|
892
|
+
<DropdownSeparator key="separator" />,
|
|
893
|
+
<DropdownItem key="separated link">Separated Link</DropdownItem>,
|
|
894
|
+
<DropdownItem key="separated action" component="button">
|
|
895
|
+
Separated Action
|
|
896
|
+
</DropdownItem>
|
|
897
|
+
];
|
|
898
|
+
return (
|
|
899
|
+
<>
|
|
900
|
+
<Card
|
|
901
|
+
id="first-card"
|
|
902
|
+
onKeyDown={this.onKeyDown}
|
|
903
|
+
onClick={this.onClick}
|
|
904
|
+
isSelectable
|
|
905
|
+
isSelected={selected === 'first-card'}
|
|
906
|
+
>
|
|
907
|
+
<CardHeader>
|
|
908
|
+
<CardActions>
|
|
909
|
+
<Dropdown
|
|
910
|
+
onSelect={this.onSelect}
|
|
911
|
+
toggle={<KebabToggle onToggle={this.onToggle} />}
|
|
912
|
+
isOpen={isOpen}
|
|
913
|
+
isPlain
|
|
914
|
+
dropdownItems={dropdownItems}
|
|
915
|
+
position={'right'}
|
|
916
|
+
/>
|
|
917
|
+
</CardActions>
|
|
918
|
+
</CardHeader>
|
|
919
|
+
<CardTitle>First card</CardTitle>
|
|
920
|
+
<CardBody>This is a selectable card. Click me to select me. Click again to deselect me.</CardBody>
|
|
921
|
+
</Card>
|
|
922
|
+
<br />
|
|
923
|
+
<Card
|
|
924
|
+
id="second-card"
|
|
925
|
+
onKeyDown={this.onKeyDown}
|
|
926
|
+
onClick={this.onClick}
|
|
927
|
+
isSelectable
|
|
928
|
+
isSelected={selected === 'second-card'}
|
|
929
|
+
>
|
|
930
|
+
<CardTitle>Second card</CardTitle>
|
|
931
|
+
<CardBody>This is a selectable card. Click me to select me. Click again to deselect me.</CardBody>
|
|
932
|
+
</Card>
|
|
933
|
+
</>
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
```
|
|
@@ -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]}
|
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]}
|