@aarhus-university/au-lib-react-components 11.3.2 → 11.4.0
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/.eslintrc.js +34 -34
- package/.storybook/main.js +20 -20
- package/.storybook/preview.js +17 -17
- package/README.md +19 -19
- package/__tests__/jest/AUButtonComponent.test.tsx +165 -165
- package/__tests__/jest/AUErrorComponent.test.tsx +142 -142
- package/__tests__/jest/AUModalComponent.test.tsx +186 -186
- package/__tests__/jest/AUNotificationComponent.test.tsx +115 -115
- package/__tests__/jest/AUSpinnerComponent.test.tsx +57 -57
- package/__tests__/jest/AUToolbarComponent.test.tsx +46 -46
- package/__tests__/jest/context.test.ts +25 -25
- package/__tests__/jest/helpers.test.ts +15 -15
- package/__tests__/jest/setupTests.ts +2 -2
- package/babel.config.js +8 -8
- package/build/umd/all.css +2 -2
- package/build/umd/all.js +1 -1
- package/build/umd/alphabox.js +1 -1
- package/build/umd/databox.js +1 -1
- package/build/umd/diagramme.js +1 -1
- package/build/umd/flowbox.js +1 -1
- package/build/umd/universe.js +1 -1
- package/build-storybook.log +367 -367
- package/package.json +114 -114
- package/src/components/AUAlertComponent.tsx +70 -70
- package/src/components/AUAutoSuggestComponent.js +158 -158
- package/src/components/AUButtonComponent.tsx +84 -84
- package/src/components/AUCalendarComponent.tsx +493 -493
- package/src/components/AUContentToggleComponent.tsx +47 -47
- package/src/components/AUDatepickerComponent.tsx +121 -121
- package/src/components/AUErrorComponent.tsx +78 -78
- package/src/components/AUMobilePrefixComponent.tsx +15 -15
- package/src/components/AUModalComponent.tsx +68 -68
- package/src/components/AUNotificationComponent.tsx +43 -43
- package/src/components/AUReceiptComponent.tsx +33 -33
- package/src/components/AUSpinnerComponent.tsx +36 -36
- package/src/components/AUStepComponent.tsx +47 -41
- package/src/components/AUSubNavComponent.tsx +48 -48
- package/src/components/AUSubmitButtonContainerComponent.tsx +29 -29
- package/src/components/AUTabbedContentComponent.tsx +145 -145
- package/src/components/AUTableComponent.tsx +24 -24
- package/src/components/AUToastComponent.tsx +104 -104
- package/src/components/AUToolbarComponent.tsx +101 -101
- package/src/components/AUTruncatorComponent.tsx +124 -129
- package/src/components/wrapping/AUEmbedComponent.js +47 -47
- package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +143 -143
- package/src/layout-2016/components/alphabox/AlphaBoxContentComponent.js +136 -136
- package/src/layout-2016/components/common/AUCollapsibleComponent.js +152 -152
- package/src/layout-2016/components/common/AUSpinnerComponent.js +103 -103
- package/src/layout-2016/components/databox/DataBoxAlphabetComponent.js +144 -144
- package/src/layout-2016/components/databox/DataBoxAssociationComponent.js +122 -122
- package/src/layout-2016/components/databox/DataBoxButtonComponent.js +157 -157
- package/src/layout-2016/components/databox/DataBoxComponent.js +297 -297
- package/src/layout-2016/components/databox/DataBoxGroupingComponent.js +64 -64
- package/src/layout-2016/components/databox/DataBoxSearchResultComponent.js +36 -36
- package/src/layout-2016/components/databox/DataBoxStackedAssociationComponent.js +54 -54
- package/src/layout-2016/components/databox/DataBoxSuggestionComponent.js +39 -39
- package/src/layout-2016/components/diagramme/AUDiagrammeComponent.js +309 -309
- package/src/layout-2016/components/flowbox/FlowBoxComponent.js +126 -126
- package/src/layout-2016/components/flowbox/FlowBoxPhoneComponent.js +104 -104
- package/src/layout-2016/components/profile/AUProfileAvatar2016Component.js +103 -103
- package/src/layout-2016/components/universe/StaffTopComponent.js +363 -363
- package/src/layout-2016/components/universe/StudentTopComponent.js +137 -137
- package/src/layout-2016/components/universe/UniverseContainerComponent.js +65 -65
- package/src/layout-2016/lib/all.js +3 -3
- package/src/layout-2016/lib/au-alphabox.js +100 -100
- package/src/layout-2016/lib/au-databox.js +400 -400
- package/src/layout-2016/lib/au-diagramme.js +85 -85
- package/src/layout-2016/lib/au-flowbox.js +93 -93
- package/src/layout-2016/lib/universe.js +9 -9
- package/src/lib/context.tsx +51 -51
- package/src/lib/dates.ts +50 -50
- package/src/lib/helpers.ts +208 -208
- package/src/lib/hooks.ts +75 -75
- package/src/lib/i18n.ts +600 -600
- package/src/lib/portals.tsx +119 -119
- package/src/lib/tracking.ts +69 -69
- package/src/lib/wrapping.ts +21 -21
- package/src/styles/_settings.scss +10 -10
- package/src/styles/alphabox.scss +222 -222
- package/src/styles/app.scss +7 -7
- package/src/styles/autosuggest.scss +57 -57
- package/src/styles/databox.scss +563 -563
- package/src/styles/diagramme.scss +119 -119
- package/src/styles/flowbox.scss +72 -72
- package/src/styles/maps.scss +395 -395
- package/stories/AUButtonComponent.stories.tsx +127 -127
- package/stories/AUContentToggleComponent.stories.tsx +63 -63
- package/stories/AUErrorComponent.stories.tsx +98 -98
- package/stories/AUModalComponent.stories.tsx +83 -83
- package/stories/AUNotificationComponent.stories.tsx +116 -116
- package/stories/AUSpinnerComponent.stories.tsx +41 -41
- package/stories/AUStepComponent.stories.tsx +40 -40
- package/stories/AUToolbarComponent.stories.tsx +326 -326
- package/stories/AUTruncatorComponent.stories.tsx +102 -0
- package/stories/lib/helpers.tsx +128 -128
- package/tsconfig.json +46 -46
- package/webpack.config.js +89 -89
|
@@ -1,152 +1,152 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
|
|
5
|
-
class AUCollapsibleComponent extends React.Component {
|
|
6
|
-
constructor(props) {
|
|
7
|
-
super(props);
|
|
8
|
-
|
|
9
|
-
this.state = {
|
|
10
|
-
collapsed: props.collapsed,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
componentDidMount() {
|
|
15
|
-
const { attributes } = this.props;
|
|
16
|
-
attributes.forEach((a) => {
|
|
17
|
-
if (a.selector) {
|
|
18
|
-
const el = this.node.querySelector(a.selector);
|
|
19
|
-
if (el) {
|
|
20
|
-
el.setAttribute(a.attr, a.value);
|
|
21
|
-
}
|
|
22
|
-
} else {
|
|
23
|
-
this.node.setAttribute(a.attr, a.value);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
render() {
|
|
29
|
-
const {
|
|
30
|
-
header,
|
|
31
|
-
level,
|
|
32
|
-
content,
|
|
33
|
-
classNames,
|
|
34
|
-
onClick,
|
|
35
|
-
children,
|
|
36
|
-
dataID,
|
|
37
|
-
headerElement,
|
|
38
|
-
} = this.props;
|
|
39
|
-
const { collapsed } = this.state;
|
|
40
|
-
let className = 'csc-frame au_collapsible';
|
|
41
|
-
if (collapsed) {
|
|
42
|
-
className += ' au_collapsed';
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (classNames) {
|
|
46
|
-
className += ` ${classNames}`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<div data-id={dataID} ref={(node) => { this.node = node; }} className={className}>
|
|
51
|
-
{(() => {
|
|
52
|
-
if (level > -1) {
|
|
53
|
-
return (
|
|
54
|
-
<div
|
|
55
|
-
className="csc-header"
|
|
56
|
-
onClick={() => {
|
|
57
|
-
this.setState((prevState) => ({
|
|
58
|
-
collapsed: !prevState.collapsed,
|
|
59
|
-
}), () => {
|
|
60
|
-
const { collapsed: newCollapsed } = this.state;
|
|
61
|
-
onClick(newCollapsed, this.node);
|
|
62
|
-
});
|
|
63
|
-
}}
|
|
64
|
-
onKeyUp={() => {
|
|
65
|
-
|
|
66
|
-
}}
|
|
67
|
-
role="button"
|
|
68
|
-
tabIndex={0}
|
|
69
|
-
>
|
|
70
|
-
{(() => {
|
|
71
|
-
switch (level) {
|
|
72
|
-
case 0 && headerElement != null:
|
|
73
|
-
return headerElement;
|
|
74
|
-
case 1:
|
|
75
|
-
return (
|
|
76
|
-
<h1>
|
|
77
|
-
{header}
|
|
78
|
-
</h1>
|
|
79
|
-
);
|
|
80
|
-
case 2:
|
|
81
|
-
return (
|
|
82
|
-
<h2>
|
|
83
|
-
{header}
|
|
84
|
-
</h2>
|
|
85
|
-
);
|
|
86
|
-
case 3:
|
|
87
|
-
return (
|
|
88
|
-
<h3>
|
|
89
|
-
{header}
|
|
90
|
-
</h3>
|
|
91
|
-
);
|
|
92
|
-
case 4:
|
|
93
|
-
return (
|
|
94
|
-
<h4>
|
|
95
|
-
{header}
|
|
96
|
-
</h4>
|
|
97
|
-
);
|
|
98
|
-
case 5:
|
|
99
|
-
return (
|
|
100
|
-
<h5>
|
|
101
|
-
{header}
|
|
102
|
-
</h5>
|
|
103
|
-
);
|
|
104
|
-
default:
|
|
105
|
-
return (
|
|
106
|
-
<h6>
|
|
107
|
-
{header}
|
|
108
|
-
</h6>
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
})()}
|
|
112
|
-
</div>
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
|
-
return null;
|
|
116
|
-
})()}
|
|
117
|
-
{children || content}
|
|
118
|
-
</div>
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
AUCollapsibleComponent.defaultProps = {
|
|
124
|
-
dataID: null,
|
|
125
|
-
children: null,
|
|
126
|
-
content: null,
|
|
127
|
-
header: '',
|
|
128
|
-
headerElement: null,
|
|
129
|
-
level: 1,
|
|
130
|
-
classNames: '',
|
|
131
|
-
onClick: () => { },
|
|
132
|
-
attributes: [],
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
AUCollapsibleComponent.propTypes = {
|
|
136
|
-
dataID: PropTypes.string,
|
|
137
|
-
children: PropTypes.element,
|
|
138
|
-
collapsed: PropTypes.bool.isRequired,
|
|
139
|
-
header: PropTypes.string,
|
|
140
|
-
headerElement: PropTypes.element,
|
|
141
|
-
level: PropTypes.number,
|
|
142
|
-
content: PropTypes.element,
|
|
143
|
-
classNames: PropTypes.string,
|
|
144
|
-
onClick: PropTypes.func,
|
|
145
|
-
attributes: PropTypes.arrayOf(PropTypes.shape({
|
|
146
|
-
attr: PropTypes.string,
|
|
147
|
-
value: PropTypes.string,
|
|
148
|
-
selector: PropTypes.string,
|
|
149
|
-
})),
|
|
150
|
-
};
|
|
151
|
-
AUCollapsibleComponent.displayName = 'AUCollapsibleComponent';
|
|
152
|
-
export default AUCollapsibleComponent;
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
|
|
5
|
+
class AUCollapsibleComponent extends React.Component {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
super(props);
|
|
8
|
+
|
|
9
|
+
this.state = {
|
|
10
|
+
collapsed: props.collapsed,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
componentDidMount() {
|
|
15
|
+
const { attributes } = this.props;
|
|
16
|
+
attributes.forEach((a) => {
|
|
17
|
+
if (a.selector) {
|
|
18
|
+
const el = this.node.querySelector(a.selector);
|
|
19
|
+
if (el) {
|
|
20
|
+
el.setAttribute(a.attr, a.value);
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
this.node.setAttribute(a.attr, a.value);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
render() {
|
|
29
|
+
const {
|
|
30
|
+
header,
|
|
31
|
+
level,
|
|
32
|
+
content,
|
|
33
|
+
classNames,
|
|
34
|
+
onClick,
|
|
35
|
+
children,
|
|
36
|
+
dataID,
|
|
37
|
+
headerElement,
|
|
38
|
+
} = this.props;
|
|
39
|
+
const { collapsed } = this.state;
|
|
40
|
+
let className = 'csc-frame au_collapsible';
|
|
41
|
+
if (collapsed) {
|
|
42
|
+
className += ' au_collapsed';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (classNames) {
|
|
46
|
+
className += ` ${classNames}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div data-id={dataID} ref={(node) => { this.node = node; }} className={className}>
|
|
51
|
+
{(() => {
|
|
52
|
+
if (level > -1) {
|
|
53
|
+
return (
|
|
54
|
+
<div
|
|
55
|
+
className="csc-header"
|
|
56
|
+
onClick={() => {
|
|
57
|
+
this.setState((prevState) => ({
|
|
58
|
+
collapsed: !prevState.collapsed,
|
|
59
|
+
}), () => {
|
|
60
|
+
const { collapsed: newCollapsed } = this.state;
|
|
61
|
+
onClick(newCollapsed, this.node);
|
|
62
|
+
});
|
|
63
|
+
}}
|
|
64
|
+
onKeyUp={() => {
|
|
65
|
+
|
|
66
|
+
}}
|
|
67
|
+
role="button"
|
|
68
|
+
tabIndex={0}
|
|
69
|
+
>
|
|
70
|
+
{(() => {
|
|
71
|
+
switch (level) {
|
|
72
|
+
case 0 && headerElement != null:
|
|
73
|
+
return headerElement;
|
|
74
|
+
case 1:
|
|
75
|
+
return (
|
|
76
|
+
<h1>
|
|
77
|
+
{header}
|
|
78
|
+
</h1>
|
|
79
|
+
);
|
|
80
|
+
case 2:
|
|
81
|
+
return (
|
|
82
|
+
<h2>
|
|
83
|
+
{header}
|
|
84
|
+
</h2>
|
|
85
|
+
);
|
|
86
|
+
case 3:
|
|
87
|
+
return (
|
|
88
|
+
<h3>
|
|
89
|
+
{header}
|
|
90
|
+
</h3>
|
|
91
|
+
);
|
|
92
|
+
case 4:
|
|
93
|
+
return (
|
|
94
|
+
<h4>
|
|
95
|
+
{header}
|
|
96
|
+
</h4>
|
|
97
|
+
);
|
|
98
|
+
case 5:
|
|
99
|
+
return (
|
|
100
|
+
<h5>
|
|
101
|
+
{header}
|
|
102
|
+
</h5>
|
|
103
|
+
);
|
|
104
|
+
default:
|
|
105
|
+
return (
|
|
106
|
+
<h6>
|
|
107
|
+
{header}
|
|
108
|
+
</h6>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
})()}
|
|
112
|
+
</div>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
})()}
|
|
117
|
+
{children || content}
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
AUCollapsibleComponent.defaultProps = {
|
|
124
|
+
dataID: null,
|
|
125
|
+
children: null,
|
|
126
|
+
content: null,
|
|
127
|
+
header: '',
|
|
128
|
+
headerElement: null,
|
|
129
|
+
level: 1,
|
|
130
|
+
classNames: '',
|
|
131
|
+
onClick: () => { },
|
|
132
|
+
attributes: [],
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
AUCollapsibleComponent.propTypes = {
|
|
136
|
+
dataID: PropTypes.string,
|
|
137
|
+
children: PropTypes.element,
|
|
138
|
+
collapsed: PropTypes.bool.isRequired,
|
|
139
|
+
header: PropTypes.string,
|
|
140
|
+
headerElement: PropTypes.element,
|
|
141
|
+
level: PropTypes.number,
|
|
142
|
+
content: PropTypes.element,
|
|
143
|
+
classNames: PropTypes.string,
|
|
144
|
+
onClick: PropTypes.func,
|
|
145
|
+
attributes: PropTypes.arrayOf(PropTypes.shape({
|
|
146
|
+
attr: PropTypes.string,
|
|
147
|
+
value: PropTypes.string,
|
|
148
|
+
selector: PropTypes.string,
|
|
149
|
+
})),
|
|
150
|
+
};
|
|
151
|
+
AUCollapsibleComponent.displayName = 'AUCollapsibleComponent';
|
|
152
|
+
export default AUCollapsibleComponent;
|
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
-
/* eslint-env browser */
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import { isElementInViewport } from '../../../lib/helpers';
|
|
6
|
-
|
|
7
|
-
class AUSpinnerComponent extends React.Component {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
|
|
11
|
-
this.state = {
|
|
12
|
-
loading: true,
|
|
13
|
-
visible: props.visible,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
this.lazyLoad = this.lazyLoad.bind(this);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
componentDidMount() {
|
|
20
|
-
this.lazyLoad();
|
|
21
|
-
window.addEventListener('scroll', () => {
|
|
22
|
-
this.lazyLoad();
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
componentDidUpdate() {
|
|
27
|
-
this.lazyLoad();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static getDerivedStateFromProps(nextProps, prevState) {
|
|
31
|
-
if (nextProps.visible !== prevState.visible) {
|
|
32
|
-
return {
|
|
33
|
-
visible: nextProps.visible,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
lazyLoad() {
|
|
41
|
-
const {
|
|
42
|
-
loadingCondition,
|
|
43
|
-
loaded,
|
|
44
|
-
domID,
|
|
45
|
-
onLoad,
|
|
46
|
-
} = this.props;
|
|
47
|
-
const { loading, visible } = this.state;
|
|
48
|
-
|
|
49
|
-
const element = document.getElementById(domID);
|
|
50
|
-
if (!loaded && loading && loadingCondition && (visible || isElementInViewport(element))) {
|
|
51
|
-
this.setState({
|
|
52
|
-
loading: false,
|
|
53
|
-
}, () => {
|
|
54
|
-
onLoad();
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
render() {
|
|
60
|
-
const {
|
|
61
|
-
columns, content, loaded, domID, children,
|
|
62
|
-
} = this.props;
|
|
63
|
-
|
|
64
|
-
if (!loaded) {
|
|
65
|
-
return (
|
|
66
|
-
<div id={domID} className={`cell column ${columns}`}>
|
|
67
|
-
<p className="spinner" />
|
|
68
|
-
</div>
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return children || content;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
AUSpinnerComponent.defaultProps = {
|
|
77
|
-
domID: 'au-spinner-component',
|
|
78
|
-
visible: false,
|
|
79
|
-
columns: 'large-12 medium-12 small-12',
|
|
80
|
-
content: null,
|
|
81
|
-
children: null,
|
|
82
|
-
onLoad: () => {},
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
AUSpinnerComponent.propTypes = {
|
|
86
|
-
/**
|
|
87
|
-
* Relevant ved mere end en spinner per side
|
|
88
|
-
*/
|
|
89
|
-
domID: PropTypes.string,
|
|
90
|
-
/**
|
|
91
|
-
* Om den er synlig på skærmen ved indlæsning
|
|
92
|
-
*/
|
|
93
|
-
visible: PropTypes.bool,
|
|
94
|
-
columns: PropTypes.string,
|
|
95
|
-
content: PropTypes.element,
|
|
96
|
-
children: PropTypes.element,
|
|
97
|
-
loaded: PropTypes.bool.isRequired,
|
|
98
|
-
loadingCondition: PropTypes.bool.isRequired,
|
|
99
|
-
onLoad: PropTypes.func,
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
AUSpinnerComponent.displayName = 'AUSpinnerComponent';
|
|
103
|
-
export default AUSpinnerComponent;
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
+
/* eslint-env browser */
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { isElementInViewport } from '../../../lib/helpers';
|
|
6
|
+
|
|
7
|
+
class AUSpinnerComponent extends React.Component {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
|
|
11
|
+
this.state = {
|
|
12
|
+
loading: true,
|
|
13
|
+
visible: props.visible,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
this.lazyLoad = this.lazyLoad.bind(this);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
componentDidMount() {
|
|
20
|
+
this.lazyLoad();
|
|
21
|
+
window.addEventListener('scroll', () => {
|
|
22
|
+
this.lazyLoad();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
componentDidUpdate() {
|
|
27
|
+
this.lazyLoad();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static getDerivedStateFromProps(nextProps, prevState) {
|
|
31
|
+
if (nextProps.visible !== prevState.visible) {
|
|
32
|
+
return {
|
|
33
|
+
visible: nextProps.visible,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
lazyLoad() {
|
|
41
|
+
const {
|
|
42
|
+
loadingCondition,
|
|
43
|
+
loaded,
|
|
44
|
+
domID,
|
|
45
|
+
onLoad,
|
|
46
|
+
} = this.props;
|
|
47
|
+
const { loading, visible } = this.state;
|
|
48
|
+
|
|
49
|
+
const element = document.getElementById(domID);
|
|
50
|
+
if (!loaded && loading && loadingCondition && (visible || isElementInViewport(element))) {
|
|
51
|
+
this.setState({
|
|
52
|
+
loading: false,
|
|
53
|
+
}, () => {
|
|
54
|
+
onLoad();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
render() {
|
|
60
|
+
const {
|
|
61
|
+
columns, content, loaded, domID, children,
|
|
62
|
+
} = this.props;
|
|
63
|
+
|
|
64
|
+
if (!loaded) {
|
|
65
|
+
return (
|
|
66
|
+
<div id={domID} className={`cell column ${columns}`}>
|
|
67
|
+
<p className="spinner" />
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return children || content;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
AUSpinnerComponent.defaultProps = {
|
|
77
|
+
domID: 'au-spinner-component',
|
|
78
|
+
visible: false,
|
|
79
|
+
columns: 'large-12 medium-12 small-12',
|
|
80
|
+
content: null,
|
|
81
|
+
children: null,
|
|
82
|
+
onLoad: () => {},
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
AUSpinnerComponent.propTypes = {
|
|
86
|
+
/**
|
|
87
|
+
* Relevant ved mere end en spinner per side
|
|
88
|
+
*/
|
|
89
|
+
domID: PropTypes.string,
|
|
90
|
+
/**
|
|
91
|
+
* Om den er synlig på skærmen ved indlæsning
|
|
92
|
+
*/
|
|
93
|
+
visible: PropTypes.bool,
|
|
94
|
+
columns: PropTypes.string,
|
|
95
|
+
content: PropTypes.element,
|
|
96
|
+
children: PropTypes.element,
|
|
97
|
+
loaded: PropTypes.bool.isRequired,
|
|
98
|
+
loadingCondition: PropTypes.bool.isRequired,
|
|
99
|
+
onLoad: PropTypes.func,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
AUSpinnerComponent.displayName = 'AUSpinnerComponent';
|
|
103
|
+
export default AUSpinnerComponent;
|