Debian Codegraph @

node/@patternfly/react-core/src/components/FileUpload/examples/FileUploadWithHelperText.tsx

raw
1 import { useState } from 'react';
2 import { FileUpload, FileUploadHelperText, HelperText, HelperTextItem, DropEvent } from '@patternfly/react-core';
3
4 export const FileUploadWithHelperText: React.FunctionComponent = () => {
5 const [value, setValue] = useState('');
6 const [filename, setFilename] = useState('');
7 const [isLoading, setIsLoading] = useState(false);
8
9 const handleFileInputChange = (_, file: File) => {
10 setFilename(file.name);
11 };
12
13 const handleTextChange = (_event: React.ChangeEvent<HTMLTextAreaElement>, value: string) => {
14 setValue(value);
15 };
16
17 const handleDataChange = (_event: DropEvent, value: string) => {
18 setValue(value);
19 };
20
21 const handleClear = (_event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
22 setFilename('');
23 setValue('');
24 };
25
26 const handleFileReadStarted = (_event: DropEvent, _fileHandle: File) => {
27 setIsLoading(true);
28 };
29
30 const handleFileReadFinished = (_event: DropEvent, _fileHandle: File) => {
31 setIsLoading(false);
32 };
33
34 return (
35 <FileUpload
36 id="file-upload-helper-text"
37 type="text"
38 value={value}
39 filename={filename}
40 filenamePlaceholder="Drag and drop a file or upload one"
41 onFileInputChange={handleFileInputChange}
42 onDataChange={handleDataChange}
43 onTextChange={handleTextChange}
44 onReadStarted={handleFileReadStarted}
45 onReadFinished={handleFileReadFinished}
46 onClearClick={handleClear}
47 isLoading={isLoading}
48 allowEditingUploadedText={false}
49 browseButtonText="Upload"
50 browseButtonAriaDescribedby="helper-text-example-helpText"
51 >
52 <FileUploadHelperText>
53 <HelperText>
54 <HelperTextItem id="helper-text-example-helpText">Upload a CSV file</HelperTextItem>
55 </HelperText>
56 </FileUploadHelperText>
57 </FileUpload>
58 );
59 };