@trellixio/roaster-coffee
Version:
Beans' product component library
22 lines (21 loc) • 1.66 kB
JavaScript
/* eslint-disable @typescript-eslint/no-unused-expressions */
import React from 'react';
import { Button } from '@/components/Button';
import { useModal } from '../utils/useModal';
export function ModalProviderFooter({ cancelProps, confirmProps, labels = { confirm: 'Confirm', cancel: 'Cancel' }, closeOnConfirm = true, closeOnCancel = true, onCancel, onConfirm, }) {
const { cancel: cancelLabel, confirm: confirmLabel } = labels;
const ctx = useModal();
const handleCancel = () => {
typeof (cancelProps === null || cancelProps === void 0 ? void 0 : cancelProps.onClick) === 'function' && (cancelProps === null || cancelProps === void 0 ? void 0 : cancelProps.onClick());
typeof onCancel === 'function' && onCancel();
closeOnCancel && ctx.closeModal();
};
const handleConfirm = () => {
typeof (confirmProps === null || confirmProps === void 0 ? void 0 : confirmProps.onClick) === 'function' && (confirmProps === null || confirmProps === void 0 ? void 0 : confirmProps.onClick());
typeof onConfirm === 'function' && onConfirm();
closeOnConfirm && ctx.closeModal();
};
return (React.createElement(React.Fragment, null,
React.createElement(Button, Object.assign({ variant: "primary", color: "danger" }, cancelProps, { onClick: handleCancel }), (cancelProps === null || cancelProps === void 0 ? void 0 : cancelProps.children) || cancelLabel),
React.createElement(Button, Object.assign({ variant: "primary", color: "success" }, confirmProps, { onClick: handleConfirm }), (confirmProps === null || confirmProps === void 0 ? void 0 : confirmProps.children) || confirmLabel)));
}