@aarhus-university/au-lib-react-components 9.11.10 → 9.11.11
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": "9.11.
|
|
4
|
+
"version": "9.11.11",
|
|
5
5
|
"description": "Library for shared React components for various applications on au.dk",
|
|
6
6
|
"main": "build/cjs/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -1,90 +1,58 @@
|
|
|
1
1
|
/* eslint-env browser */
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { useEffect } from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import { isElementInViewport } from '../../lib/helpers';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
const AUSpinnerComponent = ({
|
|
7
|
+
domID,
|
|
8
|
+
visible,
|
|
9
|
+
className,
|
|
10
|
+
children,
|
|
11
|
+
loaded,
|
|
12
|
+
loadingCondition,
|
|
13
|
+
onLoad,
|
|
14
|
+
height,
|
|
15
|
+
init,
|
|
16
|
+
}) => {
|
|
17
|
+
const lazyLoad = () => {
|
|
18
|
+
const element = document.getElementById(domID);
|
|
19
|
+
if (!loaded && loadingCondition && (visible || isElementInViewport(element))) {
|
|
20
|
+
onLoad();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
useEffect(() => {
|
|
20
24
|
window.addEventListener('scroll', () => {
|
|
21
|
-
|
|
25
|
+
lazyLoad();
|
|
22
26
|
});
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
componentDidUpdate() {
|
|
26
|
-
this.lazyLoad();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static getDerivedStateFromProps(nextProps, prevState) {
|
|
30
|
-
if (nextProps.visible !== prevState.visible) {
|
|
31
|
-
return {
|
|
32
|
-
visible: nextProps.visible,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
27
|
+
}, []);
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
lazyLoad() {
|
|
40
|
-
const {
|
|
41
|
-
loadingCondition,
|
|
42
|
-
loaded,
|
|
43
|
-
domID,
|
|
44
|
-
onLoad,
|
|
45
|
-
} = this.props;
|
|
46
|
-
const { loading, visible } = this.state;
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
lazyLoad();
|
|
31
|
+
});
|
|
47
32
|
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
onLoad();
|
|
54
|
-
});
|
|
33
|
+
if (!loaded) {
|
|
34
|
+
if (init === 'table') {
|
|
35
|
+
return (
|
|
36
|
+
<div id={domID} className={`processing-state processing-state--init-table ${className}`} style={{ minHeight: height }} />
|
|
37
|
+
);
|
|
55
38
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
render() {
|
|
59
|
-
const {
|
|
60
|
-
className, content, loaded, domID, children, height, init,
|
|
61
|
-
} = this.props;
|
|
62
|
-
|
|
63
|
-
if (!loaded) {
|
|
64
|
-
if (init === 'table') {
|
|
65
|
-
return (
|
|
66
|
-
<div id={domID} className={`processing-state processing-state--init-table ${className}`} style={{ minHeight: height }} />
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
if (init === 'box') {
|
|
70
|
-
return (
|
|
71
|
-
<div id={domID} className={`processing-state processing-state--init-box ${className}`} style={{ minHeight: height }} />
|
|
72
|
-
);
|
|
73
|
-
}
|
|
39
|
+
if (init === 'box') {
|
|
74
40
|
return (
|
|
75
|
-
<div id={domID} className={`processing-state ${className}`} style={{ minHeight: height }} />
|
|
41
|
+
<div id={domID} className={`processing-state processing-state--init-box ${className}`} style={{ minHeight: height }} />
|
|
76
42
|
);
|
|
77
43
|
}
|
|
78
|
-
|
|
79
|
-
|
|
44
|
+
return (
|
|
45
|
+
<div id={domID} className={`processing-state ${className}`} style={{ minHeight: height }} />
|
|
46
|
+
);
|
|
80
47
|
}
|
|
81
|
-
|
|
48
|
+
|
|
49
|
+
return children;
|
|
50
|
+
};
|
|
82
51
|
|
|
83
52
|
AUSpinnerComponent.defaultProps = {
|
|
84
53
|
domID: 'au-spinner-component',
|
|
85
54
|
visible: false,
|
|
86
55
|
className: '',
|
|
87
|
-
content: null,
|
|
88
56
|
children: null,
|
|
89
57
|
onLoad: () => { },
|
|
90
58
|
height: 'auto',
|
|
@@ -92,16 +60,9 @@ AUSpinnerComponent.defaultProps = {
|
|
|
92
60
|
};
|
|
93
61
|
|
|
94
62
|
AUSpinnerComponent.propTypes = {
|
|
95
|
-
/**
|
|
96
|
-
* Relevant ved mere end en spinner per side
|
|
97
|
-
*/
|
|
98
63
|
domID: PropTypes.string,
|
|
99
|
-
/**
|
|
100
|
-
* Om den er synlig på skærmen ved indlæsning
|
|
101
|
-
*/
|
|
102
64
|
visible: PropTypes.bool,
|
|
103
65
|
className: PropTypes.string,
|
|
104
|
-
content: PropTypes.element,
|
|
105
66
|
children: PropTypes.element,
|
|
106
67
|
loaded: PropTypes.bool.isRequired,
|
|
107
68
|
loadingCondition: PropTypes.bool.isRequired,
|