@aarhus-university/au-lib-react-components 12.6.2 → 12.6.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.
Files changed (109) hide show
  1. package/.eslintrc.js +35 -35
  2. package/.storybook/main.js +34 -34
  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/AUDynamicContentComponent.test.tsx +386 -386
  7. package/__tests__/jest/AUErrorComponent.test.tsx +142 -142
  8. package/__tests__/jest/AUModalComponent.test.tsx +186 -186
  9. package/__tests__/jest/AUNotificationComponent.test.tsx +115 -115
  10. package/__tests__/jest/AUSpinnerComponent.test.tsx +57 -57
  11. package/__tests__/jest/AUToolbarComponent.test.tsx +46 -46
  12. package/__tests__/jest/context.test.ts +25 -25
  13. package/__tests__/jest/helpers.test.ts +15 -15
  14. package/__tests__/jest/setupTests.ts +2 -2
  15. package/babel.config.js +8 -8
  16. package/build/umd/all.css +2 -2
  17. package/build/umd/all.js +1 -1
  18. package/build/umd/alphabox.js +1 -1
  19. package/build/umd/databox.js +1 -1
  20. package/build/umd/diagramme.js +1 -1
  21. package/build/umd/flowbox.js +1 -1
  22. package/build/umd/flowbox.js.map +1 -1
  23. package/build/umd/universe.js +1 -1
  24. package/build-storybook.log +386 -386
  25. package/esbuild.mjs +22 -22
  26. package/package.json +107 -107
  27. package/src/components/AUAlertComponent.tsx +128 -128
  28. package/src/components/AUAutoSuggestComponent.js +148 -148
  29. package/src/components/AUButtonComponent.tsx +99 -99
  30. package/src/components/AUCalendarComponent.tsx +497 -497
  31. package/src/components/AUCharacterCountComponent.tsx +56 -56
  32. package/src/components/AUComboBoxComponent.tsx +195 -195
  33. package/src/components/AUContentToggleComponent.tsx +50 -50
  34. package/src/components/AUDatepickerComponent.tsx +124 -124
  35. package/src/components/AUDialogModalComponent.tsx +124 -124
  36. package/src/components/AUDynamicContentComponent.tsx +137 -137
  37. package/src/components/AUEditorComponent.tsx +126 -126
  38. package/src/components/AUErrorComponent.tsx +73 -73
  39. package/src/components/AUMobilePrefixComponent.tsx +20 -20
  40. package/src/components/AUModalComponent.tsx +72 -72
  41. package/src/components/AUNotificationComponent.tsx +44 -44
  42. package/src/components/AUReceiptComponent.tsx +34 -34
  43. package/src/components/AUSpinnerComponent.tsx +40 -40
  44. package/src/components/AUStepComponent.tsx +75 -75
  45. package/src/components/AUSubNavComponent.tsx +57 -57
  46. package/src/components/AUSubmitButtonContainerComponent.tsx +38 -38
  47. package/src/components/AUTabbedContentComponent.tsx +154 -154
  48. package/src/components/AUTableComponent.tsx +29 -29
  49. package/src/components/AUToastComponent.tsx +104 -104
  50. package/src/components/AUToolbarComponent.tsx +108 -108
  51. package/src/components/AUTruncatorComponent.tsx +141 -141
  52. package/src/components/wrapping/AUEmbedComponent.js +47 -47
  53. package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +142 -142
  54. package/src/layout-2016/components/alphabox/AlphaBoxContentComponent.js +136 -136
  55. package/src/layout-2016/components/common/AUCollapsibleComponent.js +152 -152
  56. package/src/layout-2016/components/common/AUSpinnerComponent.js +103 -103
  57. package/src/layout-2016/components/databox/DataBoxAlphabetComponent.js +144 -144
  58. package/src/layout-2016/components/databox/DataBoxAssociationComponent.js +122 -122
  59. package/src/layout-2016/components/databox/DataBoxButtonComponent.js +157 -157
  60. package/src/layout-2016/components/databox/DataBoxComponent.js +297 -297
  61. package/src/layout-2016/components/databox/DataBoxGroupingComponent.js +64 -64
  62. package/src/layout-2016/components/databox/DataBoxSearchResultComponent.js +36 -36
  63. package/src/layout-2016/components/databox/DataBoxStackedAssociationComponent.js +54 -54
  64. package/src/layout-2016/components/databox/DataBoxSuggestionComponent.js +39 -39
  65. package/src/layout-2016/components/diagramme/AUDiagrammeComponent.js +309 -309
  66. package/src/layout-2016/components/flowbox/FlowBoxComponent.js +126 -126
  67. package/src/layout-2016/components/flowbox/FlowBoxPhoneComponent.js +104 -104
  68. package/src/layout-2016/lib/all.js +3 -3
  69. package/src/layout-2016/lib/au-alphabox.js +99 -99
  70. package/src/layout-2016/lib/au-databox.js +399 -399
  71. package/src/layout-2016/lib/au-diagramme.js +85 -85
  72. package/src/layout-2016/lib/au-flowbox.js +116 -119
  73. package/src/lib/context.tsx +59 -59
  74. package/src/lib/dates.ts +52 -52
  75. package/src/lib/helpers.ts +208 -208
  76. package/src/lib/hooks.ts +157 -157
  77. package/src/lib/i18n.ts +600 -600
  78. package/src/lib/portals.tsx +150 -150
  79. package/src/lib/tinymce.ts +84 -84
  80. package/src/lib/wrapping.ts +21 -21
  81. package/src/styles/_settings.scss +10 -10
  82. package/src/styles/alphabox.scss +222 -222
  83. package/src/styles/app.scss +7 -7
  84. package/src/styles/autosuggest.scss +57 -57
  85. package/src/styles/databox.scss +563 -563
  86. package/src/styles/diagramme.scss +119 -119
  87. package/src/styles/flowbox.scss +72 -72
  88. package/src/styles/maps.scss +395 -395
  89. package/stories/AUAlertComponent.stories.tsx +133 -133
  90. package/stories/AUAutoSuggestComponent.stories.tsx +95 -95
  91. package/stories/AUButtonComponent.stories.tsx +139 -139
  92. package/stories/AUCharacterCountComponent.stories.tsx +121 -121
  93. package/stories/AUComboBoxComponent.stories.tsx +101 -101
  94. package/stories/AUContentToggleComponent.stories.tsx +87 -87
  95. package/stories/AUDialogModalComponent.stories.tsx +75 -75
  96. package/stories/AUDynamicContentComponent.stories.tsx +119 -119
  97. package/stories/AUEditorComponent.stories.tsx +66 -66
  98. package/stories/AUErrorComponent.stories.tsx +132 -132
  99. package/stories/AUModalComponent.stories.tsx +160 -160
  100. package/stories/AUNotificationComponent.stories.tsx +151 -151
  101. package/stories/AUSpinnerComponent.stories.tsx +44 -44
  102. package/stories/AUStepComponent.stories.tsx +91 -91
  103. package/stories/AUToolbarComponent.stories.tsx +389 -389
  104. package/stories/AUTruncatorComponent.stories.tsx +123 -123
  105. package/stories/lib/helpers.tsx +146 -146
  106. package/tsconfig.json +46 -46
  107. package/webpack.config.js +88 -88
  108. package/.claude/settings.local.json +0 -12
  109. package/.vscode/settings.json +0 -22
@@ -1,141 +1,141 @@
1
- import React, {
2
- FC, useEffect, useRef, useState,
3
- } from 'react';
4
- import { overflowsY, focusableSelector } from '@aarhus-university/au-designsystem-delphinus/source/js/components/helpers';
5
- import { truncate } from '@aarhus-university/au-designsystem-delphinus/source/js/components/truncator';
6
-
7
- const getMaxLinesStyle = (maxLines: number): React.CSSProperties => ({ '--max-lines': maxLines } as React.CSSProperties);
8
-
9
- type Props = {
10
- maxLines: number;
11
- header?: string;
12
- headerLevel?: number;
13
- children: string | JSX.Element | JSX.Element[];
14
- classNames?: string;
15
- buttonChild: JSX.Element;
16
- };
17
-
18
- let lastWidth = window.innerWidth;
19
- let resizeTimeout;
20
- let onResize;
21
- let onFocus;
22
-
23
- const AUTruncatorComponent: FC<Props> = ({
24
- maxLines,
25
- header = undefined,
26
- headerLevel = 2,
27
- children,
28
- classNames = 'truncator',
29
- buttonChild,
30
- }) => {
31
- const expandRef = useRef<HTMLButtonElement>(null);
32
- const contentRef = useRef<HTMLDivElement>(null);
33
- const [expanded, setExpanded] = useState<boolean>(false);
34
- useEffect(() => {
35
- window.removeEventListener('resize', onResize);
36
- if (expanded) {
37
- (expandRef.current as HTMLElement).removeAttribute('hidden');
38
- expandRef.current?.parentElement?.classList.add('truncator--no-truncation');
39
- }
40
- truncate(expandRef.current as HTMLElement, contentRef.current as HTMLElement);
41
-
42
- onResize = () => {
43
- clearTimeout(resizeTimeout);
44
-
45
- resizeTimeout = setTimeout(() => {
46
- if (window.innerWidth !== lastWidth) {
47
- expandRef.current?.setAttribute('hidden', 'hidden');
48
- expandRef.current?.parentElement?.classList.remove('truncator--no-truncation');
49
- lastWidth = window.innerWidth;
50
- setExpanded(false);
51
- }
52
- }, 200);
53
- };
54
-
55
- window.addEventListener('resize', onResize);
56
-
57
- const focusElements = contentRef.current?.querySelectorAll(focusableSelector);
58
-
59
- onFocus = (event: Event) => {
60
- if (overflowsY(event.target as HTMLElement)) {
61
- setExpanded(true);
62
- }
63
- };
64
-
65
- if (focusElements) {
66
- focusElements.forEach((f) => {
67
- f.removeEventListener('focus', onFocus);
68
- f.addEventListener('focus', onFocus);
69
- });
70
- }
71
-
72
- return () => {
73
- if (focusElements) {
74
- focusElements.forEach((f) => {
75
- f.removeEventListener('focus', onFocus);
76
- });
77
- }
78
- window.removeEventListener('resize', onResize);
79
- };
80
- }, [expanded]);
81
-
82
- return (
83
- <div className={`${classNames}${expanded ? ' truncator--no-truncation' : ''}`} style={getMaxLinesStyle(maxLines)}>
84
- {
85
- header && (
86
- <>
87
- {
88
- headerLevel === 1 && (
89
- <h1 className="truncator__header">{header}</h1>
90
- )
91
- }
92
- {
93
- headerLevel === 2 && (
94
- <h2 className="truncator__header">{header}</h2>
95
- )
96
- }
97
- {
98
- headerLevel === 3 && (
99
- <h3 className="truncator__header">{header}</h3>
100
- )
101
- }
102
- {
103
- headerLevel === 4 && (
104
- <h4 className="truncator__header">{header}</h4>
105
- )
106
- }
107
- {
108
- headerLevel === 5 && (
109
- <h5 className="truncator__header">{header}</h5>
110
- )
111
- }
112
- {
113
- headerLevel === 6 && (
114
- <h6 className="truncator__header">{header}</h6>
115
- )
116
- }
117
- </>
118
- )
119
- }
120
- <button
121
- ref={expandRef}
122
- type="button"
123
- className="truncator__expand"
124
- hidden
125
- aria-expanded={expanded}
126
- onClick={() => setExpanded(true)}
127
- >
128
- {buttonChild}
129
- </button>
130
- <div
131
- ref={contentRef}
132
- className="truncator__content"
133
- >
134
- {children}
135
- </div>
136
- </div>
137
- );
138
- };
139
-
140
- AUTruncatorComponent.displayName = 'AUTruncatorComponent';
141
- export default AUTruncatorComponent;
1
+ import React, {
2
+ FC, useEffect, useRef, useState,
3
+ } from 'react';
4
+ import { overflowsY, focusableSelector } from '@aarhus-university/au-designsystem-delphinus/source/js/components/helpers';
5
+ import { truncate } from '@aarhus-university/au-designsystem-delphinus/source/js/components/truncator';
6
+
7
+ const getMaxLinesStyle = (maxLines: number): React.CSSProperties => ({ '--max-lines': maxLines } as React.CSSProperties);
8
+
9
+ type Props = {
10
+ maxLines: number;
11
+ header?: string;
12
+ headerLevel?: number;
13
+ children: string | JSX.Element | JSX.Element[];
14
+ classNames?: string;
15
+ buttonChild: JSX.Element;
16
+ };
17
+
18
+ let lastWidth = window.innerWidth;
19
+ let resizeTimeout;
20
+ let onResize;
21
+ let onFocus;
22
+
23
+ const AUTruncatorComponent: FC<Props> = ({
24
+ maxLines,
25
+ header = undefined,
26
+ headerLevel = 2,
27
+ children,
28
+ classNames = 'truncator',
29
+ buttonChild,
30
+ }) => {
31
+ const expandRef = useRef<HTMLButtonElement>(null);
32
+ const contentRef = useRef<HTMLDivElement>(null);
33
+ const [expanded, setExpanded] = useState<boolean>(false);
34
+ useEffect(() => {
35
+ window.removeEventListener('resize', onResize);
36
+ if (expanded) {
37
+ (expandRef.current as HTMLElement).removeAttribute('hidden');
38
+ expandRef.current?.parentElement?.classList.add('truncator--no-truncation');
39
+ }
40
+ truncate(expandRef.current as HTMLElement, contentRef.current as HTMLElement);
41
+
42
+ onResize = () => {
43
+ clearTimeout(resizeTimeout);
44
+
45
+ resizeTimeout = setTimeout(() => {
46
+ if (window.innerWidth !== lastWidth) {
47
+ expandRef.current?.setAttribute('hidden', 'hidden');
48
+ expandRef.current?.parentElement?.classList.remove('truncator--no-truncation');
49
+ lastWidth = window.innerWidth;
50
+ setExpanded(false);
51
+ }
52
+ }, 200);
53
+ };
54
+
55
+ window.addEventListener('resize', onResize);
56
+
57
+ const focusElements = contentRef.current?.querySelectorAll(focusableSelector);
58
+
59
+ onFocus = (event: Event) => {
60
+ if (overflowsY(event.target as HTMLElement)) {
61
+ setExpanded(true);
62
+ }
63
+ };
64
+
65
+ if (focusElements) {
66
+ focusElements.forEach((f) => {
67
+ f.removeEventListener('focus', onFocus);
68
+ f.addEventListener('focus', onFocus);
69
+ });
70
+ }
71
+
72
+ return () => {
73
+ if (focusElements) {
74
+ focusElements.forEach((f) => {
75
+ f.removeEventListener('focus', onFocus);
76
+ });
77
+ }
78
+ window.removeEventListener('resize', onResize);
79
+ };
80
+ }, [expanded]);
81
+
82
+ return (
83
+ <div className={`${classNames}${expanded ? ' truncator--no-truncation' : ''}`} style={getMaxLinesStyle(maxLines)}>
84
+ {
85
+ header && (
86
+ <>
87
+ {
88
+ headerLevel === 1 && (
89
+ <h1 className="truncator__header">{header}</h1>
90
+ )
91
+ }
92
+ {
93
+ headerLevel === 2 && (
94
+ <h2 className="truncator__header">{header}</h2>
95
+ )
96
+ }
97
+ {
98
+ headerLevel === 3 && (
99
+ <h3 className="truncator__header">{header}</h3>
100
+ )
101
+ }
102
+ {
103
+ headerLevel === 4 && (
104
+ <h4 className="truncator__header">{header}</h4>
105
+ )
106
+ }
107
+ {
108
+ headerLevel === 5 && (
109
+ <h5 className="truncator__header">{header}</h5>
110
+ )
111
+ }
112
+ {
113
+ headerLevel === 6 && (
114
+ <h6 className="truncator__header">{header}</h6>
115
+ )
116
+ }
117
+ </>
118
+ )
119
+ }
120
+ <button
121
+ ref={expandRef}
122
+ type="button"
123
+ className="truncator__expand"
124
+ hidden
125
+ aria-expanded={expanded}
126
+ onClick={() => setExpanded(true)}
127
+ >
128
+ {buttonChild}
129
+ </button>
130
+ <div
131
+ ref={contentRef}
132
+ className="truncator__content"
133
+ >
134
+ {children}
135
+ </div>
136
+ </div>
137
+ );
138
+ };
139
+
140
+ AUTruncatorComponent.displayName = 'AUTruncatorComponent';
141
+ 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,142 +1,142 @@
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
- links: PropTypes.arrayOf(PropTypes.shape({
122
- title: PropTypes.string.isRequired,
123
- url: PropTypes.string.isRequired,
124
- })).isRequired,
125
- title: PropTypes.string.isRequired,
126
- noResultsAlphabet: PropTypes.string.isRequired,
127
- noResultsSearch: PropTypes.string.isRequired,
128
- noResultsUri: PropTypes.string.isRequired,
129
- }).isRequired,
130
- background: PropTypes.shape({
131
- color: PropTypes.string.isRequired,
132
- linkColor: PropTypes.string.isRequired,
133
- }).isRequired,
134
- search: PropTypes.shape({
135
- placeHolder: PropTypes.string.isRequired,
136
- minLength: PropTypes.number.isRequired,
137
- }).isRequired,
138
- }).isRequired,
139
- };
140
-
141
- AlphaBoxComponent.displayName = 'AlphaBoxComponent';
142
- 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
+ links: PropTypes.arrayOf(PropTypes.shape({
122
+ title: PropTypes.string.isRequired,
123
+ url: PropTypes.string.isRequired,
124
+ })).isRequired,
125
+ title: PropTypes.string.isRequired,
126
+ noResultsAlphabet: PropTypes.string.isRequired,
127
+ noResultsSearch: PropTypes.string.isRequired,
128
+ noResultsUri: PropTypes.string.isRequired,
129
+ }).isRequired,
130
+ background: PropTypes.shape({
131
+ color: PropTypes.string.isRequired,
132
+ linkColor: PropTypes.string.isRequired,
133
+ }).isRequired,
134
+ search: PropTypes.shape({
135
+ placeHolder: PropTypes.string.isRequired,
136
+ minLength: PropTypes.number.isRequired,
137
+ }).isRequired,
138
+ }).isRequired,
139
+ };
140
+
141
+ AlphaBoxComponent.displayName = 'AlphaBoxComponent';
142
+ export default AlphaBoxComponent;