@patternfly/react-core 4.260.1 → 4.261.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.260.1",
3
+ "version": "4.261.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",
@@ -70,5 +70,5 @@
70
70
  "react": "^16.8 || ^17 || ^18",
71
71
  "react-dom": "^16.8 || ^17 || ^18"
72
72
  },
73
- "gitHead": "246184250fd0b32f33c87a9226b9cd621c30c16e"
73
+ "gitHead": "5d1af989ad4a302d1fa53c4658f033ad0fa1abef"
74
74
  }
@@ -54,6 +54,8 @@ export interface MultipleFileUploadStatusItemProps extends React.HTMLProps<HTMLL
54
54
  progressAriaLiveMessage?: string | ((loadPercentage: number) => string);
55
55
  /** Unique identifier for progress. Generated if not specified. */
56
56
  progressId?: string;
57
+ /** @beta Additional content related to the status item. */
58
+ progressHelperText?: React.ReactNode;
57
59
  }
58
60
 
59
61
  export const MultipleFileUploadStatusItem: React.FunctionComponent<MultipleFileUploadStatusItemProps> = ({
@@ -75,6 +77,7 @@ export const MultipleFileUploadStatusItem: React.FunctionComponent<MultipleFileU
75
77
  progressId,
76
78
  progressAriaLiveMessage,
77
79
  buttonAriaLabel = 'Remove from list',
80
+ progressHelperText,
78
81
  ...props
79
82
  }: MultipleFileUploadStatusItemProps) => {
80
83
  const [loadPercentage, setLoadPercentage] = React.useState(0);
@@ -129,6 +132,9 @@ export const MultipleFileUploadStatusItem: React.FunctionComponent<MultipleFileU
129
132
  return `${Math.round(size)}${prefixes[prefixUnit]}B`;
130
133
  };
131
134
 
135
+ const value = progressValue || loadPercentage;
136
+ const variant = progressVariant || loadResult;
137
+
132
138
  const title = (
133
139
  <span className={styles.multipleFileUploadStatusItemProgress}>
134
140
  <span className={styles.multipleFileUploadStatusItemProgressText}>{fileName || file?.name || ''}</span>
@@ -151,11 +157,12 @@ export const MultipleFileUploadStatusItem: React.FunctionComponent<MultipleFileU
151
157
  </div>
152
158
  <Progress
153
159
  title={title}
154
- value={progressValue || loadPercentage}
155
- variant={progressVariant || loadResult}
160
+ value={value}
161
+ variant={variant}
156
162
  aria-label={progressAriaLabel}
157
163
  aria-labelledby={progressAriaLabelledBy}
158
164
  id={progressId}
165
+ helperText={progressHelperText}
159
166
  />
160
167
  </div>
161
168
  <div className={styles.multipleFileUploadStatusItemClose}>
@@ -99,3 +99,38 @@ describe('MultipleFileUploadStatusItem', () => {
99
99
  expect(asFragment()).toMatchSnapshot();
100
100
  });
101
101
  });
102
+
103
+ test('does not render helper text by default', () => {
104
+ const testFile = new File(['foo'], 'testFile.txt');
105
+ render(
106
+ <MultipleFileUploadStatusItem
107
+ file={testFile}
108
+ buttonAriaLabel="buttonAriaLabel"
109
+ progressAriaLabel="progressAriaLabel"
110
+ progressAriaLabelledBy="progressAriaLabelledBy"
111
+ progressId="test-progress-id"
112
+ />
113
+ );
114
+
115
+ const helperText = screen.queryByText('Test helper text');
116
+
117
+ expect(helperText).not.toBeInTheDocument();
118
+ });
119
+
120
+ test('renders helper text', () => {
121
+ const testFile = new File(['foo'], 'testFile.txt');
122
+ render(
123
+ <MultipleFileUploadStatusItem
124
+ file={testFile}
125
+ buttonAriaLabel="buttonAriaLabel"
126
+ progressAriaLabel="progressAriaLabel"
127
+ progressAriaLabelledBy="progressAriaLabelledBy"
128
+ progressId="test-progress-id"
129
+ progressHelperText="Test helper text"
130
+ />
131
+ );
132
+
133
+ const helperText = screen.getByText('Test helper text');
134
+
135
+ expect(helperText).toBeVisible();
136
+ });
@@ -42,5 +42,11 @@ File upload - multiple is designed in a composable manner to make customization
42
42
 
43
43
  ### Basic
44
44
 
45
+ The below example demonstrates a typical application of file upload - multiple, with a few tweaks from that typical application to enhance the convenience of the example.
46
+
47
+ The "Show as horizontal" checkbox can be used to easily toggle the `isHorizontal` prop, showing our available styling variations.
48
+
49
+ The "Demonstrate error reporting by forcing uploads to fail" checkbox shows how our `progressHelperText` prop can be used to provide status messages to users, such as when a file fails to upload. While this checkbox is checked it will cause any file uploaded to automatically fail the file reading process, and helper text will be dynamically rendered which informs the user of that error.
50
+
45
51
  ```ts file="./MultipleFileUploadBasic.tsx"
46
52
  ```
@@ -4,7 +4,9 @@ import {
4
4
  MultipleFileUploadMain,
5
5
  MultipleFileUploadStatus,
6
6
  MultipleFileUploadStatusItem,
7
- Checkbox
7
+ Checkbox,
8
+ HelperText,
9
+ HelperTextItem
8
10
  } from '@patternfly/react-core';
9
11
  import UploadIcon from '@patternfly/react-icons/dist/esm/icons/upload-icon';
10
12
 
@@ -17,6 +19,7 @@ interface readFile {
17
19
 
18
20
  export const MultipleFileUploadBasic: React.FunctionComponent = () => {
19
21
  const [isHorizontal, setIsHorizontal] = React.useState(false);
22
+ const [fileUploadShouldFail, setFileUploadShouldFail] = React.useState(false);
20
23
  const [currentFiles, setCurrentFiles] = React.useState<File[]>([]);
21
24
  const [readFileData, setReadFileData] = React.useState<readFile[]>([]);
22
25
  const [showStatus, setShowStatus] = React.useState(false);
@@ -53,6 +56,17 @@ export const MultipleFileUploadBasic: React.FunctionComponent = () => {
53
56
  setReadFileData(newReadFiles);
54
57
  };
55
58
 
59
+ /** Forces uploaded files to become corrupted if "Demonstrate error reporting by forcing uploads to fail" is selected in the example,
60
+ * only used in this example for demonstration purposes */
61
+ const updateCurrentFiles = (files: File[]) => {
62
+ if (fileUploadShouldFail) {
63
+ const corruptedFiles = files.map(file => ({ ...file, lastModified: ('foo' as unknown) as number }));
64
+ setCurrentFiles(prevFiles => [...prevFiles, ...corruptedFiles]);
65
+ } else {
66
+ setCurrentFiles(prevFiles => [...prevFiles, ...files]);
67
+ }
68
+ };
69
+
56
70
  // callback that will be called by the react dropzone with the newly dropped file objects
57
71
  const handleFileDrop = (droppedFiles: File[]) => {
58
72
  // identify what, if any, files are re-uploads of already uploaded files
@@ -63,7 +77,7 @@ export const MultipleFileUploadBasic: React.FunctionComponent = () => {
63
77
  * won't realize that the status items for the re-uploaded files needs to be re-rendered */
64
78
  Promise.resolve()
65
79
  .then(() => removeFiles(reUploads.map(file => file.name)))
66
- .then(() => setCurrentFiles(prevFiles => [...prevFiles, ...droppedFiles]));
80
+ .then(() => updateCurrentFiles(droppedFiles));
67
81
  };
68
82
 
69
83
  // callback called by the status item when a file is successfully read with the built-in file reader
@@ -79,6 +93,18 @@ export const MultipleFileUploadBasic: React.FunctionComponent = () => {
79
93
  ]);
80
94
  };
81
95
 
96
+ // add helper text to a status item showing any error encountered during the file reading process
97
+ const createHelperText = (file: File) => {
98
+ const fileResult = readFileData.find(readFile => readFile.fileName === file.name);
99
+ if (fileResult?.loadError) {
100
+ return (
101
+ <HelperText isLiveRegion>
102
+ <HelperTextItem variant={'error'}>{fileResult.loadError.toString()}</HelperTextItem>
103
+ </HelperText>
104
+ );
105
+ }
106
+ };
107
+
82
108
  const successfullyReadFileCount = readFileData.filter(fileData => fileData.loadResult === 'success').length;
83
109
 
84
110
  return (
@@ -108,6 +134,7 @@ export const MultipleFileUploadBasic: React.FunctionComponent = () => {
108
134
  onClearClick={() => removeFiles([file.name])}
109
135
  onReadSuccess={handleReadSuccess}
110
136
  onReadFail={handleReadFail}
137
+ progressHelperText={createHelperText(file)}
111
138
  />
112
139
  ))}
113
140
  </MultipleFileUploadStatus>
@@ -119,6 +146,12 @@ export const MultipleFileUploadBasic: React.FunctionComponent = () => {
119
146
  isChecked={isHorizontal}
120
147
  onChange={() => setIsHorizontal(!isHorizontal)}
121
148
  />
149
+ <Checkbox
150
+ id="upload-should-fail-checkbox"
151
+ label="Demonstrate error reporting by forcing uploads to fail"
152
+ isChecked={fileUploadShouldFail}
153
+ onChange={() => setFileUploadShouldFail(!fileUploadShouldFail)}
154
+ />
122
155
  </>
123
156
  );
124
157
  };