You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/react-core/src/components/FileUpload/examples/FileUpload.md
+51-3Lines changed: 51 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,11 @@ section: 'components'
7
7
beta: true
8
8
---
9
9
10
-
import { FileUpload } from '@patternfly/react-core';
10
+
import { FileUpload, Form, FormGroup } from '@patternfly/react-core';
11
11
12
12
## Examples
13
13
14
-
The basic `FileUpload` component can handle simple text files, loading them into memory and passing their contents as a string to an `onChange` prop. It uses the `react-dropzone` library to provide the file browse dialog and drag/drop behavior. Any props accepted by `react-dropzone` can be passed as a `dropzoneProps` object in order to customize the behavior of the Dropzone.
14
+
The basic `FileUpload` component can handle simple text files via browse or drag-and-drop, loading them into memory and passing their contents as a string to an `onChange` prop.
15
15
16
16
```js title=Simple-text-file isBeta
17
17
importReactfrom'react';
@@ -33,7 +33,55 @@ class SimpleTextFileUpload extends React.Component {
33
33
}
34
34
```
35
35
36
-
`FileUpload` is a thin wrapper around the `FileUploadField` presentational component. If you need to implement your own logic for reading or displaying a file, you can instead render a `FileUploadField` directly, which requires additional props (you must implement your own `onBrowseButtonClick` handler, etc).
36
+
Any [props accepted by `react-dropzone`'s `Dropzone` component](https://react-dropzone.js.org/#!/Dropzone) can be passed as a `dropzoneProps` object in order to customize the behavior of the Dropzone, such as restricting the size and type of files allowed. This example will only accept CSV files smaller than 1 KB.
helperTextInvalid="Must be a CSV file no larger than 1 KB"
62
+
validated={rejected ?'error':'default'}
63
+
>
64
+
<FileUpload
65
+
id="simple-text-file-with-restrictions"
66
+
value={value}
67
+
filename={filename}
68
+
onChange={this.handleFileChange}
69
+
dropzoneProps={{
70
+
accept:'.csv',
71
+
maxSize:1024,
72
+
onDropAccepted:this.handleFileAccepted,
73
+
onDropRejected:this.handleFileRejected
74
+
}}
75
+
validated={rejected ?'error':'default'}
76
+
/>
77
+
</FormGroup>
78
+
</Form>
79
+
);
80
+
}
81
+
}
82
+
```
83
+
84
+
`FileUpload` is a thin wrapper around the `FileUploadField` presentational component. If you need to implement your own logic for accepting, reading or displaying files, you can instead render a `FileUploadField` directly, which requires additional props (e.g. `onBrowseButtonClick`, `isDragActive`).
0 commit comments