@aarhus-university/au-lib-react-components 8.20.2 → 8.80.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.
Files changed (167) hide show
  1. package/.eslintrc.js +44 -0
  2. package/README.md +19 -20
  3. package/babel.config.js +7 -0
  4. package/build/umd/all.css +1 -2
  5. package/build/umd/all.css.map +1 -1
  6. package/build/umd/all.js +1 -1
  7. package/build/umd/all.js.map +1 -1
  8. package/build/umd/alphabox.js +1 -1
  9. package/build/umd/alphabox.js.map +1 -1
  10. package/build/umd/databox.js +1 -6
  11. package/build/umd/databox.js.map +1 -1
  12. package/build/umd/diagramme.js +1 -1
  13. package/build/umd/diagramme.js.map +1 -1
  14. package/build/umd/flowbox.js +1 -1
  15. package/build/umd/flowbox.js.map +1 -1
  16. package/build/umd/universe.js +1 -1
  17. package/build/umd/universe.js.map +1 -1
  18. package/package.json +66 -65
  19. package/src/components/AUAlertComponent.tsx +70 -0
  20. package/src/components/{AutoSuggestComponent.js → AUAutoSuggestComponent.js} +45 -19
  21. package/src/components/AUCalendarComponent.tsx +493 -0
  22. package/src/components/AUContentToggleComponent.tsx +33 -0
  23. package/src/components/AUDatepickerComponent.tsx +117 -0
  24. package/src/components/AUMobilePrefixComponent.tsx +15 -0
  25. package/src/components/{delphinus/AUModalComponent.js → AUModalComponent.tsx} +78 -76
  26. package/src/components/{form/AUReceiptComponent.js → AUReceiptComponent.tsx} +33 -40
  27. package/src/components/AUSpinnerComponent.tsx +64 -0
  28. package/src/components/{delphinus/AUSubNavComponent.js → AUSubNavComponent.tsx} +38 -53
  29. package/src/components/{form/AUSubmitButtonContainerComponent.js → AUSubmitButtonContainerComponent.tsx} +31 -39
  30. package/src/components/AUTabbedContentComponent.tsx +145 -0
  31. package/src/components/{delphinus/AUTableComponent.js → AUTableComponent.tsx} +24 -28
  32. package/src/components/{delphinus/AUToastComponent.js → AUToastComponent.tsx} +104 -91
  33. package/src/components/{delphinus/AUToolbarComponent.js → AUToolbarComponent.tsx} +45 -48
  34. package/src/components/profile/AUProfileActions.js +128 -113
  35. package/src/components/profile/AUProfileAvatarComponent.js +83 -83
  36. package/src/components/profile/AUProfileAvatarV2Component.js +91 -0
  37. package/src/components/profile/AUProfileAvatarV3Component.js +80 -0
  38. package/src/components/profile/AUProfileContainerComponent.js +283 -285
  39. package/src/components/profile/AUProfileHooks.js +30 -30
  40. package/src/components/profile/AUProfileItemComponent.js +54 -54
  41. package/src/components/profile/AUProfileLanguageComponent.js +131 -131
  42. package/src/components/profile/AUProfileLoginComponent.js +0 -2
  43. package/src/components/profile/AUProfileMailComponent.js +307 -299
  44. package/src/components/profile/AUProfileMobileComponent.js +164 -164
  45. package/src/components/profile/AUProfileNameComponent.js +253 -253
  46. package/src/components/profile/AUProfileNextOfKinComponent.js +216 -216
  47. package/src/components/profile/AUProfileReducer.js +230 -210
  48. package/src/components/profile/AUProfileWidgetComponent.js +95 -95
  49. package/src/components/profile/AUProfileWidgetV2Component.js +116 -0
  50. package/src/components/profile/AUProfileWidgetV3Component.js +130 -0
  51. package/src/components/wrapping/AUEmbedComponent.js +47 -47
  52. package/src/{components → layout-2016/components}/alphabox/AlphaBoxComponent.js +29 -28
  53. package/src/{components → layout-2016/components}/alphabox/AlphaBoxContentComponent.js +25 -14
  54. package/src/{components → layout-2016/components/common}/AUCollapsibleComponent.js +1 -22
  55. package/src/{components → layout-2016/components/common}/AUSpinnerComponent.js +2 -24
  56. package/src/{components → layout-2016/components}/databox/DataBoxAlphabetComponent.js +1 -1
  57. package/src/{components → layout-2016/components}/databox/DataBoxAssociationComponent.js +2 -2
  58. package/src/{components → layout-2016/components}/databox/DataBoxButtonComponent.js +7 -3
  59. package/src/{components → layout-2016/components}/databox/DataBoxComponent.js +2 -2
  60. package/src/{components → layout-2016/components}/databox/DataBoxGroupingComponent.js +2 -0
  61. package/src/{components → layout-2016/components}/databox/DataBoxSearchResultComponent.js +1 -5
  62. package/src/{components → layout-2016/components}/databox/DataBoxStackedAssociationComponent.js +1 -5
  63. package/src/{components → layout-2016/components}/databox/DataBoxSuggestionComponent.js +0 -0
  64. package/src/{components → layout-2016/components/diagramme}/AUDiagrammeComponent.js +5 -6
  65. package/src/{components → layout-2016/components}/flowbox/FlowBoxComponent.js +8 -8
  66. package/src/{components → layout-2016/components}/flowbox/FlowBoxPhoneComponent.js +3 -5
  67. package/src/{components → layout-2016/components}/profile/AUProfileAvatar2016Component.js +6 -2
  68. package/src/{components → layout-2016/components}/universe/StaffTopComponent.js +4 -3
  69. package/src/{components → layout-2016/components}/universe/StudentTopComponent.js +0 -0
  70. package/src/{components → layout-2016/components}/universe/UniverseContainerComponent.js +11 -8
  71. package/src/layout-2016/lib/all.js +3 -0
  72. package/src/{lib → layout-2016/lib}/au-alphabox.js +1 -3
  73. package/src/{lib → layout-2016/lib}/au-databox.js +6 -9
  74. package/src/{lib → layout-2016/lib}/au-diagramme.js +2 -4
  75. package/src/{lib → layout-2016/lib}/au-flowbox.js +1 -3
  76. package/src/{lib → layout-2016/lib}/universe.js +0 -0
  77. package/src/lib/{helpers.js → helpers.ts} +40 -66
  78. package/src/{components/delphinus/hooks.js → lib/hooks.ts} +33 -26
  79. package/src/lib/{i18n.js → i18n.ts} +600 -595
  80. package/src/lib/tracking.ts +69 -0
  81. package/src/lib/{wrapping.js → wrapping.ts} +21 -16
  82. package/src/styles/_settings.scss +11 -11
  83. package/src/styles/alphabox.scss +222 -209
  84. package/src/styles/app.scss +7 -12
  85. package/src/styles/autosuggest.scss +57 -57
  86. package/src/styles/databox.scss +563 -563
  87. package/src/styles/diagramme.scss +119 -119
  88. package/src/styles/flowbox.scss +72 -72
  89. package/src/styles/maps.scss +396 -0
  90. package/tsconfig.json +47 -0
  91. package/types/common/interfaces.d.ts +64 -0
  92. package/types/common/main.d.ts +4 -0
  93. package/types/common/package.json +5 -0
  94. package/types/common/payloads.d.ts +0 -0
  95. package/types/common/props.d.ts +138 -0
  96. package/webpack.config.js +89 -0
  97. package/.eslintrc +0 -19
  98. package/DOCUMENTATION.md +0 -369
  99. package/build/cjs/auAuth.js +0 -2
  100. package/build/cjs/auAuth.js.map +0 -1
  101. package/build/dev.html +0 -329
  102. package/build/umd/auAuth.js +0 -2
  103. package/build/umd/auAuth.js.map +0 -1
  104. package/build/umd/news.js +0 -2
  105. package/build/umd/news.js.map +0 -1
  106. package/src/all.js +0 -3
  107. package/src/app.js +0 -263
  108. package/src/components/AUAlertComponent.js +0 -158
  109. package/src/components/AUAmountComponent.js +0 -84
  110. package/src/components/AUBannerComponent.js +0 -99
  111. package/src/components/AUCalendarComponent.js +0 -393
  112. package/src/components/AUDatepickerComponent.js +0 -105
  113. package/src/components/AUFilterCheckboxComponent.js +0 -122
  114. package/src/components/AUFocusComponent.js +0 -55
  115. package/src/components/AUModalComponent.js +0 -94
  116. package/src/components/AUPaginationComponent.js +0 -103
  117. package/src/components/context/AUUserContextComponent.js +0 -91
  118. package/src/components/context/ImpersonateComponent.js +0 -54
  119. package/src/components/delphinus/AUCalendarComponent.js +0 -422
  120. package/src/components/delphinus/AUContentToggleComponent.js +0 -32
  121. package/src/components/delphinus/AUDatepickerComponent.js +0 -113
  122. package/src/components/delphinus/AULoginComponent.js +0 -65
  123. package/src/components/delphinus/AUSpinnerComponent.js +0 -114
  124. package/src/components/delphinus/AUTabbedContentComponent.js +0 -53
  125. package/src/components/form/AUMobilePrefixComponent.js +0 -18
  126. package/src/components/news/EventLayout1Component.js +0 -94
  127. package/src/components/news/EventLayout2Component.js +0 -90
  128. package/src/components/news/EventLayout3Component.js +0 -68
  129. package/src/components/news/NewsCategoriesComponent.js +0 -21
  130. package/src/components/news/NewsCollageBannerComponent.js +0 -71
  131. package/src/components/news/NewsColumnsComponent.js +0 -125
  132. package/src/components/news/NewsLanguageChangeComponent.js +0 -74
  133. package/src/components/news/NewsLayout1Component.js +0 -80
  134. package/src/components/news/NewsLayout2Component.js +0 -80
  135. package/src/components/news/NewsLayout3Component.js +0 -81
  136. package/src/components/news/NewsLayout4Component.js +0 -80
  137. package/src/components/news/NewsLayout5Component.js +0 -61
  138. package/src/components/news/NewsLayout6Component.js +0 -55
  139. package/src/components/news/NewsLayout7Component.js +0 -58
  140. package/src/components/news/NewsLayout8Component.js +0 -57
  141. package/src/components/news/NewsListComponent.js +0 -291
  142. package/src/components/news/NewsPopUpComponent.js +0 -591
  143. package/src/components/news/NewsRSSComponent.js +0 -74
  144. package/src/components/news/NewsSocialComponent.js +0 -104
  145. package/src/components/news/NewsSubHeaderComponent.js +0 -19
  146. package/src/components/password/AUChangePasswordComponent.js +0 -177
  147. package/src/components/password/AUCurrentPasswordComponent.js +0 -72
  148. package/src/components/password/AUNewPasswordComponent.js +0 -143
  149. package/src/components/password/AUPasswordActions.js +0 -101
  150. package/src/components/password/AUPasswordHooks.js +0 -47
  151. package/src/components/password/AUPasswordReducer.js +0 -78
  152. package/src/components/password/AUPasswordRequirementsComponent.js +0 -29
  153. package/src/config/webpack.cjs.config.js +0 -75
  154. package/src/config/webpack.dev.config.js +0 -61
  155. package/src/config/webpack.umd.config.js +0 -107
  156. package/src/index.js +0 -6
  157. package/src/lib/au-auth.js +0 -221
  158. package/src/lib/au-news.js +0 -306
  159. package/src/lib/menu.js +0 -10
  160. package/src/lib/urlHandler.js +0 -63
  161. package/src/lib/validation.js +0 -181
  162. package/src/styles/alert.scss +0 -39
  163. package/src/styles/calendar.scss +0 -112
  164. package/src/styles/filtercheckbox.scss +0 -5
  165. package/src/styles/modal.scss +0 -35
  166. package/src/styles/pagination.scss +0 -11
  167. package/src/styles/spinner.scss +0 -30
@@ -0,0 +1,493 @@
1
+ import React, { useState, FC } from 'react';
2
+ import dayjs from 'dayjs';
3
+ import 'dayjs/locale/da';
4
+ import advancedFormat from 'dayjs/plugin/advancedFormat';
5
+
6
+ const months = {
7
+ da: ['Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'December'],
8
+ en: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
9
+ };
10
+ const dayTitles = {
11
+ da: ['Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør', 'Søn'],
12
+ en: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
13
+ };
14
+
15
+ const daysInMonth = (year: number, month: number): number => new Date(year, month, 0).getDate();
16
+
17
+ // eslint-disable-next-line max-len
18
+ const addDays = (days: number, date: Date): Date => new Date(date.getTime() + days * 60 * 24 * 60000);
19
+
20
+ const calcEaster = (year: number): Date => {
21
+ const a = year % 19;
22
+ const b = Math.floor(year / 100);
23
+ const c = year % 100;
24
+ const d = Math.floor(b / 4);
25
+ const e = b % 4;
26
+ const f = Math.floor((b + 8) / 25);
27
+ const g = Math.floor((b - f + 1) / 3);
28
+ const h = (19 * a + b - d - g + 15) % 30;
29
+ const i = Math.floor(c / 4);
30
+ const k = c % 4;
31
+ const l = (32 + 2 * e + 2 * i - h - k) % 7;
32
+ const m = Math.floor((a + 11 * h + 22 * l) / 451);
33
+ const n0 = (h + l + 7 * m + 114);
34
+ const n = Math.floor(n0 / 31) - 1;
35
+ const p = (n0 % 31) + 1;
36
+ const date = new Date(year, n, p);
37
+ return date;
38
+ };
39
+
40
+ const isHoliday = (date: Date): boolean => {
41
+ const year = date.getFullYear();
42
+ const holidays: Date[] = [];
43
+ const newYear = new Date(year, 0, 1);
44
+ holidays.push(newYear);
45
+ const easter = calcEaster(year);
46
+ holidays.push(easter);
47
+ const easterThu = addDays(-3, easter);
48
+ holidays.push(easterThu);
49
+ const easterFri = addDays(-2, easter);
50
+ holidays.push(easterFri);
51
+ const easter2 = addDays(1, easter);
52
+ holidays.push(easter2);
53
+ const stBededag = addDays(26, easter);
54
+ holidays.push(stBededag);
55
+ const kristiHf = addDays(39, easter);
56
+ holidays.push(kristiHf);
57
+ const whitsun = addDays(49, easter);
58
+ holidays.push(whitsun);
59
+ const whitsun2 = addDays(1, whitsun);
60
+ holidays.push(whitsun2);
61
+ const grundlov = new Date(year, 5, 5);
62
+ holidays.push(grundlov);
63
+ const christmas = new Date(year, 11, 25);
64
+ holidays.push(christmas);
65
+ const christmas2 = addDays(1, christmas);
66
+ holidays.push(christmas2);
67
+
68
+ return holidays.map((h) => h.toString()).filter((x) => x === date.toString()).length > 0;
69
+ };
70
+
71
+ const dateAllowed = (date: Date, limitStart: Date, limitEnd: Date): boolean => {
72
+ if (limitStart && !limitEnd) {
73
+ return date >= limitStart;
74
+ }
75
+
76
+ if (!limitStart && limitEnd) {
77
+ return date <= limitEnd;
78
+ }
79
+
80
+ if (limitStart && limitEnd) {
81
+ return date >= limitStart && date <= limitEnd;
82
+ }
83
+
84
+ return true;
85
+ };
86
+
87
+ const skipDays = [6, 0, 1, 2, 3, 4, 5];
88
+
89
+ const AUCalendarComponent: FC<AUCalendarComponentProps> = ({
90
+ lang,
91
+ day,
92
+ month,
93
+ year,
94
+ hour,
95
+ minute,
96
+ selected,
97
+ onSelected,
98
+ highlightWeekend,
99
+ highlightHolidays,
100
+ yearSpanMinus,
101
+ yearSpanPlus,
102
+ minuteInterval,
103
+ showTime,
104
+ closeable,
105
+ onClose,
106
+ limitStart,
107
+ limitEnd,
108
+ controls,
109
+ }: AUCalendarComponentProps) => {
110
+ dayjs.locale(lang);
111
+ dayjs.extend(advancedFormat);
112
+
113
+ const [calendarState, setCalendarState] = useState<ICalendarState>({
114
+ day,
115
+ month,
116
+ year,
117
+ hour,
118
+ minute,
119
+ selected: selected as Date,
120
+ });
121
+
122
+ const {
123
+ day: sDay,
124
+ month: sMonth,
125
+ year: sYear,
126
+ hour: sHour,
127
+ minute: sMinute,
128
+ selected: sSelected,
129
+ } = calendarState;
130
+
131
+ const goBack = () => {
132
+ const newMonth = sMonth - 1 < 1 ? 12 : (sMonth - 1);
133
+ const newYear = newMonth === 12 ? (sYear - 1) : sYear;
134
+ setCalendarState({
135
+ ...calendarState,
136
+ ...{
137
+ month: newMonth,
138
+ year: newYear,
139
+ },
140
+ });
141
+ };
142
+
143
+ const goForward = () => {
144
+ const newMonth = sMonth + 1 > 12 ? 1 : (sMonth + 1);
145
+ const newYear = newMonth === 1 ? (sYear + 1) : sYear;
146
+ setCalendarState({
147
+ ...calendarState,
148
+ ...{
149
+ month: newMonth,
150
+ year: newYear,
151
+ },
152
+ });
153
+ };
154
+
155
+ const renderMonths = months[lang as string].map(
156
+ (m: string, i: number) => (
157
+ <option key={m} value={i + 1}>
158
+ {m}
159
+ </option>
160
+ ),
161
+ );
162
+
163
+ let yearStart = yearSpanMinus;
164
+ // eslint-disable-next-line max-len
165
+ if (limitStart && limitStart.getFullYear() > (sSelected.getFullYear() - (yearSpanMinus as number))) {
166
+ yearStart = sSelected.getFullYear() - limitStart.getFullYear();
167
+ }
168
+
169
+ let yearEnd = yearSpanPlus;
170
+ if (limitEnd && limitEnd.getFullYear() < (sSelected.getFullYear() + (yearSpanPlus as number))) {
171
+ yearEnd = limitEnd.getFullYear() + sSelected.getFullYear();
172
+ }
173
+
174
+ const yearArr: number[] = [];
175
+ for (let y = sYear - (yearStart as number); y <= sYear + (yearEnd as number); y += 1) {
176
+ yearArr.push(y);
177
+ }
178
+
179
+ const renderYears = yearArr.map(
180
+ (y) => (
181
+ <option key={y}>
182
+ {y}
183
+ </option>
184
+ ),
185
+ );
186
+
187
+ const renderWeekDays = dayTitles[lang as string].map(
188
+ (w: string) => (
189
+ <span key={w} className="calendar__days__day">
190
+ {w}
191
+ </span>
192
+ ),
193
+ );
194
+
195
+ const firstDayInMonth = new Date(sYear, sMonth - 1, 1);
196
+ const emptyDays = skipDays[firstDayInMonth.getDay()];
197
+ const prevYear = sMonth === 1 ? sYear - 1 : sYear;
198
+ const prevMonth = sMonth === 1 ? 12 : sMonth - 1;
199
+ const numberOfDaysInPrevMonth = daysInMonth(
200
+ prevYear, prevMonth,
201
+ );
202
+
203
+ let rowCount = -1;
204
+ const renderEmptyDaysBefore = Array(emptyDays).fill(null).map((_, i) => {
205
+ rowCount = i;
206
+ const beforeDay = numberOfDaysInPrevMonth - emptyDays + i + 1;
207
+ const date = new Date(prevYear, prevMonth - 1, beforeDay);
208
+ const isWeekend = (highlightWeekend && rowCount > 4)
209
+ || (highlightHolidays
210
+ && isHoliday(date));
211
+ return (
212
+ <button
213
+ type="button"
214
+ key={rowCount}
215
+ disabled={(limitStart && date < limitStart) as boolean}
216
+ className={`calendar__days__date ${isWeekend ? 'calendar__days__date--weekend calendar__days__date--empty' : 'calendar__days__date--empty'}`}
217
+ onClick={() => {
218
+ goBack();
219
+ }}
220
+ aria-label={dayjs(date).format('LL')}
221
+ >
222
+ {beforeDay}
223
+ </button>
224
+ );
225
+ });
226
+
227
+ const renderDays = Array(daysInMonth(sYear, sMonth)).fill(null).map((_, i) => {
228
+ const key = i; // suck it
229
+ if (rowCount === 6) {
230
+ rowCount = 0;
231
+ } else {
232
+ rowCount += 1;
233
+ }
234
+ const newDay = i + 1;
235
+ const isSelected = (
236
+ newDay === sSelected.getDate()
237
+ && sYear === sSelected.getFullYear()
238
+ && sMonth === sSelected.getMonth() + 1
239
+ );
240
+ const isWeekend = (highlightWeekend && rowCount > 4)
241
+ || (highlightHolidays && isHoliday(new Date(sYear, sMonth - 1, newDay)));
242
+ let className = 'calendar__days__date';
243
+ if (isSelected) {
244
+ className = `${className} calendar__days__date--selected`;
245
+ }
246
+ if (isWeekend) {
247
+ className = `${className} calendar__days__date--weekend`;
248
+ }
249
+ const date = new Date(sYear, sMonth - 1, newDay, sHour, sMinute);
250
+ return (
251
+ <button
252
+ key={key}
253
+ disabled={((limitStart && date < limitStart) || (limitEnd && date > limitEnd) as boolean)}
254
+ type="button"
255
+ className={className}
256
+ onClick={() => {
257
+ const newSelected = date;
258
+ setCalendarState({
259
+ ...calendarState,
260
+ ...{
261
+ day: newDay,
262
+ selected: newSelected,
263
+ },
264
+ });
265
+ onSelected(newSelected);
266
+ }}
267
+ aria-label={dayjs(date).format('LL')}
268
+ >
269
+ {i + 1}
270
+ </button>
271
+ );
272
+ });
273
+
274
+ const nextYear = sMonth === 12 ? (sYear + 1) : sYear;
275
+ const nextMonth = sMonth === 12 ? 1 : (sMonth + 1);
276
+ const renderEmptyDaysAfter = Array(6 - rowCount).fill(null).map((_, i) => {
277
+ const key = i;
278
+ const afterDay = i + 1;
279
+ if (rowCount === 6) {
280
+ rowCount = 0;
281
+ } else {
282
+ rowCount += 1;
283
+ }
284
+ const date = new Date(nextYear, nextMonth - 1, afterDay);
285
+ const isWeekend = (highlightWeekend && rowCount > 4)
286
+ || (highlightHolidays
287
+ && isHoliday(date));
288
+ return (
289
+ <button
290
+ type="button"
291
+ key={key}
292
+ disabled={(limitEnd && date > limitEnd) as boolean}
293
+ className={`calendar__days__date ${isWeekend ? 'calendar__days__date--weekend calendar__days__date--empty' : 'calendar__days__date--empty'}`}
294
+ onClick={() => {
295
+ goForward();
296
+ }}
297
+ aria-label={dayjs(date).format('LL')}
298
+ >
299
+ {afterDay}
300
+ </button>
301
+ );
302
+ });
303
+
304
+ const renderHours = Array(24).fill(null).map((_, i) => {
305
+ const key = i;
306
+ const optHour = i < 10 ? `0${i}` : i;
307
+ return (
308
+ <option key={key} value={i}>
309
+ {optHour}
310
+ </option>
311
+ );
312
+ });
313
+
314
+ const renderMinutes = Array(60).fill(null).map((_, i) => {
315
+ const key = i;
316
+ if (i % (minuteInterval as number) === 0) {
317
+ const optMinute = i < 10 ? `0${i}` : i;
318
+ return (
319
+ <option key={key} value={i}>
320
+ {optMinute}
321
+ </option>
322
+ );
323
+ }
324
+ return null;
325
+ });
326
+
327
+ return (
328
+ <div id={`${controls}-calendar`} className="calendar" aria-controls={controls}>
329
+ <div className="calendar__year-month">
330
+ <div className="form__field">
331
+ <select
332
+ value={sMonth}
333
+ title={lang === 'da' ? 'Vælg måned' : 'Select month'}
334
+ onChange={(e) => {
335
+ const newMonth = parseInt(e.target.value, 10);
336
+ const newSelected = new Date(sYear, newMonth - 1, sDay, sHour, sMinute);
337
+ if (dateAllowed(newSelected, limitStart as Date, limitEnd as Date)) {
338
+ setCalendarState({
339
+ ...calendarState,
340
+ ...{
341
+ month: newMonth,
342
+ selected: newSelected,
343
+ },
344
+ });
345
+ onSelected(newSelected);
346
+ } else {
347
+ setCalendarState({
348
+ ...calendarState,
349
+ ...{
350
+ month: newMonth,
351
+ },
352
+ });
353
+ }
354
+ }}
355
+ >
356
+ {renderMonths}
357
+ </select>
358
+ </div>
359
+ <div className="form__field">
360
+ <select
361
+ value={sYear}
362
+ title={lang === 'da' ? 'Vælg år' : 'Select year'}
363
+ onChange={(e) => {
364
+ const newYear = parseInt(e.target.value, 10);
365
+ const newSelected = new Date(newYear, sMonth - 1, sDay, sHour, sMinute);
366
+ if (dateAllowed(newSelected, limitStart as Date, limitEnd as Date)) {
367
+ setCalendarState({
368
+ ...calendarState,
369
+ ...{
370
+ year: newYear,
371
+ selected: newSelected,
372
+ },
373
+ });
374
+ onSelected(newSelected);
375
+ } else {
376
+ setCalendarState({
377
+ ...calendarState,
378
+ ...{
379
+ year: newYear,
380
+ },
381
+ });
382
+ }
383
+ }}
384
+ >
385
+ {renderYears}
386
+ </select>
387
+ </div>
388
+ {
389
+ closeable && (
390
+ <button
391
+ className="button button--icon--hide-label button--small button--icon"
392
+ type="button"
393
+ data-icon=""
394
+ onClick={onClose}
395
+ >
396
+ {lang === 'da' ? 'Luk' : 'Close'}
397
+ </button>
398
+ )
399
+ }
400
+ </div>
401
+ <div className="calendar__days">
402
+ {renderWeekDays}
403
+ {renderEmptyDaysBefore}
404
+ {renderDays}
405
+ {renderEmptyDaysAfter}
406
+ </div>
407
+ {
408
+ showTime && (
409
+ <div className="calendar__time">
410
+ <div className="form__field">
411
+ <select
412
+ value={sHour}
413
+ title={lang === 'da' ? 'Vælg time' : 'Select hour'}
414
+ onChange={(e) => {
415
+ const newHour = parseInt(e.target.value, 10);
416
+ const newSelected = new Date(sYear, sMonth - 1, sDay, newHour, sMinute);
417
+ if (dateAllowed(newSelected, limitStart as Date, limitEnd as Date)) {
418
+ setCalendarState({
419
+ ...calendarState,
420
+ ...{
421
+ hour: newHour,
422
+ selected: newSelected,
423
+ },
424
+ });
425
+ onSelected(newSelected);
426
+ } else {
427
+ setCalendarState({
428
+ ...calendarState,
429
+ ...{
430
+ hour: newHour,
431
+ },
432
+ });
433
+ }
434
+ }}
435
+ >
436
+ {renderHours}
437
+ </select>
438
+ </div>
439
+ <div className="form__field">
440
+ <select
441
+ value={sMinute}
442
+ title={lang === 'da' ? 'Vælg minut' : 'Select minute'}
443
+ onChange={(e) => {
444
+ const newMinute = parseInt(e.target.value, 10);
445
+ const newSelected = new Date(sYear, sMonth - 1, sDay, sHour, newMinute);
446
+ if (dateAllowed(newSelected, limitStart as Date, limitEnd as Date)) {
447
+ setCalendarState({
448
+ ...calendarState,
449
+ ...{
450
+ minute: newMinute,
451
+ selected: newSelected,
452
+ },
453
+ });
454
+ onSelected(newSelected);
455
+ } else {
456
+ setCalendarState({
457
+ ...calendarState,
458
+ ...{
459
+ minute: newMinute,
460
+ },
461
+ });
462
+ }
463
+ }}
464
+ >
465
+ {renderMinutes}
466
+ </select>
467
+ </div>
468
+ </div>
469
+ )
470
+ }
471
+ </div>
472
+ );
473
+ };
474
+
475
+ AUCalendarComponent.defaultProps = {
476
+ lang: 'da',
477
+ selected: new Date(),
478
+ // eslint-disable-next-line no-console
479
+ highlightWeekend: true,
480
+ highlightHolidays: true,
481
+ yearSpanMinus: 5,
482
+ yearSpanPlus: 5,
483
+ minuteInterval: 5,
484
+ showTime: true,
485
+ closeable: false,
486
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
487
+ onClose: () => { },
488
+ limitStart: null,
489
+ limitEnd: null,
490
+ };
491
+
492
+ AUCalendarComponent.displayName = 'AUCalendarComponent';
493
+ export default AUCalendarComponent;
@@ -0,0 +1,33 @@
1
+ import React, {
2
+ useEffect,
3
+ useRef,
4
+ FC,
5
+ } from 'react';
6
+ import { setContentToggle } from '@aarhus-university/au-designsystem-delphinus/source/js/components/content-toggle';
7
+
8
+ const AUContentToggleComponent: FC<AUContentToggleComponentProps> = ({
9
+ toggled,
10
+ classNames,
11
+ children,
12
+ }: AUContentToggleComponentProps) => {
13
+ const toggleContainer = useRef<HTMLDivElement>(null);
14
+ useEffect(() => {
15
+ const toggle = toggleContainer?.current?.querySelector('.content-toggle__content');
16
+ if (toggle) {
17
+ const button = setContentToggle(toggle);
18
+ button?.setAttribute('aria-expanded', toggled ? 'true' : 'false');
19
+ }
20
+ }, []);
21
+ return (
22
+ <div ref={toggleContainer} className={classNames}>
23
+ {children}
24
+ </div>
25
+ );
26
+ };
27
+
28
+ AUContentToggleComponent.defaultProps = {
29
+ classNames: undefined,
30
+ };
31
+
32
+ AUContentToggleComponent.displayName = 'AUContentToggleComponent';
33
+ export default AUContentToggleComponent;
@@ -0,0 +1,117 @@
1
+ /* eslint-env browser */
2
+ import React, { FC, useState } from 'react';
3
+ import dayjs from 'dayjs';
4
+ import AUCalendarComponent from './AUCalendarComponent';
5
+
6
+ const AUDatepickerComponent: FC<AUDatepickerComponentProps> = ({
7
+ id,
8
+ lang,
9
+ date,
10
+ onDateChange,
11
+ onHide,
12
+ format,
13
+ showTime,
14
+ showLabel,
15
+ labelInline,
16
+ labelText,
17
+ fullWidth,
18
+ yearSpanMinus,
19
+ yearSpanPlus,
20
+ limitStart,
21
+ limitEnd,
22
+ disabled,
23
+ }: AUDatepickerComponentProps) => {
24
+ const [showCalendar, setShowCalendar] = useState(false);
25
+ const [sDate, setDate] = useState<Date>(date as Date);
26
+ const dateFormatted = dayjs(sDate).format(format);
27
+
28
+ const hideDatePicker = () => {
29
+ setShowCalendar(false);
30
+ onHide(sDate, dateFormatted);
31
+ };
32
+
33
+ let className = 'form__field';
34
+ if (fullWidth) {
35
+ className = `${className} form__field--full-width`;
36
+ }
37
+
38
+ if (labelInline) {
39
+ className = `${className} form__field--inline-label`;
40
+ }
41
+
42
+ if (disabled) {
43
+ className = `${className} visually-disabled`;
44
+ }
45
+
46
+ return (
47
+ <div
48
+ className="datepicker"
49
+ aria-owns={`${id}-calendar`}
50
+ aria-haspopup="true"
51
+ aria-expanded={showCalendar}
52
+ >
53
+ <div className={className}>
54
+ {showLabel && <label htmlFor={id}>{labelText}</label>}
55
+ <input
56
+ id={id}
57
+ type="text"
58
+ value={dateFormatted}
59
+ title={
60
+ lang === 'da'
61
+ ? 'Klik for at åbne datovælger'
62
+ : 'Click to open datepicker'
63
+ }
64
+ readOnly
65
+ disabled={disabled}
66
+ onClick={() => setShowCalendar(!showCalendar)}
67
+ />
68
+ </div>
69
+ {showCalendar && (
70
+ <div className="datepicker__calendar-container">
71
+ <AUCalendarComponent
72
+ key={`${showCalendar}`}
73
+ minuteInterval={1}
74
+ selected={date}
75
+ day={(date as Date).getDate()}
76
+ month={(date as Date).getMonth() + 1}
77
+ year={(date as Date).getFullYear()}
78
+ hour={(date as Date).getHours()}
79
+ minute={(date as Date).getMinutes()}
80
+ onSelected={(selected) => {
81
+ const formatted = dayjs(selected).format(format);
82
+ setDate(selected);
83
+ onDateChange(selected, formatted);
84
+ }}
85
+ showTime={showTime}
86
+ yearSpanMinus={yearSpanMinus}
87
+ yearSpanPlus={yearSpanPlus}
88
+ closeable
89
+ onClose={hideDatePicker}
90
+ controls={id}
91
+ limitStart={limitStart}
92
+ limitEnd={limitEnd}
93
+ />
94
+ </div>
95
+ )}
96
+ </div>
97
+ );
98
+ };
99
+
100
+ AUDatepickerComponent.defaultProps = {
101
+ date: new Date(),
102
+ format: 'YYYY-MM-DD HH:mm',
103
+ showTime: true,
104
+ lang: 'da',
105
+ showLabel: false,
106
+ labelInline: false,
107
+ labelText: 'Vælg dato:',
108
+ fullWidth: true,
109
+ yearSpanMinus: 5,
110
+ yearSpanPlus: 5,
111
+ limitStart: null,
112
+ limitEnd: null,
113
+ disabled: false,
114
+ };
115
+
116
+ AUDatepickerComponent.displayName = 'AUDatepickerComponent';
117
+ export default AUDatepickerComponent;
@@ -0,0 +1,15 @@
1
+ import React, { FC } from 'react';
2
+
3
+ const AUMobilePrefixComponent: FC<AUMobilePrefixComponentProps> = ({
4
+ countryCodes,
5
+ important,
6
+ }: AUMobilePrefixComponentProps) => {
7
+ const renderCountryCodes = (codes: ICountryCode[]) => codes.map(c => <option key={c.da} value={`+${c.code}`}>{`${c.da} (+${c.code})`}</option>);
8
+ if (important) {
9
+ return <>{renderCountryCodes(countryCodes.filter(c => c.important))}</>;
10
+ }
11
+ return <>{renderCountryCodes(countryCodes)}</>;
12
+ };
13
+
14
+ AUMobilePrefixComponent.displayName = 'AUMobilePrefixComponent';
15
+ export default AUMobilePrefixComponent;