@aarhus-university/au-lib-react-components 12.5.1 → 12.6.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.
- package/.claude/settings.local.json +12 -0
- package/.eslintrc.js +35 -35
- package/.storybook/main.js +34 -34
- package/.storybook/preview.js +17 -17
- package/.vscode/settings.json +22 -0
- package/README.md +19 -19
- package/__tests__/jest/AUButtonComponent.test.tsx +165 -165
- package/__tests__/jest/AUDynamicContentComponent.test.tsx +386 -0
- 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 +3 -2
- package/build/umd/all.css.map +1 -7
- package/build/umd/all.js +2 -45
- package/build/umd/all.js.map +1 -7
- package/build/umd/alphabox.js +2 -45
- package/build/umd/alphabox.js.map +1 -7
- package/build/umd/databox.js +2 -45
- package/build/umd/databox.js.map +1 -7
- package/build/umd/diagramme.js +2 -44
- package/build/umd/diagramme.js.map +1 -7
- package/build/umd/flowbox.js +2 -44
- package/build/umd/flowbox.js.map +1 -7
- package/build/umd/universe.js +1 -1
- package/build-storybook.log +386 -386
- package/esbuild.mjs +22 -22
- package/package.json +107 -105
- package/src/components/AUAlertComponent.tsx +128 -128
- package/src/components/AUAutoSuggestComponent.js +148 -148
- package/src/components/AUButtonComponent.tsx +99 -97
- package/src/components/AUCalendarComponent.tsx +497 -497
- package/src/components/AUCharacterCountComponent.tsx +56 -56
- package/src/components/AUComboBoxComponent.tsx +195 -195
- package/src/components/AUContentToggleComponent.tsx +50 -50
- package/src/components/AUDatepickerComponent.tsx +124 -124
- package/src/components/AUDialogModalComponent.tsx +124 -124
- package/src/components/AUDynamicContentComponent.tsx +137 -0
- package/src/components/AUEditorComponent.tsx +126 -117
- package/src/components/AUErrorComponent.tsx +73 -73
- package/src/components/AUMobilePrefixComponent.tsx +20 -20
- package/src/components/AUModalComponent.tsx +72 -72
- package/src/components/AUNotificationComponent.tsx +44 -44
- package/src/components/AUReceiptComponent.tsx +34 -34
- package/src/components/AUSpinnerComponent.tsx +40 -40
- package/src/components/AUStepComponent.tsx +75 -75
- package/src/components/AUSubNavComponent.tsx +57 -57
- package/src/components/AUSubmitButtonContainerComponent.tsx +38 -38
- package/src/components/AUTabbedContentComponent.tsx +154 -154
- package/src/components/AUTableComponent.tsx +29 -29
- package/src/components/AUToastComponent.tsx +104 -104
- package/src/components/AUToolbarComponent.tsx +108 -108
- package/src/components/AUTruncatorComponent.tsx +141 -141
- package/src/components/wrapping/AUEmbedComponent.js +47 -47
- package/src/layout-2016/components/alphabox/AlphaBoxComponent.js +142 -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/lib/all.js +3 -3
- package/src/layout-2016/lib/au-alphabox.js +99 -100
- package/src/layout-2016/lib/au-databox.js +399 -400
- package/src/layout-2016/lib/au-diagramme.js +85 -85
- package/src/layout-2016/lib/au-flowbox.js +119 -93
- package/src/lib/context.tsx +59 -59
- package/src/lib/dates.ts +52 -52
- package/src/lib/helpers.ts +208 -208
- package/src/lib/hooks.ts +157 -157
- package/src/lib/i18n.ts +600 -600
- package/src/lib/portals.tsx +150 -150
- package/src/lib/tinymce.ts +84 -84
- 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/AUAlertComponent.stories.tsx +133 -133
- package/stories/AUAutoSuggestComponent.stories.tsx +95 -95
- package/stories/AUButtonComponent.stories.tsx +139 -139
- package/stories/AUCharacterCountComponent.stories.tsx +121 -121
- package/stories/AUComboBoxComponent.stories.tsx +101 -101
- package/stories/AUContentToggleComponent.stories.tsx +87 -87
- package/stories/AUDialogModalComponent.stories.tsx +75 -75
- package/stories/AUDynamicContentComponent.stories.tsx +119 -0
- package/stories/AUEditorComponent.stories.tsx +66 -66
- package/stories/AUErrorComponent.stories.tsx +132 -132
- package/stories/AUModalComponent.stories.tsx +160 -160
- package/stories/AUNotificationComponent.stories.tsx +151 -151
- package/stories/AUSpinnerComponent.stories.tsx +44 -44
- package/stories/AUStepComponent.stories.tsx +91 -91
- package/stories/AUToolbarComponent.stories.tsx +389 -389
- package/stories/AUTruncatorComponent.stories.tsx +123 -123
- package/stories/lib/helpers.tsx +146 -146
- package/tsconfig.json +46 -46
- package/webpack.config.js +88 -88
- package/src/lib/tracking.ts +0 -69
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
import React, { FC, useState } from 'react';
|
|
3
|
-
import dayjs from 'dayjs';
|
|
4
|
-
import AUCalendarComponent from './AUCalendarComponent';
|
|
5
|
-
|
|
6
|
-
type Props = {
|
|
7
|
-
id: string;
|
|
8
|
-
lang?: string;
|
|
9
|
-
date?: Date;
|
|
10
|
-
onDateChange: (date: Date, formatted: string) => void;
|
|
11
|
-
onHide: (date: Date, dateFormatted: string) => void;
|
|
12
|
-
format?: string;
|
|
13
|
-
showTime?: boolean;
|
|
14
|
-
showLabel?: boolean;
|
|
15
|
-
labelInline?: boolean;
|
|
16
|
-
labelText?: string;
|
|
17
|
-
fullWidth?: boolean;
|
|
18
|
-
sideBySideGrowth?: number;
|
|
19
|
-
yearSpanMinus?: number;
|
|
20
|
-
yearSpanPlus?: number;
|
|
21
|
-
limitStart?: Date | null;
|
|
22
|
-
limitEnd?: Date | null;
|
|
23
|
-
disabled?: boolean;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const AUDatepickerComponent: FC<Props> = ({
|
|
27
|
-
id,
|
|
28
|
-
lang = 'da',
|
|
29
|
-
date = new Date(),
|
|
30
|
-
onDateChange,
|
|
31
|
-
onHide,
|
|
32
|
-
format = 'YYYY-MM-DD HH:mm',
|
|
33
|
-
showTime = true,
|
|
34
|
-
showLabel = false,
|
|
35
|
-
labelInline = false,
|
|
36
|
-
labelText = 'Vælg dato:',
|
|
37
|
-
fullWidth = true,
|
|
38
|
-
yearSpanMinus = 5,
|
|
39
|
-
yearSpanPlus = 5,
|
|
40
|
-
limitStart = null,
|
|
41
|
-
limitEnd = null,
|
|
42
|
-
disabled = false,
|
|
43
|
-
sideBySideGrowth = 0,
|
|
44
|
-
}) => {
|
|
45
|
-
const [showCalendar, setShowCalendar] = useState(false);
|
|
46
|
-
const [sDate, setDate] = useState<Date>(date as Date);
|
|
47
|
-
const dateFormatted = dayjs(sDate).format(format);
|
|
48
|
-
|
|
49
|
-
const hideDatePicker = () => {
|
|
50
|
-
setShowCalendar(false);
|
|
51
|
-
onHide(sDate, dateFormatted);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
let className = 'datepicker form__field';
|
|
55
|
-
if (fullWidth) {
|
|
56
|
-
className = `${className} form__field--full-width`;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (labelInline) {
|
|
60
|
-
className = `${className} form__field--inline-label`;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (disabled) {
|
|
64
|
-
className = `${className} visually-disabled`;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (typeof sideBySideGrowth !== 'undefined' && sideBySideGrowth > 0) {
|
|
68
|
-
className = `${className} form__field--width-relative-${sideBySideGrowth}`;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return (
|
|
72
|
-
<div
|
|
73
|
-
className={className}
|
|
74
|
-
aria-owns={`${id}-calendar`}
|
|
75
|
-
aria-haspopup="true"
|
|
76
|
-
aria-expanded={showCalendar}
|
|
77
|
-
>
|
|
78
|
-
{showLabel && <label htmlFor={id}>{labelText}</label>}
|
|
79
|
-
<input
|
|
80
|
-
id={id}
|
|
81
|
-
type="text"
|
|
82
|
-
value={dateFormatted}
|
|
83
|
-
title={
|
|
84
|
-
lang === 'da'
|
|
85
|
-
? 'Klik for at åbne datovælger'
|
|
86
|
-
: 'Click to open datepicker'
|
|
87
|
-
}
|
|
88
|
-
readOnly
|
|
89
|
-
disabled={disabled}
|
|
90
|
-
onClick={() => setShowCalendar(!showCalendar)}
|
|
91
|
-
/>
|
|
92
|
-
{showCalendar && (
|
|
93
|
-
<div className="datepicker__calendar-container">
|
|
94
|
-
<AUCalendarComponent
|
|
95
|
-
key={`${showCalendar}`}
|
|
96
|
-
minuteInterval={1}
|
|
97
|
-
selected={date}
|
|
98
|
-
day={(date as Date).getDate()}
|
|
99
|
-
month={(date as Date).getMonth() + 1}
|
|
100
|
-
year={(date as Date).getFullYear()}
|
|
101
|
-
hour={(date as Date).getHours()}
|
|
102
|
-
minute={(date as Date).getMinutes()}
|
|
103
|
-
onSelected={(selected) => {
|
|
104
|
-
const formatted = dayjs(selected).format(format);
|
|
105
|
-
setDate(selected);
|
|
106
|
-
onDateChange(selected, formatted);
|
|
107
|
-
}}
|
|
108
|
-
showTime={showTime}
|
|
109
|
-
yearSpanMinus={yearSpanMinus}
|
|
110
|
-
yearSpanPlus={yearSpanPlus}
|
|
111
|
-
closeable
|
|
112
|
-
onClose={hideDatePicker}
|
|
113
|
-
controls={id}
|
|
114
|
-
limitStart={limitStart}
|
|
115
|
-
limitEnd={limitEnd}
|
|
116
|
-
/>
|
|
117
|
-
</div>
|
|
118
|
-
)}
|
|
119
|
-
</div>
|
|
120
|
-
);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
AUDatepickerComponent.displayName = 'AUDatepickerComponent';
|
|
124
|
-
export default AUDatepickerComponent;
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
import React, { FC, useState } from 'react';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import AUCalendarComponent from './AUCalendarComponent';
|
|
5
|
+
|
|
6
|
+
type Props = {
|
|
7
|
+
id: string;
|
|
8
|
+
lang?: string;
|
|
9
|
+
date?: Date;
|
|
10
|
+
onDateChange: (date: Date, formatted: string) => void;
|
|
11
|
+
onHide: (date: Date, dateFormatted: string) => void;
|
|
12
|
+
format?: string;
|
|
13
|
+
showTime?: boolean;
|
|
14
|
+
showLabel?: boolean;
|
|
15
|
+
labelInline?: boolean;
|
|
16
|
+
labelText?: string;
|
|
17
|
+
fullWidth?: boolean;
|
|
18
|
+
sideBySideGrowth?: number;
|
|
19
|
+
yearSpanMinus?: number;
|
|
20
|
+
yearSpanPlus?: number;
|
|
21
|
+
limitStart?: Date | null;
|
|
22
|
+
limitEnd?: Date | null;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const AUDatepickerComponent: FC<Props> = ({
|
|
27
|
+
id,
|
|
28
|
+
lang = 'da',
|
|
29
|
+
date = new Date(),
|
|
30
|
+
onDateChange,
|
|
31
|
+
onHide,
|
|
32
|
+
format = 'YYYY-MM-DD HH:mm',
|
|
33
|
+
showTime = true,
|
|
34
|
+
showLabel = false,
|
|
35
|
+
labelInline = false,
|
|
36
|
+
labelText = 'Vælg dato:',
|
|
37
|
+
fullWidth = true,
|
|
38
|
+
yearSpanMinus = 5,
|
|
39
|
+
yearSpanPlus = 5,
|
|
40
|
+
limitStart = null,
|
|
41
|
+
limitEnd = null,
|
|
42
|
+
disabled = false,
|
|
43
|
+
sideBySideGrowth = 0,
|
|
44
|
+
}) => {
|
|
45
|
+
const [showCalendar, setShowCalendar] = useState(false);
|
|
46
|
+
const [sDate, setDate] = useState<Date>(date as Date);
|
|
47
|
+
const dateFormatted = dayjs(sDate).format(format);
|
|
48
|
+
|
|
49
|
+
const hideDatePicker = () => {
|
|
50
|
+
setShowCalendar(false);
|
|
51
|
+
onHide(sDate, dateFormatted);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
let className = 'datepicker form__field';
|
|
55
|
+
if (fullWidth) {
|
|
56
|
+
className = `${className} form__field--full-width`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (labelInline) {
|
|
60
|
+
className = `${className} form__field--inline-label`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (disabled) {
|
|
64
|
+
className = `${className} visually-disabled`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof sideBySideGrowth !== 'undefined' && sideBySideGrowth > 0) {
|
|
68
|
+
className = `${className} form__field--width-relative-${sideBySideGrowth}`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div
|
|
73
|
+
className={className}
|
|
74
|
+
aria-owns={`${id}-calendar`}
|
|
75
|
+
aria-haspopup="true"
|
|
76
|
+
aria-expanded={showCalendar}
|
|
77
|
+
>
|
|
78
|
+
{showLabel && <label htmlFor={id}>{labelText}</label>}
|
|
79
|
+
<input
|
|
80
|
+
id={id}
|
|
81
|
+
type="text"
|
|
82
|
+
value={dateFormatted}
|
|
83
|
+
title={
|
|
84
|
+
lang === 'da'
|
|
85
|
+
? 'Klik for at åbne datovælger'
|
|
86
|
+
: 'Click to open datepicker'
|
|
87
|
+
}
|
|
88
|
+
readOnly
|
|
89
|
+
disabled={disabled}
|
|
90
|
+
onClick={() => setShowCalendar(!showCalendar)}
|
|
91
|
+
/>
|
|
92
|
+
{showCalendar && (
|
|
93
|
+
<div className="datepicker__calendar-container">
|
|
94
|
+
<AUCalendarComponent
|
|
95
|
+
key={`${showCalendar}`}
|
|
96
|
+
minuteInterval={1}
|
|
97
|
+
selected={date}
|
|
98
|
+
day={(date as Date).getDate()}
|
|
99
|
+
month={(date as Date).getMonth() + 1}
|
|
100
|
+
year={(date as Date).getFullYear()}
|
|
101
|
+
hour={(date as Date).getHours()}
|
|
102
|
+
minute={(date as Date).getMinutes()}
|
|
103
|
+
onSelected={(selected) => {
|
|
104
|
+
const formatted = dayjs(selected).format(format);
|
|
105
|
+
setDate(selected);
|
|
106
|
+
onDateChange(selected, formatted);
|
|
107
|
+
}}
|
|
108
|
+
showTime={showTime}
|
|
109
|
+
yearSpanMinus={yearSpanMinus}
|
|
110
|
+
yearSpanPlus={yearSpanPlus}
|
|
111
|
+
closeable
|
|
112
|
+
onClose={hideDatePicker}
|
|
113
|
+
controls={id}
|
|
114
|
+
limitStart={limitStart}
|
|
115
|
+
limitEnd={limitEnd}
|
|
116
|
+
/>
|
|
117
|
+
</div>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
AUDatepickerComponent.displayName = 'AUDatepickerComponent';
|
|
124
|
+
export default AUDatepickerComponent;
|
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
/* eslint-env browser */
|
|
2
|
-
/* eslint jsx-a11y/click-events-have-key-events: 0 */
|
|
3
|
-
/* eslint jsx-a11y/no-noninteractive-element-interactions: 0 */
|
|
4
|
-
/* eslint jsx-a11y/no-static-element-interactions: 0 */
|
|
5
|
-
import React, { FC, useEffect } from 'react';
|
|
6
|
-
import ReactDOM from 'react-dom';
|
|
7
|
-
import AUButtonComponent from './AUButtonComponent';
|
|
8
|
-
import { AUDialogModalContext } from '../lib/context';
|
|
9
|
-
|
|
10
|
-
type Props = {
|
|
11
|
-
lang?: string;
|
|
12
|
-
domId: string;
|
|
13
|
-
className?: string;
|
|
14
|
-
children?: JSX.Element;
|
|
15
|
-
closeButton?: boolean;
|
|
16
|
-
closeButtonDisabled?: boolean;
|
|
17
|
-
show: boolean;
|
|
18
|
-
onClose?: () => void;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const AUDialogModalComponent: FC<Props> = ({
|
|
22
|
-
lang = 'da',
|
|
23
|
-
domId = 'modal-view1',
|
|
24
|
-
className = 'modal-view',
|
|
25
|
-
children,
|
|
26
|
-
closeButton = true,
|
|
27
|
-
closeButtonDisabled,
|
|
28
|
-
show,
|
|
29
|
-
onClose,
|
|
30
|
-
}) => {
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
const dialog = document.getElementById(domId) as HTMLDialogElement;
|
|
33
|
-
if (dialog) {
|
|
34
|
-
if (show) {
|
|
35
|
-
dialog.showModal();
|
|
36
|
-
} else {
|
|
37
|
-
dialog.close();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Handler for click outside dialog
|
|
42
|
-
function handleClickOutside(event: MouseEvent) {
|
|
43
|
-
if (dialog && show && event.target === dialog) {
|
|
44
|
-
if (typeof onClose === 'function') {
|
|
45
|
-
dialog.close();
|
|
46
|
-
onClose();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Handler for ESC key
|
|
52
|
-
function handleKeyDown(event: KeyboardEvent) {
|
|
53
|
-
if (dialog && show && event.key === 'Escape') {
|
|
54
|
-
if (typeof onClose === 'function') {
|
|
55
|
-
dialog.close();
|
|
56
|
-
onClose();
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (dialog && show) {
|
|
62
|
-
dialog.addEventListener('mousedown', handleClickOutside);
|
|
63
|
-
window.addEventListener('keydown', handleKeyDown);
|
|
64
|
-
}
|
|
65
|
-
return () => {
|
|
66
|
-
if (dialog) {
|
|
67
|
-
dialog.removeEventListener('mousedown', handleClickOutside);
|
|
68
|
-
}
|
|
69
|
-
window.removeEventListener('keydown', handleKeyDown);
|
|
70
|
-
};
|
|
71
|
-
}, [show, domId, onClose]);
|
|
72
|
-
|
|
73
|
-
const closeModal = () => {
|
|
74
|
-
const dialog = document.getElementById(domId) as HTMLDialogElement;
|
|
75
|
-
if (dialog) {
|
|
76
|
-
dialog.close();
|
|
77
|
-
onClose?.();
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
ReactDOM.createPortal(
|
|
83
|
-
<AUDialogModalContext.Provider value={closeModal}>
|
|
84
|
-
<dialog
|
|
85
|
-
id={domId}
|
|
86
|
-
className={`${className}${show ? ' modal-view--visible' : ''}`}
|
|
87
|
-
>
|
|
88
|
-
<div className="modal-view__wrapper theme--normal">
|
|
89
|
-
{
|
|
90
|
-
closeButton && (
|
|
91
|
-
<AUButtonComponent
|
|
92
|
-
label={lang === 'da' ? 'Luk' : 'Close'}
|
|
93
|
-
disabled={closeButtonDisabled}
|
|
94
|
-
icon="close"
|
|
95
|
-
hideLabel
|
|
96
|
-
classNames={['modal-view__close']}
|
|
97
|
-
onClick={() => {
|
|
98
|
-
if (typeof onClose === 'function') {
|
|
99
|
-
const dialog = document.getElementById(domId) as HTMLDialogElement;
|
|
100
|
-
if (dialog) {
|
|
101
|
-
dialog.close();
|
|
102
|
-
onClose();
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}}
|
|
106
|
-
/>
|
|
107
|
-
)
|
|
108
|
-
}
|
|
109
|
-
<div className="modal-view__container">
|
|
110
|
-
<div className="modal-view__body">
|
|
111
|
-
{children}
|
|
112
|
-
</div>
|
|
113
|
-
</div>
|
|
114
|
-
</div>
|
|
115
|
-
</dialog>
|
|
116
|
-
</AUDialogModalContext.Provider>,
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
118
|
-
document.querySelector('body')!,
|
|
119
|
-
)
|
|
120
|
-
);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
AUDialogModalComponent.displayName = 'AUDialogModalComponent';
|
|
124
|
-
export default AUDialogModalComponent;
|
|
1
|
+
/* eslint-env browser */
|
|
2
|
+
/* eslint jsx-a11y/click-events-have-key-events: 0 */
|
|
3
|
+
/* eslint jsx-a11y/no-noninteractive-element-interactions: 0 */
|
|
4
|
+
/* eslint jsx-a11y/no-static-element-interactions: 0 */
|
|
5
|
+
import React, { FC, useEffect } from 'react';
|
|
6
|
+
import ReactDOM from 'react-dom';
|
|
7
|
+
import AUButtonComponent from './AUButtonComponent';
|
|
8
|
+
import { AUDialogModalContext } from '../lib/context';
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
lang?: string;
|
|
12
|
+
domId: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
children?: JSX.Element;
|
|
15
|
+
closeButton?: boolean;
|
|
16
|
+
closeButtonDisabled?: boolean;
|
|
17
|
+
show: boolean;
|
|
18
|
+
onClose?: () => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const AUDialogModalComponent: FC<Props> = ({
|
|
22
|
+
lang = 'da',
|
|
23
|
+
domId = 'modal-view1',
|
|
24
|
+
className = 'modal-view',
|
|
25
|
+
children,
|
|
26
|
+
closeButton = true,
|
|
27
|
+
closeButtonDisabled,
|
|
28
|
+
show,
|
|
29
|
+
onClose,
|
|
30
|
+
}) => {
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const dialog = document.getElementById(domId) as HTMLDialogElement;
|
|
33
|
+
if (dialog) {
|
|
34
|
+
if (show) {
|
|
35
|
+
dialog.showModal();
|
|
36
|
+
} else {
|
|
37
|
+
dialog.close();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Handler for click outside dialog
|
|
42
|
+
function handleClickOutside(event: MouseEvent) {
|
|
43
|
+
if (dialog && show && event.target === dialog) {
|
|
44
|
+
if (typeof onClose === 'function') {
|
|
45
|
+
dialog.close();
|
|
46
|
+
onClose();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Handler for ESC key
|
|
52
|
+
function handleKeyDown(event: KeyboardEvent) {
|
|
53
|
+
if (dialog && show && event.key === 'Escape') {
|
|
54
|
+
if (typeof onClose === 'function') {
|
|
55
|
+
dialog.close();
|
|
56
|
+
onClose();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (dialog && show) {
|
|
62
|
+
dialog.addEventListener('mousedown', handleClickOutside);
|
|
63
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
64
|
+
}
|
|
65
|
+
return () => {
|
|
66
|
+
if (dialog) {
|
|
67
|
+
dialog.removeEventListener('mousedown', handleClickOutside);
|
|
68
|
+
}
|
|
69
|
+
window.removeEventListener('keydown', handleKeyDown);
|
|
70
|
+
};
|
|
71
|
+
}, [show, domId, onClose]);
|
|
72
|
+
|
|
73
|
+
const closeModal = () => {
|
|
74
|
+
const dialog = document.getElementById(domId) as HTMLDialogElement;
|
|
75
|
+
if (dialog) {
|
|
76
|
+
dialog.close();
|
|
77
|
+
onClose?.();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
ReactDOM.createPortal(
|
|
83
|
+
<AUDialogModalContext.Provider value={closeModal}>
|
|
84
|
+
<dialog
|
|
85
|
+
id={domId}
|
|
86
|
+
className={`${className}${show ? ' modal-view--visible' : ''}`}
|
|
87
|
+
>
|
|
88
|
+
<div className="modal-view__wrapper theme--normal">
|
|
89
|
+
{
|
|
90
|
+
closeButton && (
|
|
91
|
+
<AUButtonComponent
|
|
92
|
+
label={lang === 'da' ? 'Luk' : 'Close'}
|
|
93
|
+
disabled={closeButtonDisabled}
|
|
94
|
+
icon="close"
|
|
95
|
+
hideLabel
|
|
96
|
+
classNames={['modal-view__close']}
|
|
97
|
+
onClick={() => {
|
|
98
|
+
if (typeof onClose === 'function') {
|
|
99
|
+
const dialog = document.getElementById(domId) as HTMLDialogElement;
|
|
100
|
+
if (dialog) {
|
|
101
|
+
dialog.close();
|
|
102
|
+
onClose();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}}
|
|
106
|
+
/>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
<div className="modal-view__container">
|
|
110
|
+
<div className="modal-view__body">
|
|
111
|
+
{children}
|
|
112
|
+
</div>
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
</dialog>
|
|
116
|
+
</AUDialogModalContext.Provider>,
|
|
117
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
118
|
+
document.querySelector('body')!,
|
|
119
|
+
)
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
AUDialogModalComponent.displayName = 'AUDialogModalComponent';
|
|
124
|
+
export default AUDialogModalComponent;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
|
|
3
|
+
export interface IDynamicContentLink {
|
|
4
|
+
title: string;
|
|
5
|
+
description: string;
|
|
6
|
+
url: string;
|
|
7
|
+
linkType: 'system' | 'information';
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface IDynamicContentVideo {
|
|
11
|
+
type: 'video';
|
|
12
|
+
url: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface IDynamicContentImage {
|
|
16
|
+
type: 'image';
|
|
17
|
+
url: string;
|
|
18
|
+
altText: string;
|
|
19
|
+
caption?: string;
|
|
20
|
+
linkUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface IDynamicContentInfoBox {
|
|
24
|
+
type: 'infoBox';
|
|
25
|
+
htmlContent: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type IDynamicContentFeaturedContent =
|
|
29
|
+
| IDynamicContentVideo
|
|
30
|
+
| IDynamicContentImage
|
|
31
|
+
| IDynamicContentInfoBox;
|
|
32
|
+
|
|
33
|
+
export interface IDynamicContentProps {
|
|
34
|
+
name: string;
|
|
35
|
+
featuredContentDescription: string;
|
|
36
|
+
links: IDynamicContentLink[];
|
|
37
|
+
featuredContent: IDynamicContentFeaturedContent;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const FeaturedVideo: FC<{
|
|
41
|
+
content: IDynamicContentVideo;
|
|
42
|
+
title: string;
|
|
43
|
+
}> = ({ content, title }) => (
|
|
44
|
+
<iframe
|
|
45
|
+
src={content.url}
|
|
46
|
+
title={`Video player: ${title}`}
|
|
47
|
+
loading="lazy"
|
|
48
|
+
allow="clipboard-write; encrypted-media; picture-in-picture; web-share"
|
|
49
|
+
referrerPolicy="strict-origin-when-cross-origin"
|
|
50
|
+
allowFullScreen
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const FeaturedImage: FC<{ content: IDynamicContentImage }> = ({ content }) => {
|
|
55
|
+
const imageElement = (
|
|
56
|
+
<figure>
|
|
57
|
+
<img
|
|
58
|
+
src={content.url}
|
|
59
|
+
alt={content.altText}
|
|
60
|
+
loading="lazy"
|
|
61
|
+
/>
|
|
62
|
+
{content.caption && (
|
|
63
|
+
<figcaption className="text--small">{content.caption}</figcaption>
|
|
64
|
+
)}
|
|
65
|
+
</figure>
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return content.linkUrl ? <a href={content.linkUrl}>{imageElement}</a> : imageElement;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// HTML content is expected to be sanitized by the backend
|
|
72
|
+
const FeaturedInfoBox: FC<{ content: IDynamicContentInfoBox }> = ({ content }) => (
|
|
73
|
+
<div
|
|
74
|
+
className="dynamic-content__infobox"
|
|
75
|
+
dangerouslySetInnerHTML={{ __html: content.htmlContent }}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const AUDynamicContentComponent: FC<IDynamicContentProps> = ({
|
|
80
|
+
name,
|
|
81
|
+
featuredContentDescription,
|
|
82
|
+
links,
|
|
83
|
+
featuredContent,
|
|
84
|
+
}) => {
|
|
85
|
+
// Determine which featured component to render
|
|
86
|
+
let featuredElement: React.ReactNode;
|
|
87
|
+
if (featuredContent) {
|
|
88
|
+
switch (featuredContent.type) {
|
|
89
|
+
case 'video':
|
|
90
|
+
featuredElement = <FeaturedVideo content={featuredContent} title={name} />;
|
|
91
|
+
break;
|
|
92
|
+
case 'image':
|
|
93
|
+
featuredElement = <FeaturedImage content={featuredContent} />;
|
|
94
|
+
break;
|
|
95
|
+
case 'infoBox':
|
|
96
|
+
featuredElement = <FeaturedInfoBox content={featuredContent} />;
|
|
97
|
+
break;
|
|
98
|
+
default:
|
|
99
|
+
featuredElement = null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<section className="dynamic-content" aria-labelledby="dynamic-content-heading">
|
|
105
|
+
{name && <h3 id="dynamic-content-heading">{name}</h3>}
|
|
106
|
+
<div className="dynamic-content__featured">
|
|
107
|
+
{featuredElement}
|
|
108
|
+
{/* HTML content is expected to be sanitized by the backend */}
|
|
109
|
+
{featuredContentDescription && (
|
|
110
|
+
<div dangerouslySetInnerHTML={{ __html: featuredContentDescription }} />
|
|
111
|
+
)}
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<div className="dynamic-content__links">
|
|
115
|
+
{links?.length > 0 && links.map((link, index) => {
|
|
116
|
+
const isDimmed = link.linkType === 'information';
|
|
117
|
+
|
|
118
|
+
// Using index in key is safe here since links array is immutable after initial render
|
|
119
|
+
return (
|
|
120
|
+
<a
|
|
121
|
+
href={link.url}
|
|
122
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
123
|
+
key={link.url + index}
|
|
124
|
+
className={`button button--block${isDimmed ? ' button--dimmed' : ''}`}
|
|
125
|
+
>
|
|
126
|
+
<span className="card__title">{link.title}</span>
|
|
127
|
+
<span className="card__subtitle">{link.description}</span>
|
|
128
|
+
</a>
|
|
129
|
+
);
|
|
130
|
+
})}
|
|
131
|
+
</div>
|
|
132
|
+
</section>
|
|
133
|
+
);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
AUDynamicContentComponent.displayName = 'AUDynamicContentComponent';
|
|
137
|
+
export default AUDynamicContentComponent;
|