-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split FormSubmitButton styled comp into own comp
- Loading branch information
1 parent
4deb70b
commit f699132
Showing
2 changed files
with
47 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { grid as muiGridSxProps, type GridProps as MuiGridSxProps } from "@mui/system"; | ||
import { styled } from "@mui/material/styles"; | ||
import Button, { type ButtonProps } from "@mui/material/Button"; | ||
import { ButtonLoadingIndicator } from "@/components/Indicators/ButtonLoadingIndicator"; | ||
import type { Simplify } from "type-fest"; | ||
|
||
/** | ||
* A form submit button which shows a loading indicator when `isLoading` is `true`. | ||
* | ||
* > _This is used by `Form/FormSubmitButton` and `StripeForm/StripeFormSubmitButton`_. | ||
*/ | ||
export const BaseFormSubmitButton = ({ | ||
label, | ||
type = "button", | ||
isLoading, | ||
...buttonProps | ||
}: BaseFormSubmitButtonProps) => ( | ||
<StyledButton type={type} {...buttonProps}> | ||
{isLoading ? <ButtonLoadingIndicator /> : label} | ||
</StyledButton> | ||
); | ||
|
||
const StyledButton = styled(Button, { | ||
shouldForwardProp: (propName: string) => !propName.startsWith("grid"), | ||
})<MuiGridSxProps>({ | ||
height: "2.75rem", // default is 2.5rem | ||
position: "relative", | ||
...muiGridSxProps, | ||
}); | ||
|
||
export type BaseFormSubmitButtonProps = Simplify< | ||
{ label: string; isLoading: boolean } & Omit<ButtonProps, "children"> & MuiGridSxProps | ||
>; |
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