From 4e9408ee3ef0104f0205f28f883dc6298eb2039a Mon Sep 17 00:00:00 2001 From: Lukas Jakob Date: Mon, 27 Feb 2023 09:24:31 -0600 Subject: [PATCH] refactor(AsyncButton): add disabled property --- packages/app/src/Element/AsyncButton.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/app/src/Element/AsyncButton.tsx b/packages/app/src/Element/AsyncButton.tsx index 34e6e10..c130ab2 100644 --- a/packages/app/src/Element/AsyncButton.tsx +++ b/packages/app/src/Element/AsyncButton.tsx @@ -2,6 +2,7 @@ import "./AsyncButton.css"; import { useState } from "react"; interface AsyncButtonProps extends React.ButtonHTMLAttributes { + disabled?: boolean; onClick(e: React.MouseEvent): Promise | void; children?: React.ReactNode; } @@ -31,7 +32,7 @@ export default function AsyncButton(props: AsyncButtonProps) { const [loading, setLoading] = useState(false); async function handle(e: React.MouseEvent) { - if (loading) return; + if (loading || props.disabled) return; setLoading(true); try { if (typeof props.onClick === "function") { @@ -46,7 +47,7 @@ export default function AsyncButton(props: AsyncButtonProps) { } return ( -