@aarhus-university/au-lib-react-components 9.11.14 → 9.11.15

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