@braineet/ui
Version:
Braineet design system
132 lines • 3.74 kB
JavaScript
var _excluded = ["animation", "blockScrollOnMount", "children", "footer", "initialFocusRef", "finalFocusRef", "isCentered", "targetDom"];
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Provider } from '../provider';
import { ModalProvider } from './context';
import { OriginalModal, destroyFns } from './Modal';
import { jsx as _jsx } from "react/jsx-runtime";
var confirm = function confirm(config) {
var div = document.createElement('div');
document.body.appendChild(div);
var currentConfig = _extends({
noClose: true
}, config, {
autoFocus: false,
onClose: close,
isOpen: true,
closeOnOverlayClick: false
});
function render(_ref) {
var animation = _ref.animation,
blockScrollOnMount = _ref.blockScrollOnMount,
children = _ref.children,
footer = _ref.footer,
initialFocusRef = _ref.initialFocusRef,
finalFocusRef = _ref.finalFocusRef,
isCentered = _ref.isCentered,
targetDom = _ref.targetDom,
providerProps = _objectWithoutPropertiesLoose(_ref, _excluded);
var modalProps = {
animation: animation,
blockScrollOnMount: blockScrollOnMount,
children: children,
footer: footer,
initialFocusRef: initialFocusRef,
finalFocusRef: finalFocusRef,
isCentered: isCentered,
targetDom: targetDom
};
setTimeout(function () {
ReactDOM.render(/*#__PURE__*/_jsx(Provider, {
children: /*#__PURE__*/_jsx(ModalProvider, _extends({}, providerProps, {
children: /*#__PURE__*/_jsx(OriginalModal, _extends({}, modalProps))
}))
}), div);
});
}
function close() {
currentConfig = _extends({}, currentConfig, {
isOpen: false
});
render(currentConfig);
}
function update(newConfig) {
currentConfig = _extends({}, currentConfig, newConfig, {
autoFocus: false
});
render(currentConfig);
}
destroyFns.push(close);
render(currentConfig);
return {
destroy: close,
update: update
};
};
export var withInfo = function withInfo(props) {
return _extends({
noCancel: true,
noClose: true
}, props, {
autoFocus: false,
closeOnOverlayClick: false,
icon: {
name: 'info',
color: 'action'
},
okButtonProps: {
color: 'action'
}
});
};
export var withSuccess = function withSuccess(props) {
return _extends({
noCancel: true,
noClose: true
}, props, {
autoFocus: false,
closeOnOverlayClick: false,
icon: {
name: 'tick',
color: 'success'
},
okButtonProps: {
color: 'success'
}
});
};
export var withWarning = function withWarning(props) {
return _extends({
noCancel: true,
noClose: true
}, props, {
autoFocus: false,
closeOnOverlayClick: false,
icon: {
name: 'error_alert',
color: 'warning'
},
okButtonProps: {
color: 'warning'
}
});
};
export var withError = function withError(props) {
return _extends({
noCancel: true,
noClose: true
}, props, {
autoFocus: false,
closeOnOverlayClick: false,
icon: {
name: 'cross',
color: 'error'
},
okButtonProps: {
color: 'error'
}
});
};
export default confirm;