@aarhus-university/au-lib-react-components 10.0.0 → 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.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"
@@ -52,7 +52,9 @@ const AUModalComponent: FC<AUModalComponentProps> = ({
52
52
  if (typeof onClose === 'function') {
53
53
  onClose();
54
54
  }
55
- hideModal(domId, sender);
55
+ if (sender) {
56
+ hideModal(domId, sender);
57
+ }
56
58
  }}
57
59
  >
58
60
  {lang === 'da' ? 'Luk' : 'Close'}
@@ -1,67 +1,91 @@
1
- /* eslint-env browser */
2
- import React, { useState, useEffect, FC } from 'react';
3
- import { isElementInViewport } from '../lib/helpers';
4
-
5
- const AUSpinnerComponent: FC<AUSpinnerComponentProps> = ({
6
- domID,
7
- className,
8
- children,
9
- visible,
10
- loaded,
11
- loadingCondition,
12
- height,
13
- init,
14
- onLoad,
15
- }: AUSpinnerComponentProps) => {
16
- const [loading, setLoading] = useState<boolean>(true);
17
- const lazyLoad = (): void => {
18
- const element = document.getElementById(domID as string);
19
- if (element
20
- && !loaded
21
- && loading
22
- && loadingCondition
23
- && (visible || isElementInViewport(element))) {
24
- setLoading(false);
25
- onLoad();
26
- }
27
- };
28
-
29
- useEffect(() => {
30
- window.addEventListener('scroll', () => {
31
- lazyLoad();
32
- });
33
- });
34
-
35
- useEffect(() => {
36
- lazyLoad();
37
- });
38
-
39
- if (!loaded) {
40
- if (init === 'table') {
41
- return (
42
- <div id={domID} className={`processing-state processing-state--init-table ${className}`} style={{ minHeight: height }} />
43
- );
44
- }
45
- if (init === 'box') {
46
- return (
47
- <div id={domID} className={`processing-state processing-state--init-box ${className}`} style={{ minHeight: height }} />
48
- );
49
- }
50
- return (
51
- <div id={domID} className={`processing-state ${className}`} style={{ minHeight: height }} />
52
- );
53
- }
54
-
55
- return children;
56
- };
57
-
58
- AUSpinnerComponent.defaultProps = {
59
- domID: 'au-spinner-component',
60
- visible: false,
61
- className: '',
62
- height: 'auto',
63
- init: '',
64
- };
65
-
66
- AUSpinnerComponent.displayName = 'AUSpinnerComponent';
67
- export default AUSpinnerComponent;
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;
@@ -50,3 +50,14 @@ interface IProfileSettings {
50
50
  disabled?: boolean,
51
51
  onClick?: (el: Element) => void,
52
52
  }
53
+
54
+ interface ITabbedObject {
55
+ domElement: Element,
56
+ rendered: boolean,
57
+ }
58
+
59
+ interface ITabbedTab {
60
+ href: string,
61
+ text: string,
62
+ dataGtm: string,
63
+ }