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

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.10",
4
+ "version": "9.11.14",
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,57 @@
1
1
  /* eslint-env browser */
2
- import React from 'react';
2
+ import React, { useEffect, useState } from 'react';
3
3
  import PropTypes from 'prop-types';
4
4
  import { isElementInViewport } from '../../lib/helpers';
5
5
 
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();
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();
20
27
  window.addEventListener('scroll', () => {
21
- this.lazyLoad();
28
+ lazyLoad();
22
29
  });
23
- }
24
-
25
- componentDidUpdate() {
26
- this.lazyLoad();
27
- }
30
+ }, []);
28
31
 
29
- static getDerivedStateFromProps(nextProps, prevState) {
30
- if (nextProps.visible !== prevState.visible) {
31
- return {
32
- visible: nextProps.visible,
33
- };
34
- }
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
- });
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
+ );
55
37
  }
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
- }
38
+ if (init === 'box') {
74
39
  return (
75
- <div id={domID} className={`processing-state ${className}`} style={{ minHeight: height }} />
40
+ <div id={domID} className={`processing-state processing-state--init-box ${className}`} style={{ minHeight: height }} />
76
41
  );
77
42
  }
78
-
79
- return children || content;
43
+ return (
44
+ <div id={domID} className={`processing-state ${className}`} style={{ minHeight: height }} />
45
+ );
80
46
  }
81
- }
47
+
48
+ return children;
49
+ };
82
50
 
83
51
  AUSpinnerComponent.defaultProps = {
84
52
  domID: 'au-spinner-component',
85
53
  visible: false,
86
54
  className: '',
87
- content: null,
88
55
  children: null,
89
56
  onLoad: () => { },
90
57
  height: 'auto',
@@ -92,16 +59,9 @@ AUSpinnerComponent.defaultProps = {
92
59
  };
93
60
 
94
61
  AUSpinnerComponent.propTypes = {
95
- /**
96
- * Relevant ved mere end en spinner per side
97
- */
98
62
  domID: PropTypes.string,
99
- /**
100
- * Om den er synlig på skærmen ved indlæsning
101
- */
102
63
  visible: PropTypes.bool,
103
64
  className: PropTypes.string,
104
- content: PropTypes.element,
105
65
  children: PropTypes.element,
106
66
  loaded: PropTypes.bool.isRequired,
107
67
  loadingCondition: PropTypes.bool.isRequired,