forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
156 lines (147 loc) · 3.88 KB
/
Copy pathutils.js
File metadata and controls
156 lines (147 loc) · 3.88 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
export function getTetherAttachments(placement) {
let attachments = {};
switch (placement) {
case 'top':
case 'top center':
attachments = {
attachment: 'bottom center',
targetAttachment: 'top center'
};
break;
case 'bottom':
case 'bottom center':
attachments = {
attachment: 'top center',
targetAttachment: 'bottom center'
};
break;
case 'left':
case 'left center':
attachments = {
attachment: 'middle right',
targetAttachment: 'middle left'
};
break;
case 'right':
case 'right center':
attachments = {
attachment: 'middle left',
targetAttachment: 'middle right'
};
break;
case 'top left':
attachments = {
attachment: 'bottom left',
targetAttachment: 'top left'
};
break;
case 'top right':
attachments = {
attachment: 'bottom right',
targetAttachment: 'top right'
};
break;
case 'bottom left':
attachments = {
attachment: 'top left',
targetAttachment: 'bottom left'
};
break;
case 'bottom right':
attachments = {
attachment: 'top right',
targetAttachment: 'bottom right'
};
break;
case 'right top':
attachments = {
attachment: 'top left',
targetAttachment: 'top right'
};
break;
case 'right bottom':
attachments = {
attachment: 'bottom left',
targetAttachment: 'bottom right'
};
break;
case 'left top':
attachments = {
attachment: 'top right',
targetAttachment: 'top left'
};
break;
case 'left bottom':
attachments = {
attachment: 'bottom right',
targetAttachment: 'bottom left'
};
break;
default:
attachments = {
attachment: 'top center',
targetAttachment: 'bottom center'
};
}
return attachments;
}
export const tetherAttachements = [
'top',
'bottom',
'left',
'right',
'top left',
'top center',
'top right',
'right top',
'right middle',
'right bottom',
'bottom right',
'bottom center',
'bottom left',
'left top',
'left middle',
'left bottom'
];
// https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.4/js/src/modal.js#L436-L443
export function getScrollbarWidth() {
let scrollDiv = document.createElement('div');
// .modal-scrollbar-measure styles // https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.4/scss/_modal.scss#L106-L113
scrollDiv.style.position = 'absolute';
scrollDiv.style.top = '-9999px';
scrollDiv.style.width = '50px';
scrollDiv.style.height = '50px';
scrollDiv.style.overflow = 'scroll';
document.body.appendChild(scrollDiv);
const scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
document.body.removeChild(scrollDiv);
return scrollbarWidth;
}
export function setScrollbarWidth(padding) {
document.body.style.paddingRight = padding > 0 ? `${padding}px` : null;
}
export function isBodyOverflowing() {
return document.body.clientWidth < window.innerWidth;
}
export function getOriginalBodyPadding() {
return parseInt(
window.getComputedStyle(document.body, null).getPropertyValue('padding-right') || 0,
10
);
}
export function conditionallyUpdateScrollbar() {
const scrollbarWidth = getScrollbarWidth();
// https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.4/js/src/modal.js#L420
const fixedContent = document.querySelectorAll('.navbar-fixed-top, .navbar-fixed-bottom, .is-fixed')[0];
const bodyPadding = fixedContent ? parseInt(
fixedContent.style.paddingRight || 0,
10
) : 0;
if (isBodyOverflowing()) {
setScrollbarWidth(bodyPadding + scrollbarWidth);
}
}
export function mapToCssModules(className, cssModule) {
if (!cssModule) return className;
return className.split(' ').map(c => cssModule[c] || c).join(' ');
}