Skip to content

Commit

Permalink
feat: allow loading and disable state for confirm button in Confirmat…
Browse files Browse the repository at this point in the history
…ionModal

Signed-off-by: Mason Hu <mason.hu@canonical.com>
  • Loading branch information
mas-who committed Apr 22, 2024
1 parent 3de71fc commit b6067ee
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/components/ConfirmationModal/ConfirmationModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ReactNode } from "react";
import { PropsWithSpread, ValueOf } from "types";
import Button, { ButtonAppearance } from "components/Button";
import Modal, { ModalProps } from "components/Modal";
import ActionButton from "components/ActionButton";

export type Props = PropsWithSpread<
{
Expand Down Expand Up @@ -30,6 +31,14 @@ export type Props = PropsWithSpread<
* Function to perform the action prompted by the modal.
*/
onConfirm: (event: MouseEvent<HTMLElement>) => void;
/**
* Whether the confirm button should be in the loading state.
*/
confirmButtonLoading?: boolean;
/**
* Whether the confirm button should be disabled.
*/
confirmButtonDisabled?: boolean;
},
Omit<ModalProps, "buttonRow">
>;
Expand All @@ -41,6 +50,8 @@ export const ConfirmationModal = ({
confirmButtonLabel,
confirmExtra,
onConfirm,
confirmButtonLoading,
confirmButtonDisabled,
...props
}: Props): ReactElement => {
const handleClick =
Expand All @@ -65,13 +76,15 @@ export const ConfirmationModal = ({
>
{cancelButtonLabel}
</Button>
<Button
<ActionButton
appearance={confirmButtonAppearance}
className="u-no-margin--bottom"
onClick={handleClick(onConfirm)}
loading={confirmButtonLoading}
disabled={confirmButtonDisabled}
>
{confirmButtonLabel}
</Button>
</ActionButton>
</>
}
{...props}
Expand Down

0 comments on commit b6067ee

Please sign in to comment.