UNPKG

@coveord/plasma-mantine

Version:

A Plasma flavoured Mantine theme

80 lines (79 loc) 3.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "InlineConfirmPrompt", { enumerable: true, get: function() { return InlineConfirmPrompt; } }); var _object_spread = require("@swc/helpers/_/_object_spread"); var _object_spread_props = require("@swc/helpers/_/_object_spread_props"); var _object_without_properties = require("@swc/helpers/_/_object_without_properties"); var _jsxruntime = require("react/jsx-runtime"); var _core = require("@mantine/core"); var _react = require("react"); var _Button = require("../button/Button"); var _InlineConfirmContext = require("./InlineConfirmContext"); var defaultProps = { label: 'Are you sure?', confirm: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Button.Button, { color: "red", children: "Delete" }), cancel: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Button.Button, { variant: "outline", children: "Cancel" }), gap: 'xs', wrap: 'nowrap' }; var InlineConfirmPrompt = (0, _core.factory)(function(props, ref) { var _useProps = (0, _core.useProps)('InlineConfirmPrompt', defaultProps, props), inlineConfirmId = _useProps.inlineConfirmId, label = _useProps.label, confirm = _useProps.confirm, cancel = _useProps.cancel, onConfirm = _useProps.onConfirm, onCancel = _useProps.onCancel, others = _object_without_properties._(_useProps, [ "inlineConfirmId", "label", "confirm", "cancel", "onConfirm", "onCancel" ]); var _useInlineConfirm = (0, _InlineConfirmContext.useInlineConfirm)(), confirmingId = _useInlineConfirm.confirmingId, clearConfirm = _useInlineConfirm.clearConfirm; if (!(0, _core.isElement)(cancel) || !(0, _core.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'); } var cancelEl = /*#__PURE__*/ (0, _react.cloneElement)(cancel, { onClick: function() { var _cancel_props_onClick, _cancel_props; (_cancel_props_onClick = (_cancel_props = cancel.props).onClick) === null || _cancel_props_onClick === void 0 ? void 0 : _cancel_props_onClick.call(_cancel_props); onCancel === null || onCancel === void 0 ? void 0 : onCancel(); clearConfirm(); } }); var confirmEl = /*#__PURE__*/ (0, _react.cloneElement)(confirm, { onClick: function() { var _confirm_props_onClick, _confirm_props; (_confirm_props_onClick = (_confirm_props = confirm.props).onClick) === null || _confirm_props_onClick === void 0 ? void 0 : _confirm_props_onClick.call(_confirm_props); onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(); clearConfirm(); } }); (0, _react.useEffect)(function() { if (confirmingId !== inlineConfirmId) { clearConfirm(); } }, []); if (confirmingId === inlineConfirmId) { return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_core.Group, _object_spread_props._(_object_spread._({ ref: ref }, others), { children: [ label, confirmEl, cancelEl ] })); } return null; }); //# sourceMappingURL=InlineConfirmPrompt.js.map