@aarhus-university/au-lib-react-components 10.0.2 → 10.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"sideEffects": false,
|
|
3
3
|
"name": "@aarhus-university/au-lib-react-components",
|
|
4
|
-
"version": "10.0.
|
|
4
|
+
"version": "10.0.3",
|
|
5
5
|
"description": "Library for shared React components for various applications on au.dk",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "webpack --config ./webpack.config.js"
|
|
@@ -1,67 +1,91 @@
|
|
|
1
|
-
/* eslint-
|
|
2
|
-
|
|
3
|
-
import
|
|
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
|
-
|
|
1
|
+
/* eslint-disable react/static-property-placement */
|
|
2
|
+
/* eslint-env browser */
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { isElementInViewport } from '../lib/helpers';
|
|
5
|
+
|
|
6
|
+
type AUSpinnerComponentState = {
|
|
7
|
+
loading: boolean,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
class AUSpinnerComponent extends React.Component<AUSpinnerComponentProps, AUSpinnerComponentState> {
|
|
11
|
+
static displayName = 'AUSpinnerComponent';
|
|
12
|
+
|
|
13
|
+
static defaultProps = {
|
|
14
|
+
domID: 'au-spinner-component',
|
|
15
|
+
visible: false,
|
|
16
|
+
className: '',
|
|
17
|
+
height: 'auto',
|
|
18
|
+
init: '',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
constructor(props: AUSpinnerComponentProps) {
|
|
22
|
+
super(props);
|
|
23
|
+
|
|
24
|
+
this.state = {
|
|
25
|
+
loading: true,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
this.lazyLoad = this.lazyLoad.bind(this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
componentDidMount() {
|
|
32
|
+
this.lazyLoad();
|
|
33
|
+
window.addEventListener('scroll', () => {
|
|
34
|
+
this.lazyLoad();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
componentDidUpdate() {
|
|
39
|
+
this.lazyLoad();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
lazyLoad() {
|
|
43
|
+
const {
|
|
44
|
+
loadingCondition,
|
|
45
|
+
loaded,
|
|
46
|
+
visible,
|
|
47
|
+
domID,
|
|
48
|
+
onLoad,
|
|
49
|
+
} = this.props;
|
|
50
|
+
const { loading } = this.state;
|
|
51
|
+
|
|
52
|
+
const element = document.getElementById(domID || '');
|
|
53
|
+
if (element
|
|
54
|
+
&& !loaded
|
|
55
|
+
&& loading
|
|
56
|
+
&& loadingCondition
|
|
57
|
+
&& (visible || isElementInViewport(element))) {
|
|
58
|
+
this.setState({
|
|
59
|
+
loading: false,
|
|
60
|
+
}, () => {
|
|
61
|
+
onLoad();
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
render() {
|
|
67
|
+
const {
|
|
68
|
+
loaded, domID, children, init, className, height,
|
|
69
|
+
} = this.props;
|
|
70
|
+
|
|
71
|
+
if (!loaded) {
|
|
72
|
+
if (init === 'table') {
|
|
73
|
+
return (
|
|
74
|
+
<div id={domID} className={`processing-state processing-state--init-table ${className}`} style={{ minHeight: height }} />
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (init === 'box') {
|
|
78
|
+
return (
|
|
79
|
+
<div id={domID} className={`processing-state processing-state--init-box ${className}`} style={{ minHeight: height }} />
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return (
|
|
83
|
+
<div id={domID} className={`processing-state ${className}`} style={{ minHeight: height }} />
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return children;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default AUSpinnerComponent;
|