Add custom confirm modal component

This commit is contained in:
jeffvli 2023-01-03 00:12:07 -08:00
parent 4dc8920ff4
commit 9537309fe2

View File

@ -1,10 +1,16 @@
import React from 'react';
import type { ModalProps as MantineModalProps } from '@mantine/core';
import { Modal as MantineModal } from '@mantine/core';
import type { ContextModalProps } from '@mantine/modals';
import React, { ReactNode } from 'react';
import {
ModalProps as MantineModalProps,
Stack,
Modal as MantineModal,
Flex,
Group,
} from '@mantine/core';
import { closeAllModals, ContextModalProps } from '@mantine/modals';
import { Button } from '/@/renderer/components/button';
export interface ModalProps extends Omit<MantineModalProps, 'onClose'> {
children?: React.ReactNode;
children?: ReactNode;
handlers: {
close: () => void;
open: () => void;
@ -41,3 +47,44 @@ export const BaseContextModal = ({
Modal.defaultProps = {
children: undefined,
};
interface ConfirmModalProps {
children: ReactNode;
labels?: {
cancel?: string;
confirm?: string;
};
onCancel?: () => void;
onConfirm: () => void;
}
export const ConfirmModal = ({ labels, onCancel, onConfirm, children }: ConfirmModalProps) => {
const handleCancel = () => {
if (onCancel) {
onCancel();
} else {
closeAllModals();
}
};
return (
<Stack>
<Flex>{children}</Flex>
<Group position="right">
<Button
data-focus
variant="default"
onClick={handleCancel}
>
{labels?.cancel ? labels.cancel : 'Cancel'}
</Button>
<Button
variant="filled"
onClick={onConfirm}
>
{labels?.confirm ? labels.confirm : 'Confirm'}
</Button>
</Group>
</Stack>
);
};