Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions packages/react-core/src/components/FileUpload/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ export interface FileUploadProps
/** Clear button was clicked. */
onClearClick?: React.MouseEventHandler<HTMLButtonElement>;
/** On data changed - if type='text' or type='dataURL' and file was loaded it will call this method */
onDataChange?: (data: string) => void;
onDataChange?: (event: DropEvent, data: string) => void;
/** A callback for when the FileReader API fails. */
onReadFailed?: (error: DOMException, fileHandle: File) => void;
onReadFailed?: (event: DropEvent, error: DOMException, fileHandle: File) => void;
/** A callback for when a selected file finishes loading. */
onReadFinished?: (fileHandle: File) => void;
onReadFinished?: (event: DropEvent, fileHandle: File) => void;
/** A callback for when a selected file starts loading. */
onReadStarted?: (fileHandle: File) => void;
onReadStarted?: (event: DropEvent, fileHandle: File) => void;
/** Text area text changed. */
onTextChange?: (event: React.ChangeEvent<HTMLTextAreaElement>, text: string) => void;
}
Expand Down Expand Up @@ -102,16 +102,16 @@ export const FileUpload: React.FunctionComponent<FileUploadProps> = ({
onFileInputChange?.(event, fileHandle);

if (type === fileReaderType.text || type === fileReaderType.dataURL) {
onReadStarted(fileHandle);
onReadStarted(event, fileHandle);
readFile(fileHandle, type as fileReaderType)
.then(data => {
onReadFinished(fileHandle);
onDataChange?.(data as string);
onReadFinished(event, fileHandle);
onDataChange?.(event, data as string);
})
.catch((error: DOMException) => {
onReadFailed(error, fileHandle);
onReadFinished(fileHandle);
onDataChange?.('');
onReadFailed(event, error, fileHandle);
onReadFinished(event, fileHandle);
onDataChange?.(event, '');
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { FileUpload } from '@patternfly/react-core';
import { DropEvent } from 'react-dropzone';

export const SimpleTextFileUpload: React.FunctionComponent = () => {
const [value, setValue] = React.useState('');
Expand All @@ -14,7 +15,7 @@ export const SimpleTextFileUpload: React.FunctionComponent = () => {
setValue(value);
};

const handleDataChange = (value: string) => {
const handleDataChange = (_event: DropEvent, value: string) => {
setValue(value);
};

Expand All @@ -23,11 +24,11 @@ export const SimpleTextFileUpload: React.FunctionComponent = () => {
setValue('');
};

const handleFileReadStarted = (_fileHandle: File) => {
const handleFileReadStarted = (_event: DropEvent, _fileHandle: File) => {
setIsLoading(true);
};

const handleFileReadFinished = (_fileHandle: File) => {
const handleFileReadFinished = (_event: DropEvent, _fileHandle: File) => {
setIsLoading(false);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { FileUpload } from '@patternfly/react-core';
import { DropEvent } from 'react-dropzone';

export const TextFileWithEditsAllowed: React.FunctionComponent = () => {
const [value, setValue] = React.useState('');
Expand All @@ -14,7 +15,7 @@ export const TextFileWithEditsAllowed: React.FunctionComponent = () => {
setValue(value);
};

const handleDataChange = (value: string) => {
const handleDataChange = (_event: DropEvent, value: string) => {
setValue(value);
};

Expand All @@ -23,11 +24,11 @@ export const TextFileWithEditsAllowed: React.FunctionComponent = () => {
setValue('');
};

const handleFileReadStarted = (_fileHandle: File) => {
const handleFileReadStarted = (_event: DropEvent, _fileHandle: File) => {
setIsLoading(true);
};

const handleFileReadFinished = (_fileHandle: File) => {
const handleFileReadFinished = (_event: DropEvent, _fileHandle: File) => {
setIsLoading(false);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { FileUpload, Form, FormGroup, FormHelperText, HelperText, HelperTextItem } from '@patternfly/react-core';
import { DropEvent } from 'react-dropzone';

export const TextFileUploadWithRestrictions: React.FunctionComponent = () => {
const [value, setValue] = React.useState('');
Expand All @@ -15,7 +16,7 @@ export const TextFileUploadWithRestrictions: React.FunctionComponent = () => {
setValue(value);
};

const handleDataChange = (value: string) => {
const handleDataChange = (_event: DropEvent, value: string) => {
setValue(value);
};

Expand All @@ -29,11 +30,11 @@ export const TextFileUploadWithRestrictions: React.FunctionComponent = () => {
setIsRejected(true);
};

const handleFileReadStarted = (_fileHandle: File) => {
const handleFileReadStarted = (_event: DropEvent, _fileHandle: File) => {
setIsLoading(true);
};

const handleFileReadFinished = (_fileHandle: File) => {
const handleFileReadFinished = (_event: DropEvent, _fileHandle: File) => {
setIsLoading(false);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { FileUpload } from '@patternfly/react-core';
import { DropEvent } from 'react-dropzone';

export class FileUploadDemo extends React.Component {
static displayName = 'FileUploadDemo';
Expand All @@ -8,10 +9,10 @@ export class FileUploadDemo extends React.Component {
/* eslint-disable-next-line no-console */
handleFileInputChange = (event: React.ChangeEvent<HTMLInputElement>, file: File) =>
this.setState({ value: file, filename: file.name });
handleDataChange = (value: string) => this.setState({ value });
handleDataChange = (_event: DropEvent, value: string) => this.setState({ value });
/* eslint-disable @typescript-eslint/no-unused-vars */
handleFileReadStarted = (fileHandle: File) => this.setState({ isLoading: true });
handleFileReadFinished = (fileHandle: File) => this.setState({ isLoading: false });
handleFileReadStarted = (_event: DropEvent, _fileHandle: File) => this.setState({ isLoading: true });
handleFileReadFinished = (_event: DropEvent, _fileHandle: File) => this.setState({ isLoading: false });
/* eslint-enable @typescript-eslint/no-unused-vars */

render() {
Expand Down