UNPKG

2.68 kBJavaScriptView Raw
1import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
2import css from 'dom-helpers/css';
3import qsa from 'dom-helpers/querySelectorAll';
4import getScrollbarSize from 'dom-helpers/scrollbarSize';
5import ModalManager from 'react-overlays/ModalManager';
6var Selector = {
7 FIXED_CONTENT: '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top',
8 STICKY_CONTENT: '.sticky-top',
9 NAVBAR_TOGGLER: '.navbar-toggler'
10};
11
12var BootstrapModalManager = /*#__PURE__*/function (_ModalManager) {
13 _inheritsLoose(BootstrapModalManager, _ModalManager);
14
15 function BootstrapModalManager() {
16 return _ModalManager.apply(this, arguments) || this;
17 }
18
19 var _proto = BootstrapModalManager.prototype;
20
21 _proto.adjustAndStore = function adjustAndStore(prop, element, adjust) {
22 var _css;
23
24 var actual = element.style[prop]; // TODO: DOMStringMap and CSSStyleDeclaration aren't strictly compatible
25 // @ts-ignore
26
27 element.dataset[prop] = actual;
28 css(element, (_css = {}, _css[prop] = parseFloat(css(element, prop)) + adjust + "px", _css));
29 };
30
31 _proto.restore = function restore(prop, element) {
32 var value = element.dataset[prop];
33
34 if (value !== undefined) {
35 var _css2;
36
37 delete element.dataset[prop];
38 css(element, (_css2 = {}, _css2[prop] = value, _css2));
39 }
40 };
41
42 _proto.setContainerStyle = function setContainerStyle(containerState, container) {
43 var _this = this;
44
45 _ModalManager.prototype.setContainerStyle.call(this, containerState, container);
46
47 if (!containerState.overflowing) return;
48 var size = getScrollbarSize();
49 qsa(container, Selector.FIXED_CONTENT).forEach(function (el) {
50 return _this.adjustAndStore('paddingRight', el, size);
51 });
52 qsa(container, Selector.STICKY_CONTENT).forEach(function (el) {
53 return _this.adjustAndStore('marginRight', el, -size);
54 });
55 qsa(container, Selector.NAVBAR_TOGGLER).forEach(function (el) {
56 return _this.adjustAndStore('marginRight', el, size);
57 });
58 };
59
60 _proto.removeContainerStyle = function removeContainerStyle(containerState, container) {
61 var _this2 = this;
62
63 _ModalManager.prototype.removeContainerStyle.call(this, containerState, container);
64
65 qsa(container, Selector.FIXED_CONTENT).forEach(function (el) {
66 return _this2.restore('paddingRight', el);
67 });
68 qsa(container, Selector.STICKY_CONTENT).forEach(function (el) {
69 return _this2.restore('marginRight', el);
70 });
71 qsa(container, Selector.NAVBAR_TOGGLER).forEach(function (el) {
72 return _this2.restore('marginRight', el);
73 });
74 };
75
76 return BootstrapModalManager;
77}(ModalManager);
78
79export { BootstrapModalManager as default };
\No newline at end of file