From 9235e9a6fbb364713105137b6bf5bba9d81ecd4c Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Fri, 16 Feb 2024 21:26:24 +0000
Subject: ui: Change action buttons to show a spinner when the request is
 loading

---
 packages/web/components/ui/action-button.tsx | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 packages/web/components/ui/action-button.tsx

(limited to 'packages/web/components/ui/action-button.tsx')

diff --git a/packages/web/components/ui/action-button.tsx b/packages/web/components/ui/action-button.tsx
new file mode 100644
index 00000000..42e16f65
--- /dev/null
+++ b/packages/web/components/ui/action-button.tsx
@@ -0,0 +1,25 @@
+import { Button, ButtonProps } from "./button";
+import LoadingSpinner from "./spinner";
+
+export function ActionButton({
+  children,
+  loading,
+  spinner,
+  disabled,
+  ...props
+}: ButtonProps & {
+  loading: boolean;
+  spinner?: React.ReactNode;
+}) {
+  spinner ||= <LoadingSpinner />;
+  if (disabled !== undefined) {
+    disabled ||= loading;
+  } else if (loading) {
+    disabled = true;
+  }
+  return (
+    <Button {...props} disabled={disabled}>
+      {loading ? spinner : children}
+    </Button>
+  );
+}
-- 
cgit v1.2.3-70-g09d2

