diff --git a/packages/react-core/src/components/FileUpload/FileUpload.tsx b/packages/react-core/src/components/FileUpload/FileUpload.tsx index be342326057..35c5c7f6366 100644 --- a/packages/react-core/src/components/FileUpload/FileUpload.tsx +++ b/packages/react-core/src/components/FileUpload/FileUpload.tsx @@ -68,13 +68,13 @@ export interface FileUploadProps /** Clear button was clicked. */ onClearClick?: React.MouseEventHandler; /** 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, text: string) => void; } @@ -102,16 +102,16 @@ export const FileUpload: React.FunctionComponent = ({ 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, ''); }); } } diff --git a/packages/react-core/src/components/FileUpload/examples/FileUploadSimpleText.tsx b/packages/react-core/src/components/FileUpload/examples/FileUploadSimpleText.tsx index 5dc2f624147..8ad8ebf0e4c 100644 --- a/packages/react-core/src/components/FileUpload/examples/FileUploadSimpleText.tsx +++ b/packages/react-core/src/components/FileUpload/examples/FileUploadSimpleText.tsx @@ -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(''); @@ -14,7 +15,7 @@ export const SimpleTextFileUpload: React.FunctionComponent = () => { setValue(value); }; - const handleDataChange = (value: string) => { + const handleDataChange = (_event: DropEvent, value: string) => { setValue(value); }; @@ -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); }; diff --git a/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithEdits.tsx b/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithEdits.tsx index b62838bb8a6..19b03745676 100644 --- a/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithEdits.tsx +++ b/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithEdits.tsx @@ -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(''); @@ -14,7 +15,7 @@ export const TextFileWithEditsAllowed: React.FunctionComponent = () => { setValue(value); }; - const handleDataChange = (value: string) => { + const handleDataChange = (_event: DropEvent, value: string) => { setValue(value); }; @@ -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); }; diff --git a/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithRestrictions.tsx b/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithRestrictions.tsx index b1ae48379fc..c35d6e7975f 100644 --- a/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithRestrictions.tsx +++ b/packages/react-core/src/components/FileUpload/examples/FileUploadTextWithRestrictions.tsx @@ -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(''); @@ -15,7 +16,7 @@ export const TextFileUploadWithRestrictions: React.FunctionComponent = () => { setValue(value); }; - const handleDataChange = (value: string) => { + const handleDataChange = (_event: DropEvent, value: string) => { setValue(value); }; @@ -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); }; diff --git a/packages/react-integration/demo-app-ts/src/components/demos/FileUploadDemo/FileUploadDemo.tsx b/packages/react-integration/demo-app-ts/src/components/demos/FileUploadDemo/FileUploadDemo.tsx index 1f933eae632..c582f83e57d 100644 --- a/packages/react-integration/demo-app-ts/src/components/demos/FileUploadDemo/FileUploadDemo.tsx +++ b/packages/react-integration/demo-app-ts/src/components/demos/FileUploadDemo/FileUploadDemo.tsx @@ -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'; @@ -8,10 +9,10 @@ export class FileUploadDemo extends React.Component { /* eslint-disable-next-line no-console */ handleFileInputChange = (event: React.ChangeEvent, 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() {