blob: e9cdc3c97a89296bac906e9cb85cfd9471fa590a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
import React from "react";
import { useClientConfig } from "@/lib/clientConfig";
import type { ButtonProps } from "./button";
import { Button } from "./button";
import LoadingSpinner from "./spinner";
const ActionButton = React.forwardRef<
HTMLButtonElement,
ButtonProps & {
loading: boolean;
spinner?: React.ReactNode;
ignoreDemoMode?: boolean;
}
>(
(
{ 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 };
|