-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathutil.js
More file actions
70 lines (57 loc) · 1.74 KB
/
util.js
File metadata and controls
70 lines (57 loc) · 1.74 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
import createUUID from 'uuid';
export const uuid =
process.env.NODE_ENV === 'test' ?
() => '$uuid$' :
createUUID;
export const getToday =
process.env.NODE_ENV === 'test' ?
() => '2017-02-23' :
() => new Date().toISOString().substring(0, 10);
let assetRoot = '/assets';
export function setAssetRoot(path) {
assetRoot = path;
}
export function getAssetRoot() {
return assetRoot;
}
export function registerStyle(styleName, rules) {
const styleId = `react-slds-cssfix-${styleName}`;
let style = document.getElementById(styleId);
if (style) { return; }
style = document.createElement('style');
style.id = styleId;
style.appendChild(document.createTextNode(''));
document.documentElement.appendChild(style);
for (const ruleSet of rules) {
const declaration = ruleSet.pop();
let selectors = ruleSet;
selectors = selectors.concat(selectors.map(s => `.slds ${s}`));
const rule = `${selectors.join(', ')} ${declaration}`;
style.sheet.insertRule(rule, 0);
}
}
export function isElInChildren(rootEl, targetEl) {
/* eslint-disable no-param-reassign */
while (targetEl && targetEl !== rootEl) {
targetEl = targetEl.parentNode;
}
return !!targetEl;
}
export function offset(el) {
const rect = el.getBoundingClientRect();
return {
top: rect.top + document.body.scrollTop,
left: rect.left + document.body.scrollLeft,
};
}
export function cleanProps(props, propTypes) {
const newProps = props;
Object.keys(propTypes).forEach((key) => {
delete newProps[key];
});
return newProps;
}
export function isIE() {
return !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/));
}
export default { setAssetRoot, getAssetRoot, registerStyle, isElInChildren, offset, cleanProps };