gear-orders/web/vite/src/ConfirmDialogButton.tsx

47 lines
1.1 KiB
TypeScript
Raw Normal View History

2026-01-30 19:15:20 +00:00
import React from "react";
import { useDisclosure } from "@mantine/hooks";
2026-04-07 23:46:38 +00:00
import { Button, Modal, Text, Flex, ButtonVariant } from "@mantine/core";
2026-01-30 19:15:20 +00:00
export const ConfirmDialogButton: React.FC<{
text: string;
buttonText: string;
buttonColor: string;
onConfirm: () => void;
children: React.ReactNode;
2026-04-07 23:46:38 +00:00
variant?: ButtonVariant;
}> = ({
text,
buttonText,
buttonColor,
onConfirm,
children,
variant = "filled",
}) => {
2026-01-30 19:15:20 +00:00
const [opened, { open, close }] = useDisclosure();
const handleConfirm = React.useCallback(() => {
close();
onConfirm();
}, [close, onConfirm]);
return (
<>
<Modal opened={opened} onClose={close} p="sm" withCloseButton={false}>
<Text mb="xl">{text}</Text>
<Flex gap="md" justify="flex-end">
2026-04-07 23:46:38 +00:00
<Button variant="outline" onClick={close}>
Cancel
</Button>
2026-01-30 19:15:20 +00:00
<Button color={buttonColor} onClick={handleConfirm}>
{buttonText}
</Button>
</Flex>
</Modal>
2026-04-07 23:46:38 +00:00
<Button variant={variant} color={buttonColor} onClick={open}>
2026-01-30 19:15:20 +00:00
{children}
</Button>
</>
);
};