@aarhus-university/au-lib-react-components 11.1.0 → 11.1.1

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.
Files changed (95) hide show
  1. package/.eslintrc.js +34 -34
  2. package/.storybook/main.js +20 -20
  3. package/.storybook/preview.js +17 -17
  4. package/README.md +19 -19
  5. package/__tests__/jest/AUButtonComponent.test.tsx +165 -165
  6. package/__tests__/jest/AUErrorComponent.test.tsx +142 -142
  7. package/__tests__/jest/AUModalComponent.test.tsx +186 -186
  8. package/__tests__/jest/AUNotificationComponent.test.tsx +115 -115
  9. package/__tests__/jest/AUSpinnerComponent.test.tsx +57 -57
  10. package/__tests__/jest/AUToolbarComponent.test.tsx +46 -46
  11. package/__tests__/jest/context.test.ts +25 -25
  12. package/__tests__/jest/helpers.test.ts +15 -15
  13. package/__tests__/jest/setupTests.ts +2 -2
  14. package/babel.config.js +8 -8
  15. package/build/umd/all.css +2 -2
  16. package/build/umd/all.js +1 -1
  17. package/build/umd/alphabox.js +1 -1
  18. package/build/umd/databox.js +1 -1
  19. package/build/umd/diagramme.js +1 -1
  20. package/build/umd/flowbox.js +1 -1
  21. package/build/umd/universe.js +1 -1
  22. package/build-storybook.log +367 -367
  23. package/package.json +114 -114
  24. package/src/components/AUAlertComponent.tsx +70 -70
  25. package/src/components/AUAutoSuggestComponent.js +158 -158
  26. package/src/components/AUButtonComponent.tsx +84 -84
  27. package/src/components/AUCalendarComponent.tsx +493 -493
  28. package/src/components/AUContentToggleComponent.tsx +47 -49
  29. package/src/components/AUDatepickerComponent.tsx +121 -121
  30. package/src/components/AUErrorComponent.tsx +78 -78
  31. package/src/components/AUMobilePrefixComponent.tsx +15 -15
  32. package/src/components/AUModalComponent.tsx +68 -68
  33. package/src/components/AUNotificationComponent.tsx +43 -43
  34. package/src/components/AUReceiptComponent.tsx +33 -33
  35. package/src/components/AUSpinnerComponent.tsx +33 -33
  36. package/src/components/AUSubNavComponent.tsx +48 -48
  37. package/src/components/AUSubmitButtonContainerComponent.tsx +29 -29
  38. package/src/components/AUTabbedContentComponent.tsx +145 -145
  39. package/src/components/AUTableComponent.tsx +24 -24
  40. package/src/components/AUToastComponent.tsx +104 -104
  41. package/src/components/AUToolbarComponent.tsx +101 -101
  42. package/src/components/AUTruncatorComponent.tsx +129 -129
  43. package/src/components/wrapping/AUEmbedComponent.js +47 -47
  44. package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +143 -143
  45. package/src/layout-2016/components/alphabox/AlphaBoxContentComponent.js +136 -136
  46. package/src/layout-2016/components/common/AUCollapsibleComponent.js +152 -152
  47. package/src/layout-2016/components/common/AUSpinnerComponent.js +103 -103
  48. package/src/layout-2016/components/databox/DataBoxAlphabetComponent.js +144 -144
  49. package/src/layout-2016/components/databox/DataBoxAssociationComponent.js +122 -122
  50. package/src/layout-2016/components/databox/DataBoxButtonComponent.js +157 -157
  51. package/src/layout-2016/components/databox/DataBoxComponent.js +297 -297
  52. package/src/layout-2016/components/databox/DataBoxGroupingComponent.js +64 -64
  53. package/src/layout-2016/components/databox/DataBoxSearchResultComponent.js +36 -36
  54. package/src/layout-2016/components/databox/DataBoxStackedAssociationComponent.js +54 -54
  55. package/src/layout-2016/components/databox/DataBoxSuggestionComponent.js +39 -39
  56. package/src/layout-2016/components/diagramme/AUDiagrammeComponent.js +309 -309
  57. package/src/layout-2016/components/flowbox/FlowBoxComponent.js +126 -126
  58. package/src/layout-2016/components/flowbox/FlowBoxPhoneComponent.js +104 -104
  59. package/src/layout-2016/components/profile/AUProfileAvatar2016Component.js +103 -103
  60. package/src/layout-2016/components/universe/StaffTopComponent.js +363 -363
  61. package/src/layout-2016/components/universe/StudentTopComponent.js +137 -137
  62. package/src/layout-2016/components/universe/UniverseContainerComponent.js +65 -65
  63. package/src/layout-2016/lib/all.js +3 -3
  64. package/src/layout-2016/lib/au-alphabox.js +100 -100
  65. package/src/layout-2016/lib/au-databox.js +400 -400
  66. package/src/layout-2016/lib/au-diagramme.js +85 -85
  67. package/src/layout-2016/lib/au-flowbox.js +93 -93
  68. package/src/layout-2016/lib/universe.js +9 -9
  69. package/src/lib/context.tsx +43 -43
  70. package/src/lib/dates.ts +50 -50
  71. package/src/lib/helpers.ts +208 -208
  72. package/src/lib/hooks.ts +63 -63
  73. package/src/lib/i18n.ts +600 -600
  74. package/src/lib/portals.ts +37 -37
  75. package/src/lib/tracking.ts +69 -69
  76. package/src/lib/wrapping.ts +21 -21
  77. package/src/styles/_settings.scss +10 -10
  78. package/src/styles/alphabox.scss +222 -222
  79. package/src/styles/app.scss +7 -7
  80. package/src/styles/autosuggest.scss +57 -57
  81. package/src/styles/databox.scss +563 -563
  82. package/src/styles/diagramme.scss +119 -119
  83. package/src/styles/flowbox.scss +72 -72
  84. package/src/styles/maps.scss +395 -395
  85. package/stories/AUButtonComponent.stories.tsx +127 -127
  86. package/stories/AUContentToggleComponent.stories.tsx +63 -63
  87. package/stories/AUErrorComponent.stories.tsx +98 -98
  88. package/stories/AUModalComponent.stories.tsx +83 -83
  89. package/stories/AUNotificationComponent.stories.tsx +116 -116
  90. package/stories/AUSpinnerComponent.stories.tsx +41 -41
  91. package/stories/AUStepComponent.stories.tsx +40 -40
  92. package/stories/AUToolbarComponent.stories.tsx +326 -220
  93. package/stories/lib/helpers.tsx +128 -128
  94. package/tsconfig.json +46 -46
  95. package/webpack.config.js +89 -89
@@ -1,129 +1,129 @@
1
- import React, {
2
- FC, useEffect, useRef, useState,
3
- } from 'react';
4
- import { overflowsY } from '@aarhus-university/au-designsystem-delphinus/source/js/components/helpers';
5
-
6
- const focusableSelector = 'a[href]:not([tabindex="-1"]), area[href]:not([tabindex="-1"]), input:not([disabled]):not([tabindex="-1"]), select:not([disabled]):not([tabindex="-1"]), textarea:not([disabled]):not([tabindex="-1"]), button:not([disabled]):not([tabindex="-1"]), iframe:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), [contentEditable=true]:not([tabindex="-1"])';
7
- const getMaxLinesStyle = (maxLines: number): React.CSSProperties => ({ '--max-lines': maxLines } as React.CSSProperties);
8
-
9
- const setTruncate = (
10
- expandElement: HTMLElement,
11
- contentElement: HTMLElement,
12
- expanded: boolean,
13
- ): void => {
14
- if (!expanded && overflowsY(contentElement)) {
15
- expandElement.removeAttribute('hidden');
16
- } else {
17
- expandElement.parentElement?.classList.add('truncator--no-truncation');
18
- }
19
- };
20
-
21
- const AUTruncatorComponent: FC<AUTruncatorComponentProps> = ({
22
- maxLines,
23
- header,
24
- headerLevel,
25
- children,
26
- classNames,
27
- buttonChild,
28
- }: AUTruncatorComponentProps) => {
29
- const expandRef = useRef<HTMLButtonElement>(null);
30
- const contentRef = useRef<HTMLDivElement>(null);
31
- const [expanded, setExpanded] = useState<boolean>(false);
32
- useEffect(() => {
33
- setTruncate(expandRef.current as HTMLElement, contentRef.current as HTMLElement, expanded);
34
- const focusElements = contentRef.current?.querySelectorAll(focusableSelector);
35
-
36
- const onFocus = (event: Event) => {
37
- if (overflowsY(event.target as HTMLElement)) {
38
- setExpanded(true);
39
- }
40
- };
41
-
42
- if (focusElements) {
43
- focusElements.forEach((f) => {
44
- f.addEventListener('focus', onFocus);
45
- });
46
- }
47
-
48
- const onResize = () => {
49
- setTruncate(expandRef.current as HTMLElement, contentRef.current as HTMLElement, expanded);
50
- };
51
-
52
- window.addEventListener('resize', onResize);
53
-
54
- return () => {
55
- if (focusElements) {
56
- focusElements.forEach((f) => {
57
- f.removeEventListener('focus', onFocus);
58
- });
59
- }
60
- window.removeEventListener('resize', onResize);
61
- };
62
- }, [expanded]);
63
-
64
- return (
65
- <div className={`${classNames}${expanded ? ' truncator--no-truncation' : ''}`} style={getMaxLinesStyle(maxLines)}>
66
- {
67
- header && (
68
- <>
69
- {
70
- headerLevel === 1 && (
71
- <h1 className="truncator__header">{header}</h1>
72
- )
73
- }
74
- {
75
- headerLevel === 2 && (
76
- <h2 className="truncator__header">{header}</h2>
77
- )
78
- }
79
- {
80
- headerLevel === 3 && (
81
- <h3 className="truncator__header">{header}</h3>
82
- )
83
- }
84
- {
85
- headerLevel === 4 && (
86
- <h4 className="truncator__header">{header}</h4>
87
- )
88
- }
89
- {
90
- headerLevel === 5 && (
91
- <h5 className="truncator__header">{header}</h5>
92
- )
93
- }
94
- {
95
- headerLevel === 6 && (
96
- <h6 className="truncator__header">{header}</h6>
97
- )
98
- }
99
- </>
100
- )
101
- }
102
- <button
103
- ref={expandRef}
104
- type="button"
105
- className="truncator__expand"
106
- hidden
107
- aria-expanded={expanded}
108
- onClick={() => setExpanded(true)}
109
- >
110
- {buttonChild}
111
- </button>
112
- <div
113
- ref={contentRef}
114
- className="truncator__content"
115
- >
116
- {children}
117
- </div>
118
- </div>
119
- );
120
- };
121
-
122
- AUTruncatorComponent.defaultProps = {
123
- header: undefined,
124
- headerLevel: 2,
125
- classNames: 'truncator',
126
- };
127
-
128
- AUTruncatorComponent.displayName = 'AUTruncatorComponent';
129
- export default AUTruncatorComponent;
1
+ import React, {
2
+ FC, useEffect, useRef, useState,
3
+ } from 'react';
4
+ import { overflowsY } from '@aarhus-university/au-designsystem-delphinus/source/js/components/helpers';
5
+
6
+ const focusableSelector = 'a[href]:not([tabindex="-1"]), area[href]:not([tabindex="-1"]), input:not([disabled]):not([tabindex="-1"]), select:not([disabled]):not([tabindex="-1"]), textarea:not([disabled]):not([tabindex="-1"]), button:not([disabled]):not([tabindex="-1"]), iframe:not([tabindex="-1"]), [tabindex]:not([tabindex="-1"]), [contentEditable=true]:not([tabindex="-1"])';
7
+ const getMaxLinesStyle = (maxLines: number): React.CSSProperties => ({ '--max-lines': maxLines } as React.CSSProperties);
8
+
9
+ const setTruncate = (
10
+ expandElement: HTMLElement,
11
+ contentElement: HTMLElement,
12
+ expanded: boolean,
13
+ ): void => {
14
+ if (!expanded && overflowsY(contentElement)) {
15
+ expandElement.removeAttribute('hidden');
16
+ } else {
17
+ expandElement.parentElement?.classList.add('truncator--no-truncation');
18
+ }
19
+ };
20
+
21
+ const AUTruncatorComponent: FC<AUTruncatorComponentProps> = ({
22
+ maxLines,
23
+ header,
24
+ headerLevel,
25
+ children,
26
+ classNames,
27
+ buttonChild,
28
+ }: AUTruncatorComponentProps) => {
29
+ const expandRef = useRef<HTMLButtonElement>(null);
30
+ const contentRef = useRef<HTMLDivElement>(null);
31
+ const [expanded, setExpanded] = useState<boolean>(false);
32
+ useEffect(() => {
33
+ setTruncate(expandRef.current as HTMLElement, contentRef.current as HTMLElement, expanded);
34
+ const focusElements = contentRef.current?.querySelectorAll(focusableSelector);
35
+
36
+ const onFocus = (event: Event) => {
37
+ if (overflowsY(event.target as HTMLElement)) {
38
+ setExpanded(true);
39
+ }
40
+ };
41
+
42
+ if (focusElements) {
43
+ focusElements.forEach((f) => {
44
+ f.addEventListener('focus', onFocus);
45
+ });
46
+ }
47
+
48
+ const onResize = () => {
49
+ setTruncate(expandRef.current as HTMLElement, contentRef.current as HTMLElement, expanded);
50
+ };
51
+
52
+ window.addEventListener('resize', onResize);
53
+
54
+ return () => {
55
+ if (focusElements) {
56
+ focusElements.forEach((f) => {
57
+ f.removeEventListener('focus', onFocus);
58
+ });
59
+ }
60
+ window.removeEventListener('resize', onResize);
61
+ };
62
+ }, [expanded]);
63
+
64
+ return (
65
+ <div className={`${classNames}${expanded ? ' truncator--no-truncation' : ''}`} style={getMaxLinesStyle(maxLines)}>
66
+ {
67
+ header && (
68
+ <>
69
+ {
70
+ headerLevel === 1 && (
71
+ <h1 className="truncator__header">{header}</h1>
72
+ )
73
+ }
74
+ {
75
+ headerLevel === 2 && (
76
+ <h2 className="truncator__header">{header}</h2>
77
+ )
78
+ }
79
+ {
80
+ headerLevel === 3 && (
81
+ <h3 className="truncator__header">{header}</h3>
82
+ )
83
+ }
84
+ {
85
+ headerLevel === 4 && (
86
+ <h4 className="truncator__header">{header}</h4>
87
+ )
88
+ }
89
+ {
90
+ headerLevel === 5 && (
91
+ <h5 className="truncator__header">{header}</h5>
92
+ )
93
+ }
94
+ {
95
+ headerLevel === 6 && (
96
+ <h6 className="truncator__header">{header}</h6>
97
+ )
98
+ }
99
+ </>
100
+ )
101
+ }
102
+ <button
103
+ ref={expandRef}
104
+ type="button"
105
+ className="truncator__expand"
106
+ hidden
107
+ aria-expanded={expanded}
108
+ onClick={() => setExpanded(true)}
109
+ >
110
+ {buttonChild}
111
+ </button>
112
+ <div
113
+ ref={contentRef}
114
+ className="truncator__content"
115
+ >
116
+ {children}
117
+ </div>
118
+ </div>
119
+ );
120
+ };
121
+
122
+ AUTruncatorComponent.defaultProps = {
123
+ header: undefined,
124
+ headerLevel: 2,
125
+ classNames: 'truncator',
126
+ };
127
+
128
+ AUTruncatorComponent.displayName = 'AUTruncatorComponent';
129
+ export default AUTruncatorComponent;
@@ -1,47 +1,47 @@
1
- /* eslint-env browser */
2
- import React, { useState } from 'react';
3
- import PropTypes from 'prop-types';
4
- import AUSpinnerComponent from '../delphinus/AUSpinnerComponent';
5
- import getSourceForFrame from '../../lib/wrapping';
6
-
7
- const AUEmbedComponent = ({
8
- api,
9
- path,
10
- referrer,
11
- }) => {
12
- const [source, setSource] = useState(null);
13
- const [frameLoaded, setFrameLoaded] = useState(false);
14
-
15
- return (
16
- <AUSpinnerComponent
17
- loaded={frameLoaded}
18
- loadingCondition={!frameLoaded}
19
- onLoad={() => {
20
- getSourceForFrame(api, path, referrer, (frameSrc) => {
21
- setSource(frameSrc.url);
22
- setFrameLoaded(true);
23
- });
24
- }}
25
- >
26
- <iframe
27
- id="AUEmbedIframe"
28
- title="AUEmbed"
29
- src={source}
30
- onLoad={() => {
31
- if (window.iFrameResize) {
32
- window.iFrameResize({ heightCalculationMethods: 'taggedElement', log: false }, '#AUEmbedIframe');
33
- }
34
- }}
35
- />
36
- </AUSpinnerComponent>
37
- );
38
- };
39
-
40
- AUEmbedComponent.propTypes = {
41
- path: PropTypes.string.isRequired,
42
- api: PropTypes.string.isRequired,
43
- referrer: PropTypes.string.isRequired,
44
- };
45
-
46
- AUEmbedComponent.displayName = 'AUEmbedComponent';
47
- export default AUEmbedComponent;
1
+ /* eslint-env browser */
2
+ import React, { useState } from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import AUSpinnerComponent from '../delphinus/AUSpinnerComponent';
5
+ import getSourceForFrame from '../../lib/wrapping';
6
+
7
+ const AUEmbedComponent = ({
8
+ api,
9
+ path,
10
+ referrer,
11
+ }) => {
12
+ const [source, setSource] = useState(null);
13
+ const [frameLoaded, setFrameLoaded] = useState(false);
14
+
15
+ return (
16
+ <AUSpinnerComponent
17
+ loaded={frameLoaded}
18
+ loadingCondition={!frameLoaded}
19
+ onLoad={() => {
20
+ getSourceForFrame(api, path, referrer, (frameSrc) => {
21
+ setSource(frameSrc.url);
22
+ setFrameLoaded(true);
23
+ });
24
+ }}
25
+ >
26
+ <iframe
27
+ id="AUEmbedIframe"
28
+ title="AUEmbed"
29
+ src={source}
30
+ onLoad={() => {
31
+ if (window.iFrameResize) {
32
+ window.iFrameResize({ heightCalculationMethods: 'taggedElement', log: false }, '#AUEmbedIframe');
33
+ }
34
+ }}
35
+ />
36
+ </AUSpinnerComponent>
37
+ );
38
+ };
39
+
40
+ AUEmbedComponent.propTypes = {
41
+ path: PropTypes.string.isRequired,
42
+ api: PropTypes.string.isRequired,
43
+ referrer: PropTypes.string.isRequired,
44
+ };
45
+
46
+ AUEmbedComponent.displayName = 'AUEmbedComponent';
47
+ export default AUEmbedComponent;
@@ -1,143 +1,143 @@
1
- /* eslint-env browser */
2
- import React from 'react';
3
- import PropTypes from 'prop-types';
4
- import AlphaBoxContentComponent from './AlphaBoxContentComponent';
5
- import AUAutoSuggestComponent from '../../../components/AUAutoSuggestComponent';
6
- import DataBoxSuggestionComponent from '../databox/DataBoxSuggestionComponent';
7
-
8
- class AlphaBoxComponent extends React.Component {
9
- constructor(props) {
10
- super(props);
11
-
12
- this.state = {
13
- items: [],
14
- };
15
-
16
- this.getSuggestions = this.getSuggestions.bind(this);
17
- }
18
-
19
- componentDidMount() {
20
- const { box } = this.props;
21
- const { data } = box;
22
- if (data.mode === 'json' && data.source !== '') {
23
- if (data.itemsOnly) {
24
- data.source += '?itemsOnly=true';
25
- }
26
- fetch(data.source).then((promise) => promise.json()).then((pData) => {
27
- this.setState({ items: pData.items });
28
- });
29
- }
30
- }
31
-
32
- getSuggestions(value, _, callback) {
33
- const { items } = this.state;
34
- const inputValue = value.trim().toLowerCase();
35
- const inputLength = inputValue.length;
36
- callback(inputLength < 2 ? []
37
- : items.filter(
38
- (x) => x.name.toLowerCase().indexOf(inputValue) > -1
39
- || x.name.replace(/-/ig, ' ').toLowerCase().indexOf(inputValue) > -1
40
- || x.name.replace(/ /ig, '-').toLowerCase().indexOf(inputValue) > -1,
41
- )
42
- .sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase(), 'da', { ignorePunctuation: true })));
43
- }
44
-
45
- render() {
46
- const { box } = this.props;
47
- const { items } = this.state;
48
- const { config } = box;
49
- const renderLinks = config.links.map((l) => (
50
- <li key={l.title}>
51
- <a
52
- href={l.url}
53
- onClick={() => {
54
- if (typeof l.onClick === 'function') {
55
- l.onClick();
56
- }
57
- }}
58
- style={{ backgroundColor: box.background.linkColor }}
59
- >
60
- {l.title}
61
- </a>
62
- </li>
63
- ));
64
-
65
- return (
66
- <div className="au_alphabox" style={{ backgroundColor: box.background.color }}>
67
- <div>
68
- <h2>
69
- <a href={config.url}>{config.title}</a>
70
- </h2>
71
- <AlphaBoxContentComponent
72
- items={items}
73
- linkColor={box.background.linkColor}
74
- noResultsText={config.noResultsAlphabet}
75
- noResultsUri={config.noResultsUri}
76
- />
77
- <AUAutoSuggestComponent
78
- placeholder={box.search.placeHolder}
79
- setResults={(_items) => {
80
- if (_items.length >= 1 && _items[0].url) {
81
- window.location.href = _items[0].url;
82
- }
83
- }}
84
- collection={[]}
85
- getSuggestions={this.getSuggestions}
86
- getSuggestionValue={(suggestion) => suggestion.name}
87
- renderSuggestion={(suggestion) => <DataBoxSuggestionComponent item={suggestion} />}
88
- noResultsText={config.noResultsSearch}
89
- />
90
- {
91
- config.description !== '' && (
92
- <h3>{config.description}</h3>
93
- )
94
- }
95
- {
96
- config.links.length > 0 && (
97
- <ul className="quicklinks resetlist">
98
- {renderLinks}
99
- </ul>
100
- )
101
- }
102
- </div>
103
- </div>
104
- );
105
- }
106
- }
107
-
108
- AlphaBoxComponent.propTypes = {
109
- box: PropTypes.shape({
110
- id: PropTypes.number.isRequired,
111
- data: PropTypes.shape({
112
- itemsOnly: PropTypes.bool.isRequired,
113
- mode: PropTypes.string.isRequired,
114
- source: PropTypes.string.isRequired,
115
- }),
116
- config: PropTypes.shape({
117
- name: PropTypes.string.isRequired,
118
- url: PropTypes.string.isRequired,
119
- description: PropTypes.string.isRequired,
120
- container: PropTypes.string.isRequired,
121
- tracking: PropTypes.string.isRequired,
122
- links: PropTypes.arrayOf(PropTypes.shape({
123
- title: PropTypes.string.isRequired,
124
- url: PropTypes.string.isRequired,
125
- })).isRequired,
126
- title: PropTypes.string.isRequired,
127
- noResultsAlphabet: PropTypes.string.isRequired,
128
- noResultsSearch: PropTypes.string.isRequired,
129
- noResultsUri: PropTypes.string.isRequired,
130
- }).isRequired,
131
- background: PropTypes.shape({
132
- color: PropTypes.string.isRequired,
133
- linkColor: PropTypes.string.isRequired,
134
- }).isRequired,
135
- search: PropTypes.shape({
136
- placeHolder: PropTypes.string.isRequired,
137
- minLength: PropTypes.number.isRequired,
138
- }).isRequired,
139
- }).isRequired,
140
- };
141
-
142
- AlphaBoxComponent.displayName = 'AlphaBoxComponent';
143
- export default AlphaBoxComponent;
1
+ /* eslint-env browser */
2
+ import React from 'react';
3
+ import PropTypes from 'prop-types';
4
+ import AlphaBoxContentComponent from './AlphaBoxContentComponent';
5
+ import AUAutoSuggestComponent from '../../../components/AUAutoSuggestComponent';
6
+ import DataBoxSuggestionComponent from '../databox/DataBoxSuggestionComponent';
7
+
8
+ class AlphaBoxComponent extends React.Component {
9
+ constructor(props) {
10
+ super(props);
11
+
12
+ this.state = {
13
+ items: [],
14
+ };
15
+
16
+ this.getSuggestions = this.getSuggestions.bind(this);
17
+ }
18
+
19
+ componentDidMount() {
20
+ const { box } = this.props;
21
+ const { data } = box;
22
+ if (data.mode === 'json' && data.source !== '') {
23
+ if (data.itemsOnly) {
24
+ data.source += '?itemsOnly=true';
25
+ }
26
+ fetch(data.source).then((promise) => promise.json()).then((pData) => {
27
+ this.setState({ items: pData.items });
28
+ });
29
+ }
30
+ }
31
+
32
+ getSuggestions(value, _, callback) {
33
+ const { items } = this.state;
34
+ const inputValue = value.trim().toLowerCase();
35
+ const inputLength = inputValue.length;
36
+ callback(inputLength < 2 ? []
37
+ : items.filter(
38
+ (x) => x.name.toLowerCase().indexOf(inputValue) > -1
39
+ || x.name.replace(/-/ig, ' ').toLowerCase().indexOf(inputValue) > -1
40
+ || x.name.replace(/ /ig, '-').toLowerCase().indexOf(inputValue) > -1,
41
+ )
42
+ .sort((a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase(), 'da', { ignorePunctuation: true })));
43
+ }
44
+
45
+ render() {
46
+ const { box } = this.props;
47
+ const { items } = this.state;
48
+ const { config } = box;
49
+ const renderLinks = config.links.map((l) => (
50
+ <li key={l.title}>
51
+ <a
52
+ href={l.url}
53
+ onClick={() => {
54
+ if (typeof l.onClick === 'function') {
55
+ l.onClick();
56
+ }
57
+ }}
58
+ style={{ backgroundColor: box.background.linkColor }}
59
+ >
60
+ {l.title}
61
+ </a>
62
+ </li>
63
+ ));
64
+
65
+ return (
66
+ <div className="au_alphabox" style={{ backgroundColor: box.background.color }}>
67
+ <div>
68
+ <h2>
69
+ <a href={config.url}>{config.title}</a>
70
+ </h2>
71
+ <AlphaBoxContentComponent
72
+ items={items}
73
+ linkColor={box.background.linkColor}
74
+ noResultsText={config.noResultsAlphabet}
75
+ noResultsUri={config.noResultsUri}
76
+ />
77
+ <AUAutoSuggestComponent
78
+ placeholder={box.search.placeHolder}
79
+ setResults={(_items) => {
80
+ if (_items.length >= 1 && _items[0].url) {
81
+ window.location.href = _items[0].url;
82
+ }
83
+ }}
84
+ collection={[]}
85
+ getSuggestions={this.getSuggestions}
86
+ getSuggestionValue={(suggestion) => suggestion.name}
87
+ renderSuggestion={(suggestion) => <DataBoxSuggestionComponent item={suggestion} />}
88
+ noResultsText={config.noResultsSearch}
89
+ />
90
+ {
91
+ config.description !== '' && (
92
+ <h3>{config.description}</h3>
93
+ )
94
+ }
95
+ {
96
+ config.links.length > 0 && (
97
+ <ul className="quicklinks resetlist">
98
+ {renderLinks}
99
+ </ul>
100
+ )
101
+ }
102
+ </div>
103
+ </div>
104
+ );
105
+ }
106
+ }
107
+
108
+ AlphaBoxComponent.propTypes = {
109
+ box: PropTypes.shape({
110
+ id: PropTypes.number.isRequired,
111
+ data: PropTypes.shape({
112
+ itemsOnly: PropTypes.bool.isRequired,
113
+ mode: PropTypes.string.isRequired,
114
+ source: PropTypes.string.isRequired,
115
+ }),
116
+ config: PropTypes.shape({
117
+ name: PropTypes.string.isRequired,
118
+ url: PropTypes.string.isRequired,
119
+ description: PropTypes.string.isRequired,
120
+ container: PropTypes.string.isRequired,
121
+ tracking: PropTypes.string.isRequired,
122
+ links: PropTypes.arrayOf(PropTypes.shape({
123
+ title: PropTypes.string.isRequired,
124
+ url: PropTypes.string.isRequired,
125
+ })).isRequired,
126
+ title: PropTypes.string.isRequired,
127
+ noResultsAlphabet: PropTypes.string.isRequired,
128
+ noResultsSearch: PropTypes.string.isRequired,
129
+ noResultsUri: PropTypes.string.isRequired,
130
+ }).isRequired,
131
+ background: PropTypes.shape({
132
+ color: PropTypes.string.isRequired,
133
+ linkColor: PropTypes.string.isRequired,
134
+ }).isRequired,
135
+ search: PropTypes.shape({
136
+ placeHolder: PropTypes.string.isRequired,
137
+ minLength: PropTypes.number.isRequired,
138
+ }).isRequired,
139
+ }).isRequired,
140
+ };
141
+
142
+ AlphaBoxComponent.displayName = 'AlphaBoxComponent';
143
+ export default AlphaBoxComponent;