-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
BootstrapModalManager.js
59 lines (51 loc) · 1.79 KB
/
BootstrapModalManager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import css from 'dom-helpers/css';
import qsa from 'dom-helpers/querySelectorAll';
import getScrollbarSize from 'dom-helpers/scrollbarSize';
import ModalManager from 'react-overlays/ModalManager';
const Selector = {
FIXED_CONTENT: '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top',
STICKY_CONTENT: '.sticky-top',
NAVBAR_TOGGLER: '.navbar-toggler',
};
export default class BootstrapModalManager extends ModalManager {
adjustAndStore = (prop, element, adjust) => {
const actual = element.style[prop];
element.dataset[prop] = actual;
css(element, {
[prop]: `${parseFloat(css(element, prop)) + adjust}px`,
});
};
restore = (prop, element) => {
const value = element.dataset[prop];
if (value !== undefined) {
delete element.dataset[prop];
css(element, { [prop]: value });
}
};
setContainerStyle(containerState, container) {
super.setContainerStyle(containerState, container);
if (!containerState.overflowing) return;
const size = getScrollbarSize();
qsa(container, Selector.FIXED_CONTENT).forEach((el) =>
this.adjustAndStore('paddingRight', el, size),
);
qsa(container, Selector.STICKY_CONTENT).forEach((el) =>
this.adjustAndStore('margingRight', el, -size),
);
qsa(container, Selector.NAVBAR_TOGGLER).forEach((el) =>
this.adjustAndStore('margingRight', el, size),
);
}
removeContainerStyle(containerState, container) {
super.removeContainerStyle(containerState, container);
qsa(container, Selector.FIXED_CONTENT).forEach((el) =>
this.restore('paddingRight', el),
);
qsa(container, Selector.STICKY_CONTENT).forEach((el) =>
this.restore('margingRight', el),
);
qsa(container, Selector.NAVBAR_TOGGLER).forEach((el) =>
this.restore('margingRight', el),
);
}
}