GoScrobble/web/node_modules/react-bootstrap/cjs/BootstrapModalManager.js

92 lines
3.2 KiB
JavaScript

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _css3 = _interopRequireDefault(require("dom-helpers/css"));
var _querySelectorAll = _interopRequireDefault(require("dom-helpers/querySelectorAll"));
var _scrollbarSize = _interopRequireDefault(require("dom-helpers/scrollbarSize"));
var _ModalManager2 = _interopRequireDefault(require("react-overlays/ModalManager"));
var Selector = {
FIXED_CONTENT: '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top',
STICKY_CONTENT: '.sticky-top',
NAVBAR_TOGGLER: '.navbar-toggler'
};
var BootstrapModalManager = /*#__PURE__*/function (_ModalManager) {
(0, _inheritsLoose2.default)(BootstrapModalManager, _ModalManager);
function BootstrapModalManager() {
return _ModalManager.apply(this, arguments) || this;
}
var _proto = BootstrapModalManager.prototype;
_proto.adjustAndStore = function adjustAndStore(prop, element, adjust) {
var _css;
var actual = element.style[prop]; // TODO: DOMStringMap and CSSStyleDeclaration aren't strictly compatible
// @ts-ignore
element.dataset[prop] = actual;
(0, _css3.default)(element, (_css = {}, _css[prop] = parseFloat((0, _css3.default)(element, prop)) + adjust + "px", _css));
};
_proto.restore = function restore(prop, element) {
var value = element.dataset[prop];
if (value !== undefined) {
var _css2;
delete element.dataset[prop];
(0, _css3.default)(element, (_css2 = {}, _css2[prop] = value, _css2));
}
};
_proto.setContainerStyle = function setContainerStyle(containerState, container) {
var _this = this;
_ModalManager.prototype.setContainerStyle.call(this, containerState, container);
if (!containerState.overflowing) return;
var size = (0, _scrollbarSize.default)();
(0, _querySelectorAll.default)(container, Selector.FIXED_CONTENT).forEach(function (el) {
return _this.adjustAndStore('paddingRight', el, size);
});
(0, _querySelectorAll.default)(container, Selector.STICKY_CONTENT).forEach(function (el) {
return _this.adjustAndStore('marginRight', el, -size);
});
(0, _querySelectorAll.default)(container, Selector.NAVBAR_TOGGLER).forEach(function (el) {
return _this.adjustAndStore('marginRight', el, size);
});
};
_proto.removeContainerStyle = function removeContainerStyle(containerState, container) {
var _this2 = this;
_ModalManager.prototype.removeContainerStyle.call(this, containerState, container);
(0, _querySelectorAll.default)(container, Selector.FIXED_CONTENT).forEach(function (el) {
return _this2.restore('paddingRight', el);
});
(0, _querySelectorAll.default)(container, Selector.STICKY_CONTENT).forEach(function (el) {
return _this2.restore('marginRight', el);
});
(0, _querySelectorAll.default)(container, Selector.NAVBAR_TOGGLER).forEach(function (el) {
return _this2.restore('marginRight', el);
});
};
return BootstrapModalManager;
}(_ModalManager2.default);
exports.default = BootstrapModalManager;
module.exports = exports["default"];