keycloak-scim/js/libs/ui-shared/src/continue-cancel/ContinueCancelModal.tsx

75 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-01-16 10:23:07 +00:00
import { ReactNode, useState } from "react";
import { Button, ButtonProps, Modal, ModalProps } from "@patternfly/react-core";
export type ContinueCancelModalProps = Omit<ModalProps, "ref" | "children"> & {
modalTitle: string;
2023-01-16 10:23:07 +00:00
modalMessage?: string;
buttonTitle: string | ReactNode;
2023-01-16 10:23:07 +00:00
buttonVariant?: ButtonProps["variant"];
isDisabled?: boolean;
onContinue: () => void;
continueLabel?: string;
cancelLabel?: string;
2023-01-16 10:23:07 +00:00
component?: React.ElementType<any> | React.ComponentType<any>;
children?: ReactNode;
};
export const ContinueCancelModal = ({
modalTitle,
modalMessage,
buttonTitle,
isDisabled,
buttonVariant,
onContinue,
continueLabel = "continue",
cancelLabel = "doCancel",
component = Button,
2023-01-16 10:23:07 +00:00
children,
...rest
}: ContinueCancelModalProps) => {
const [open, setOpen] = useState(false);
const Component = component;
return (
<>
<Component
variant={buttonVariant}
onClick={() => setOpen(true)}
isDisabled={isDisabled}
>
{buttonTitle}
2023-01-16 10:23:07 +00:00
</Component>
<Modal
variant="small"
{...rest}
title={modalTitle}
2023-01-16 10:23:07 +00:00
isOpen={open}
onClose={() => setOpen(false)}
actions={[
<Button
id="modal-confirm"
key="confirm"
variant="primary"
onClick={() => {
setOpen(false);
onContinue();
}}
>
{continueLabel}
2023-01-16 10:23:07 +00:00
</Button>,
<Button
id="modal-cancel"
key="cancel"
variant="secondary"
onClick={() => setOpen(false)}
>
{cancelLabel}
2023-01-16 10:23:07 +00:00
</Button>,
]}
>
{modalMessage ? modalMessage : children}
2023-01-16 10:23:07 +00:00
</Modal>
</>
);
};