@patternfly/react-core 4.221.10 → 4.221.13

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 (39) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/esm/components/Drawer/Drawer.d.ts +1 -0
  3. package/dist/esm/components/Drawer/Drawer.d.ts.map +1 -1
  4. package/dist/esm/components/Drawer/Drawer.js +3 -1
  5. package/dist/esm/components/Drawer/Drawer.js.map +1 -1
  6. package/dist/esm/components/Drawer/DrawerContent.d.ts.map +1 -1
  7. package/dist/esm/components/Drawer/DrawerContent.js +3 -3
  8. package/dist/esm/components/Drawer/DrawerContent.js.map +1 -1
  9. package/dist/esm/components/Drawer/DrawerPanelContent.d.ts +0 -2
  10. package/dist/esm/components/Drawer/DrawerPanelContent.d.ts.map +1 -1
  11. package/dist/esm/components/Drawer/DrawerPanelContent.js +2 -2
  12. package/dist/esm/components/Drawer/DrawerPanelContent.js.map +1 -1
  13. package/dist/js/components/Drawer/Drawer.d.ts +1 -0
  14. package/dist/js/components/Drawer/Drawer.d.ts.map +1 -1
  15. package/dist/js/components/Drawer/Drawer.js +3 -1
  16. package/dist/js/components/Drawer/Drawer.js.map +1 -1
  17. package/dist/js/components/Drawer/DrawerContent.d.ts.map +1 -1
  18. package/dist/js/components/Drawer/DrawerContent.js +2 -2
  19. package/dist/js/components/Drawer/DrawerContent.js.map +1 -1
  20. package/dist/js/components/Drawer/DrawerPanelContent.d.ts +0 -2
  21. package/dist/js/components/Drawer/DrawerPanelContent.d.ts.map +1 -1
  22. package/dist/js/components/Drawer/DrawerPanelContent.js +2 -2
  23. package/dist/js/components/Drawer/DrawerPanelContent.js.map +1 -1
  24. package/dist/umd/react-core.js +7 -5
  25. package/dist/umd/react-core.min.js +1 -1
  26. package/package.json +5 -5
  27. package/src/components/Drawer/Drawer.tsx +5 -1
  28. package/src/components/Drawer/DrawerContent.tsx +4 -3
  29. package/src/components/Drawer/DrawerPanelContent.tsx +3 -4
  30. package/src/components/Drawer/__tests__/Drawer.test.tsx +38 -1
  31. package/src/components/Drawer/__tests__/Generated/__snapshots__/DrawerContent.test.tsx.snap +1 -3
  32. package/src/components/ExpandableSection/examples/ExpandableSection.md +7 -187
  33. package/src/components/ExpandableSection/examples/ExpandableSectionBasic.tsx +16 -0
  34. package/src/components/ExpandableSection/examples/ExpandableSectionCustomToggle.tsx +29 -0
  35. package/src/components/ExpandableSection/examples/ExpandableSectionDetached.tsx +26 -0
  36. package/src/components/ExpandableSection/examples/ExpandableSectionDisclosure.tsx +22 -0
  37. package/src/components/ExpandableSection/examples/ExpandableSectionIndented.tsx +21 -0
  38. package/src/components/ExpandableSection/examples/ExpandableSectionUncontrolled.tsx +8 -0
  39. package/src/components/ExpandableSection/examples/ExpandableSectionUncontrolledDynamicToggleText.tsx +8 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.221.10",
3
+ "version": "4.221.13",
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,9 +34,9 @@
34
34
  "generate": "node scripts/copyStyles.js"
35
35
  },
36
36
  "dependencies": {
37
- "@patternfly/react-icons": "^4.72.10",
38
- "@patternfly/react-styles": "^4.71.10",
39
- "@patternfly/react-tokens": "^4.73.10",
37
+ "@patternfly/react-icons": "^4.72.13",
38
+ "@patternfly/react-styles": "^4.71.13",
39
+ "@patternfly/react-tokens": "^4.73.13",
40
40
  "focus-trap": "6.9.2",
41
41
  "react-dropzone": "9.0.0",
42
42
  "tippy.js": "5.1.2",
@@ -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": "4c074ff2399b6dd544baff5536a61b73cbcb1fb0"
63
+ "gitHead": "c2e4c2796b6768e5f4c816c271593d3b45de219d"
64
64
  }
@@ -30,6 +30,7 @@ export interface DrawerContextProps {
30
30
  onExpand?: () => void;
31
31
  position?: string;
32
32
  drawerRef?: React.RefObject<HTMLDivElement>;
33
+ drawerContentRef?: React.RefObject<HTMLDivElement>;
33
34
  isInline: boolean;
34
35
  }
35
36
 
@@ -39,6 +40,7 @@ export const DrawerContext = React.createContext<Partial<DrawerContextProps>>({
39
40
  onExpand: () => {},
40
41
  position: 'right',
41
42
  drawerRef: null,
43
+ drawerContentRef: null,
42
44
  isInline: false
43
45
  });
44
46
 
@@ -53,8 +55,10 @@ export const Drawer: React.FunctionComponent<DrawerProps> = ({
53
55
  ...props
54
56
  }: DrawerProps) => {
55
57
  const drawerRef = React.useRef<HTMLDivElement>();
58
+ const drawerContentRef = React.useRef<HTMLDivElement>();
59
+
56
60
  return (
57
- <DrawerContext.Provider value={{ isExpanded, isStatic, onExpand, position, drawerRef, isInline }}>
61
+ <DrawerContext.Provider value={{ isExpanded, isStatic, onExpand, position, drawerRef, drawerContentRef, isInline }}>
58
62
  <div
59
63
  className={css(
60
64
  styles.drawer,
@@ -2,7 +2,7 @@ import * as React from 'react';
2
2
  import styles from '@patternfly/react-styles/css/components/Drawer/drawer';
3
3
  import { css } from '@patternfly/react-styles';
4
4
  import { DrawerMain } from './DrawerMain';
5
- import { DrawerColorVariant } from './Drawer';
5
+ import { DrawerColorVariant, DrawerContext } from './Drawer';
6
6
 
7
7
  export interface DrawerContentProps extends React.HTMLProps<HTMLDivElement> {
8
8
  /** Additional classes added to the Drawer. */
@@ -23,7 +23,8 @@ export const DrawerContent: React.FunctionComponent<DrawerContentProps> = ({
23
23
  colorVariant = DrawerColorVariant.default,
24
24
  ...props
25
25
  }: DrawerContentProps) => {
26
- const drawerContentRef = React.useRef<HTMLDivElement>();
26
+ const { drawerContentRef } = React.useContext(DrawerContext);
27
+
27
28
  return (
28
29
  <DrawerMain>
29
30
  <div
@@ -37,7 +38,7 @@ export const DrawerContent: React.FunctionComponent<DrawerContentProps> = ({
37
38
  >
38
39
  {children}
39
40
  </div>
40
- {panelContent && React.cloneElement(panelContent as React.ReactElement, { drawerContentRef })}
41
+ {panelContent}
41
42
  </DrawerMain>
42
43
  );
43
44
  };
@@ -37,8 +37,6 @@ export interface DrawerPanelContentProps extends React.HTMLProps<HTMLDivElement>
37
37
  };
38
38
  /** Color variant of the background of the drawer panel */
39
39
  colorVariant?: DrawerColorVariant | 'light-200' | 'default';
40
- /** @hide Internal ref to drawer content */
41
- drawerContentRef?: React.RefObject<HTMLDivElement>;
42
40
  }
43
41
  let isResizing: boolean = null;
44
42
  let newSize: number = 0;
@@ -57,13 +55,14 @@ export const DrawerPanelContent: React.FunctionComponent<DrawerPanelContentProps
57
55
  resizeAriaLabel = 'Resize',
58
56
  widths,
59
57
  colorVariant = DrawerColorVariant.default,
60
- drawerContentRef,
61
58
  ...props
62
59
  }: DrawerPanelContentProps) => {
63
60
  const panel = React.useRef<HTMLDivElement>();
64
61
  const splitterRef = React.useRef<HTMLDivElement>();
65
62
  const [separatorValue, setSeparatorValue] = React.useState(0);
66
- const { position, isExpanded, isStatic, onExpand, drawerRef, isInline } = React.useContext(DrawerContext);
63
+ const { position, isExpanded, isStatic, onExpand, drawerRef, drawerContentRef, isInline } = React.useContext(
64
+ DrawerContext
65
+ );
67
66
  const hidden = isStatic ? false : !isExpanded;
68
67
  const [isExpandedInternal, setIsExpandedInternal] = React.useState(!hidden);
69
68
  let currWidth: number = 0;
@@ -10,7 +10,8 @@ import {
10
10
  DrawerPanelContent
11
11
  } from '../';
12
12
  import React from 'react';
13
- import { render } from '@testing-library/react';
13
+ import { render, screen } from '@testing-library/react';
14
+ import userEvent from '@testing-library/user-event';
14
15
 
15
16
  Object.values([
16
17
  { isExpanded: true, isInline: false, isStatic: false },
@@ -124,3 +125,39 @@ test(`Drawer has resizable callback and id`, () => {
124
125
  );
125
126
  expect(asFragment()).toMatchSnapshot();
126
127
  });
128
+
129
+ test('Resizeable DrawerPanelContent can be wrapped in a context without causing an error', () => {
130
+ const TestContext = React.createContext({});
131
+
132
+ const consoleError = jest.spyOn(console, 'error').mockImplementation();
133
+
134
+ const panelContent = (
135
+ <TestContext.Provider value={{}}>
136
+ <DrawerPanelContent
137
+ isResizable
138
+ >
139
+ <DrawerHead>
140
+ <span>
141
+ drawer-panel
142
+ </span>
143
+ <DrawerActions>
144
+ <DrawerCloseButton />
145
+ </DrawerActions>
146
+ </DrawerHead>
147
+ </DrawerPanelContent>
148
+ </TestContext.Provider>
149
+ );
150
+
151
+ render(
152
+ <Drawer isExpanded={true} position="left">
153
+ <DrawerContent panelContent={panelContent}>
154
+ <DrawerContentBody>Drawer content text</DrawerContentBody>
155
+ </DrawerContent>
156
+ </Drawer>
157
+ );
158
+
159
+ userEvent.tab();
160
+ userEvent.keyboard('{arrowleft}');
161
+
162
+ expect(consoleError).not.toHaveBeenCalled();
163
+ })
@@ -12,9 +12,7 @@ exports[`DrawerContent should match snapshot (auto-generated) 1`] = `
12
12
  ReactNode
13
13
  </div>
14
14
  </div>
15
- <div
16
- drawercontentref="[object Object]"
17
- >
15
+ <div>
18
16
  test
19
17
  </div>
20
18
  </div>
@@ -11,217 +11,37 @@ import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle
11
11
 
12
12
  ### Basic
13
13
 
14
- ```js
15
- import React from 'react';
16
- import { ExpandableSection } from '@patternfly/react-core';
17
-
18
- class SimpleExpandableSection extends React.Component {
19
- constructor(props) {
20
- super(props);
21
- this.state = {
22
- isExpanded: false
23
- };
24
- this.onToggle = isExpanded => {
25
- this.setState({
26
- isExpanded
27
- });
28
- };
29
- }
30
-
31
- render() {
32
- const { isExpanded } = this.state;
33
- return (
34
- <ExpandableSection
35
- toggleText={isExpanded ? 'Show less' : 'Show more'}
36
- onToggle={this.onToggle}
37
- isExpanded={isExpanded}
38
- >
39
- This content is visible only when the component is expanded.
40
- </ExpandableSection>
41
- );
42
- }
43
- }
14
+ ```ts file="ExpandableSectionBasic.tsx"
44
15
  ```
45
16
 
46
17
  ### Uncontrolled
47
18
 
48
- ```js
49
- import React from 'react';
50
- import { ExpandableSection } from '@patternfly/react-core';
51
-
52
- <ExpandableSection toggleText="Show more">
53
- This content is visible only when the component is expanded.
54
- </ExpandableSection>;
19
+ ```ts file="ExpandableSectionUncontrolled.tsx"
55
20
  ```
56
21
 
57
22
  ### Uncontrolled with dynamic toggle text
58
23
 
59
- ```js
60
- import React from 'react';
61
- import { ExpandableSection } from '@patternfly/react-core';
62
-
63
- <ExpandableSection toggleTextExpanded="Show less" toggleTextCollapsed="Show more">
64
- This content is visible only when the component is expanded.
65
- </ExpandableSection>;
24
+ ```ts file="ExpandableSectionUncontrolledDynamicToggleText.tsx"
66
25
  ```
67
26
 
68
27
  ### Detached
69
28
 
70
- ```js
71
- import React from 'react';
72
- import { ExpandableSection, ExpandableSectionToggle, Stack, StackItem } from '@patternfly/react-core';
73
-
74
- class DetachedExpandableSection extends React.Component {
75
- constructor(props) {
76
- super(props);
77
- this.state = {
78
- isExpanded: false
79
- };
80
- this.onToggle = isExpanded => {
81
- this.setState({
82
- isExpanded
83
- });
84
- };
85
- }
86
-
87
- render() {
88
- const { isExpanded } = this.state;
89
- const contentId = 'detached-toggle-content';
90
- return (
91
- <Stack hasGutter>
92
- <StackItem>
93
- <ExpandableSection isExpanded={isExpanded} isDetached contentId={contentId}>
94
- This content is visible only when the component is expanded.
95
- </ExpandableSection>
96
- </StackItem>
97
- <StackItem>
98
- <ExpandableSectionToggle
99
- isExpanded={isExpanded}
100
- onToggle={this.onToggle}
101
- contentId={contentId}
102
- direction="up"
103
- >
104
- {isExpanded ? 'Show less' : 'Show more'}
105
- </ExpandableSectionToggle>
106
- </StackItem>
107
- </Stack>
108
- );
109
- }
110
- }
29
+ ```ts file="ExpandableSectionDetached.tsx"
111
30
  ```
112
31
 
113
32
  ### Disclosure variation
114
33
 
115
- ```js
116
- import React from 'react';
117
- import { ExpandableSection } from '@patternfly/react-core';
118
-
119
- class DisclosureExpandableSection extends React.Component {
120
- constructor(props) {
121
- super(props);
122
- this.state = {
123
- isExpanded: false
124
- };
125
- this.onToggle = isExpanded => {
126
- this.setState({
127
- isExpanded
128
- });
129
- };
130
- }
131
-
132
- render() {
133
- const { isExpanded } = this.state;
134
- return (
135
- <ExpandableSection
136
- toggleText={isExpanded ? 'Show less' : 'Show more'}
137
- onToggle={this.onToggle}
138
- isExpanded={isExpanded}
139
- displaySize="large"
140
- isWidthLimited
141
- >
142
- This content is visible only when the component is expanded.
143
- </ExpandableSection>
144
- );
145
- }
146
- }
34
+ ```ts file="ExpandableSectionDisclosure.tsx"
147
35
  ```
148
36
 
149
37
  ### Indented
150
38
 
151
- ```js
152
- import React from 'react';
153
- import { ExpandableSection } from '@patternfly/react-core';
154
-
155
- class SimpleExpandableSection extends React.Component {
156
- constructor(props) {
157
- super(props);
158
- this.state = {
159
- isExpanded: false
160
- };
161
- this.onToggle = isExpanded => {
162
- this.setState({
163
- isExpanded
164
- });
165
- };
166
- }
167
-
168
- render() {
169
- const { isExpanded } = this.state;
170
- return (
171
- <ExpandableSection
172
- toggleText={isExpanded ? 'Show less' : 'Show more'}
173
- onToggle={this.onToggle}
174
- isExpanded={isExpanded}
175
- isIndented={true}
176
- >
177
- This content is visible only when the component is expanded.
178
- </ExpandableSection>
179
- );
180
- }
181
- }
39
+ ```ts file="ExpandableSectionIndented.tsx"
182
40
  ```
183
41
 
184
42
  ### With custom toggle content
185
43
 
186
44
  By using the `toggleContent` prop, you can pass in content other than a simple string such as an icon or a badge. When passing in custom content in this way, you should not pass in any interactive element such as a button.
187
45
 
188
- ```js
189
- import React from "react";
190
- import { ExpandableSection, Badge } from "@patternfly/react-core";
191
- import CheckCircleIcon from "@patternfly/react-icons/dist/esm/icons/check-circle-icon";
192
-
193
- class CustomExpandableSection extends React.Component {
194
- constructor(props) {
195
- super(props);
196
- this.state = {
197
- isExpanded: false
198
- };
199
- this.onToggle = (isExpanded) => {
200
- this.setState({
201
- isExpanded
202
- });
203
- };
204
- }
205
-
206
- render() {
207
- const { isExpanded } = this.state;
208
- return (
209
- <ExpandableSection
210
- toggleContent={
211
- <div>
212
- <span>You can also use icons </span>
213
- <CheckCircleIcon />
214
- <span> or badges </span>
215
- <Badge isRead={true}>4</Badge>
216
- <span> !</span>
217
- </div>
218
- }
219
- onToggle={this.onToggle}
220
- isExpanded={isExpanded}
221
- >
222
- This content is visible only when the component is expanded.
223
- </ExpandableSection>
224
- );
225
- }
226
- }
46
+ ```ts file="ExpandableSectionCustomToggle.tsx"
227
47
  ```
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { ExpandableSection } from '@patternfly/react-core';
3
+
4
+ export const ExpandableSectionBasic: React.FunctionComponent = () => {
5
+ const [isExpanded, setIsExpanded] = React.useState(false);
6
+
7
+ const onToggle = (isExpanded: boolean) => {
8
+ setIsExpanded(isExpanded);
9
+ };
10
+
11
+ return (
12
+ <ExpandableSection toggleText={isExpanded ? 'Show less' : 'Show more'} onToggle={onToggle} isExpanded={isExpanded}>
13
+ This content is visible only when the component is expanded.
14
+ </ExpandableSection>
15
+ );
16
+ };
@@ -0,0 +1,29 @@
1
+ import React from 'react';
2
+ import { ExpandableSection, Badge } from '@patternfly/react-core';
3
+ import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon';
4
+
5
+ export const ExpandableSectionCustomToggle: React.FunctionComponent = () => {
6
+ const [isExpanded, setIsExpanded] = React.useState(false);
7
+
8
+ const onToggle = (isExpanded: boolean) => {
9
+ setIsExpanded(isExpanded);
10
+ };
11
+
12
+ return (
13
+ <ExpandableSection
14
+ toggleContent={
15
+ <div>
16
+ <span>You can also use icons </span>
17
+ <CheckCircleIcon />
18
+ <span> or badges </span>
19
+ <Badge isRead={true}>4</Badge>
20
+ <span> !</span>
21
+ </div>
22
+ }
23
+ onToggle={onToggle}
24
+ isExpanded={isExpanded}
25
+ >
26
+ This content is visible only when the component is expanded.
27
+ </ExpandableSection>
28
+ );
29
+ };
@@ -0,0 +1,26 @@
1
+ import React from 'react';
2
+ import { ExpandableSection, ExpandableSectionToggle, Stack, StackItem } from '@patternfly/react-core';
3
+
4
+ export const ExpandableSectionDetached: React.FunctionComponent = () => {
5
+ const [isExpanded, setIsExpanded] = React.useState(false);
6
+
7
+ const onToggle = (isExpanded: boolean) => {
8
+ setIsExpanded(isExpanded);
9
+ };
10
+
11
+ const contentId = 'detached-toggle-content';
12
+ return (
13
+ <Stack hasGutter>
14
+ <StackItem>
15
+ <ExpandableSection isExpanded={isExpanded} isDetached contentId={contentId}>
16
+ This content is visible only when the component is expanded.
17
+ </ExpandableSection>
18
+ </StackItem>
19
+ <StackItem>
20
+ <ExpandableSectionToggle isExpanded={isExpanded} onToggle={onToggle} contentId={contentId} direction="up">
21
+ {isExpanded ? 'Show less' : 'Show more'}
22
+ </ExpandableSectionToggle>
23
+ </StackItem>
24
+ </Stack>
25
+ );
26
+ };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import { ExpandableSection } from '@patternfly/react-core';
3
+
4
+ export const ExpandableSectionDisclosure: React.FunctionComponent = () => {
5
+ const [isExpanded, setIsExpanded] = React.useState(false);
6
+
7
+ const onToggle = (isExpanded: boolean) => {
8
+ setIsExpanded(isExpanded);
9
+ };
10
+
11
+ return (
12
+ <ExpandableSection
13
+ toggleText={isExpanded ? 'Show less' : 'Show more'}
14
+ onToggle={onToggle}
15
+ isExpanded={isExpanded}
16
+ displaySize="large"
17
+ isWidthLimited
18
+ >
19
+ This content is visible only when the component is expanded.
20
+ </ExpandableSection>
21
+ );
22
+ };
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { ExpandableSection } from '@patternfly/react-core';
3
+
4
+ export const ExpandableSectionIndented: React.FunctionComponent = () => {
5
+ const [isExpanded, setIsExpanded] = React.useState(false);
6
+
7
+ const onToggle = (isExpanded: boolean) => {
8
+ setIsExpanded(isExpanded);
9
+ };
10
+
11
+ return (
12
+ <ExpandableSection
13
+ toggleText={isExpanded ? 'Show less' : 'Show more'}
14
+ onToggle={onToggle}
15
+ isExpanded={isExpanded}
16
+ isIndented
17
+ >
18
+ This content is visible only when the component is expanded.
19
+ </ExpandableSection>
20
+ );
21
+ };
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { ExpandableSection } from '@patternfly/react-core';
3
+
4
+ export const ExpandableSectionUncontrolled: React.FunctionComponent = () => (
5
+ <ExpandableSection toggleText="Show more">
6
+ This content is visible only when the component is expanded.
7
+ </ExpandableSection>
8
+ );
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { ExpandableSection } from '@patternfly/react-core';
3
+
4
+ export const ExpandableSectionUncontrolledDynamicToggle: React.FunctionComponent = () => (
5
+ <ExpandableSection toggleTextExpanded="Show less" toggleTextCollapsed="Show more">
6
+ This content is visible only when the component is expanded.
7
+ </ExpandableSection>
8
+ );