aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/components/ui/action-button.tsx
diff options
context:
space:
mode:
authorMohamedBassem <me@mbassem.com>2024-04-14 01:39:30 +0300
committerMohamedBassem <me@mbassem.com>2024-04-14 01:40:51 +0300
commit5c9acb1cb3bfe341378b91bbed344dd7202a00d7 (patch)
tree5aaf1124283efaaff103623b7a678d9bcc7a4951 /apps/web/components/ui/action-button.tsx
parent4f17ea61cbb11a72712a1ea8c98904a1cc513e41 (diff)
downloadkarakeep-5c9acb1cb3bfe341378b91bbed344dd7202a00d7.tar.zst
fix(web): Fix some JS console errors in the preview page
Diffstat (limited to 'apps/web/components/ui/action-button.tsx')
-rw-r--r--apps/web/components/ui/action-button.tsx57
1 files changed, 31 insertions, 26 deletions
diff --git a/apps/web/components/ui/action-button.tsx b/apps/web/components/ui/action-button.tsx
index 5b862e07..e9cdc3c9 100644
--- a/apps/web/components/ui/action-button.tsx
+++ b/apps/web/components/ui/action-button.tsx
@@ -1,33 +1,38 @@
+import React from "react";
import { useClientConfig } from "@/lib/clientConfig";
import type { ButtonProps } from "./button";
import { Button } from "./button";
import LoadingSpinner from "./spinner";
-export function ActionButton({
- children,
- loading,
- spinner,
- disabled,
- ignoreDemoMode = false,
- ...props
-}: ButtonProps & {
- loading: boolean;
- spinner?: React.ReactNode;
- ignoreDemoMode?: boolean;
-}) {
- const clientConfig = useClientConfig();
- spinner ||= <LoadingSpinner />;
- if (!ignoreDemoMode && clientConfig.demoMode) {
- disabled = true;
- } else if (disabled !== undefined) {
- disabled ||= loading;
- } else if (loading) {
- disabled = true;
+const ActionButton = React.forwardRef<
+ HTMLButtonElement,
+ ButtonProps & {
+ loading: boolean;
+ spinner?: React.ReactNode;
+ ignoreDemoMode?: boolean;
}
- return (
- <Button {...props} disabled={disabled}>
- {loading ? spinner : children}
- </Button>
- );
-}
+>(
+ (
+ { children, loading, spinner, disabled, ignoreDemoMode = false, ...props },
+ ref,
+ ) => {
+ const clientConfig = useClientConfig();
+ spinner ||= <LoadingSpinner />;
+ if (!ignoreDemoMode && clientConfig.demoMode) {
+ disabled = true;
+ } else if (disabled !== undefined) {
+ disabled ||= loading;
+ } else if (loading) {
+ disabled = true;
+ }
+ return (
+ <Button ref={ref} {...props} disabled={disabled}>
+ {loading ? spinner : children}
+ </Button>
+ );
+ },
+);
+ActionButton.displayName = "ActionButton";
+
+export { ActionButton };