-
-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web): Fix some JS console errors in the preview page
- Loading branch information
1 parent
4f17ea6
commit 5c9acb1
Showing
4 changed files
with
50 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }; |