UNPKG

@coveord/plasma-mantine

Version:

A Plasma flavoured Mantine theme

58 lines (57 loc) 1.94 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { factory, Group, isElement, useProps } from '@mantine/core'; import { cloneElement, useEffect } from 'react'; import { Button } from '../button/Button'; import { useInlineConfirm } from './InlineConfirmContext'; const defaultProps = { label: 'Are you sure?', confirm: /*#__PURE__*/ _jsx(Button, { color: "red", children: "Delete" }), cancel: /*#__PURE__*/ _jsx(Button, { variant: "outline", children: "Cancel" }), gap: 'xs', wrap: 'nowrap' }; export const InlineConfirmPrompt = factory((props, ref)=>{ const { inlineConfirmId, label, confirm, cancel, onConfirm, onCancel, ...others } = useProps('InlineConfirmPrompt', defaultProps, props); const { confirmingId, clearConfirm } = useInlineConfirm(); if (!isElement(cancel) || !isElement(confirm)) { throw new Error('InlineConfirm.Prompt component cancel & confirm props should be elements or a component that accepts ref. Fragments, strings, numbers and other primitive values are not supported'); } const cancelEl = /*#__PURE__*/ cloneElement(cancel, { onClick: ()=>{ cancel.props.onClick?.(); onCancel?.(); clearConfirm(); } }); const confirmEl = /*#__PURE__*/ cloneElement(confirm, { onClick: ()=>{ confirm.props.onClick?.(); onConfirm?.(); clearConfirm(); } }); useEffect(()=>{ if (confirmingId !== inlineConfirmId) { clearConfirm(); } }, []); if (confirmingId === inlineConfirmId) { return /*#__PURE__*/ _jsxs(Group, { ref: ref, ...others, children: [ label, confirmEl, cancelEl ] }); } return null; }); //# sourceMappingURL=InlineConfirmPrompt.js.map