From 73d23d594ed514be3bb38b5df66563fc919922a7 Mon Sep 17 00:00:00 2001 From: "D. Ror" Date: Fri, 11 Dec 2020 11:43:05 -0500 Subject: [PATCH 1/4] Remove non-button props from those passed to Button. --- src/components/Buttons/EditTextDialog.tsx | 1 - src/components/Buttons/FileInputButton.tsx | 9 ++++++--- src/components/Buttons/LoadingButton.tsx | 14 +++++++++----- src/components/Buttons/LoadingDoneButton.tsx | 16 +++++++++++----- .../ProjectExport/ExportProjectButton.tsx | 8 +++++--- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/components/Buttons/EditTextDialog.tsx b/src/components/Buttons/EditTextDialog.tsx index b77761e972..40960c198e 100644 --- a/src/components/Buttons/EditTextDialog.tsx +++ b/src/components/Buttons/EditTextDialog.tsx @@ -90,7 +90,6 @@ export default function EditTextDialog(props: EditTextDialogProps) { color="primary" variant="contained" loading={loading} - {...props} > diff --git a/src/components/Buttons/FileInputButton.tsx b/src/components/Buttons/FileInputButton.tsx index 8c712fce5d..7e768010bd 100644 --- a/src/components/Buttons/FileInputButton.tsx +++ b/src/components/Buttons/FileInputButton.tsx @@ -9,7 +9,10 @@ export interface BrowseProps { // This button links to a set of functions export default function FileInputButton(props: BrowseProps & ButtonProps) { - function updateFile(files: FileList) { + // Use Destructuring to define buttonProps without our BrowseProps. + const { updateFile, accept, ...buttonProps } = props; + + function updateFirstFile(files: FileList) { const file = files[0]; if (file) { props.updateFile(file); @@ -24,13 +27,13 @@ export default function FileInputButton(props: BrowseProps & ButtonProps) { type="file" name="name" accept={props.accept} - onChange={(e) => updateFile(e.target.files as FileList)} + onChange={(e) => updateFirstFile(e.target.files as FileList)} style={{ display: "none" }} /> {/* ... and this button is tied to it with the htmlFor property */} diff --git a/src/components/Buttons/LoadingButton.tsx b/src/components/Buttons/LoadingButton.tsx index 7a86d650da..7d89bb3748 100644 --- a/src/components/Buttons/LoadingButton.tsx +++ b/src/components/Buttons/LoadingButton.tsx @@ -1,18 +1,22 @@ -import React from "react"; import { Button, CircularProgress } from "@material-ui/core"; -import { buttonSuccess } from "../../types/theme"; import { ButtonProps } from "@material-ui/core/Button"; +import React from "react"; -interface Props { +import { buttonSuccess } from "../../types/theme"; + +interface LoadingProps { loading: boolean; } /** * A button that shows a spinning wheel when loading=true */ -export default function LoadingButton(props: Props & ButtonProps) { +export default function LoadingButton(props: LoadingProps & ButtonProps) { + // Use Destructuring to define buttonProps without our LoadingProps. + const { loading, ...buttonProps } = props; + return ( - diff --git a/src/components/Buttons/DeleteDialog.tsx b/src/components/Buttons/DeleteDialog.tsx index 7c3b3abd6e..0332599aec 100644 --- a/src/components/Buttons/DeleteDialog.tsx +++ b/src/components/Buttons/DeleteDialog.tsx @@ -6,7 +6,6 @@ import { DialogContentText, DialogTitle, } from "@material-ui/core"; -import { ButtonProps } from "@material-ui/core/Button"; import React from "react"; import { Translate } from "react-localize-redux"; @@ -20,7 +19,7 @@ interface DeleteDialogProps { /** * Dialog to confirm deletion */ -export default function DeleteDialog(props: ButtonProps & DeleteDialogProps) { +export default function DeleteDialog(props: DeleteDialogProps) { return ( diff --git a/src/components/Buttons/LoadingButton.tsx b/src/components/Buttons/LoadingButton.tsx index 7d89bb3748..de88a6a5b4 100644 --- a/src/components/Buttons/LoadingButton.tsx +++ b/src/components/Buttons/LoadingButton.tsx @@ -6,17 +6,16 @@ import { buttonSuccess } from "../../types/theme"; interface LoadingProps { loading: boolean; + children: React.ReactNode; + buttonProps: ButtonProps; } /** * A button that shows a spinning wheel when loading=true */ -export default function LoadingButton(props: LoadingProps & ButtonProps) { - // Use Destructuring to define buttonProps without our LoadingProps. - const { loading, ...buttonProps } = props; - +export default function LoadingButton(props: LoadingProps) { return ( - diff --git a/src/components/Buttons/LoadingDoneButton.tsx b/src/components/Buttons/LoadingDoneButton.tsx index 899cb1a949..17a35eefab 100644 --- a/src/components/Buttons/LoadingDoneButton.tsx +++ b/src/components/Buttons/LoadingDoneButton.tsx @@ -11,27 +11,24 @@ interface LoadingDoneProps { done: boolean; doneText?: React.ReactNode | string; disabled?: boolean; + children: React.ReactNode; + buttonProps: ButtonProps; } /** * A button that shows a spinning wheel when loading and "done" when done */ -export default function LoadingDoneButton( - props: LoadingDoneProps & ButtonProps -) { - // Use Destructuring to define buttonProps without our LoadingDoneProps. - const { loading, done, doneText, disabled, ...buttonProps } = props; - +export default function LoadingDoneButton(props: LoadingDoneProps) { return (