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