@aarhus-university/au-lib-react-components 9.18.0 → 9.18.2
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/.eslintrc +18 -18
- package/README.md +20 -20
- package/babel.config.js +6 -6
- package/build/dev.html +328 -328
- package/build/umd/all.css +2 -2
- package/build/umd/all.js +1 -1
- package/build/umd/alphabox.js +1 -1
- package/build/umd/auAuth.js +1 -1
- package/build/umd/databox.js +2 -2
- package/build/umd/databox.js.LICENSE.txt +5 -5
- package/build/umd/diagramme.js +1 -1
- package/build/umd/flowbox.js +1 -1
- package/build/umd/news.js +1 -1
- package/build/umd/universe.js +1 -1
- package/package.json +60 -60
- package/src/all.js +3 -3
- package/src/app.js +263 -263
- package/src/components/AUAlertComponent.js +158 -158
- package/src/components/AUAmountComponent.js +84 -84
- package/src/components/AUBannerComponent.js +99 -99
- package/src/components/AUCalendarComponent.js +393 -393
- package/src/components/AUCollapsibleComponent.js +173 -173
- package/src/components/AUDatepickerComponent.js +105 -105
- package/src/components/AUDiagrammeComponent.js +310 -310
- package/src/components/AUFilterCheckboxComponent.js +122 -122
- package/src/components/AUFocusComponent.js +55 -55
- package/src/components/AUModalComponent.js +94 -94
- package/src/components/AUPaginationComponent.js +103 -103
- package/src/components/AUSpinnerComponent.js +125 -125
- package/src/components/AutoSuggestComponent.js +157 -157
- package/src/components/alphabox/AlphaBoxComponent.js +145 -145
- package/src/components/alphabox/AlphaBoxContentComponent.js +136 -136
- package/src/components/context/AUUserContextComponent.js +91 -91
- package/src/components/context/ImpersonateComponent.js +54 -54
- package/src/components/databox/DataBoxAlphabetComponent.js +144 -144
- package/src/components/databox/DataBoxAssociationComponent.js +122 -122
- package/src/components/databox/DataBoxButtonComponent.js +153 -153
- package/src/components/databox/DataBoxComponent.js +297 -297
- package/src/components/databox/DataBoxGroupingComponent.js +62 -62
- package/src/components/databox/DataBoxSearchResultComponent.js +40 -40
- package/src/components/databox/DataBoxStackedAssociationComponent.js +58 -58
- package/src/components/databox/DataBoxSuggestionComponent.js +39 -39
- package/src/components/delphinus/AUAlertComponent.js +85 -85
- package/src/components/delphinus/AUCalendarComponent.js +487 -487
- package/src/components/delphinus/AUContentToggleComponent.js +32 -32
- package/src/components/delphinus/AUDatepickerComponent.js +164 -164
- package/src/components/delphinus/AULoginComponent.js +65 -65
- package/src/components/delphinus/AUModalComponent.js +94 -94
- package/src/components/delphinus/AUSpinnerComponent.js +114 -114
- package/src/components/delphinus/AUSubNavComponent.js +53 -53
- package/src/components/delphinus/AUTabbedContentComponent.js +150 -150
- package/src/components/delphinus/AUTableComponent.js +28 -28
- package/src/components/delphinus/AUToastComponent.js +91 -91
- package/src/components/delphinus/AUToolbarComponent.js +48 -48
- package/src/components/delphinus/hooks.js +28 -28
- package/src/components/flowbox/FlowBoxComponent.js +126 -126
- package/src/components/flowbox/FlowBoxPhoneComponent.js +106 -106
- package/src/components/form/AUMobilePrefixComponent.js +18 -18
- package/src/components/form/AUReceiptComponent.js +40 -40
- package/src/components/form/AUSubmitButtonContainerComponent.js +39 -39
- package/src/components/news/EventLayout1Component.js +94 -94
- package/src/components/news/EventLayout2Component.js +90 -90
- package/src/components/news/EventLayout3Component.js +68 -68
- package/src/components/news/NewsCategoriesComponent.js +21 -21
- package/src/components/news/NewsCollageBannerComponent.js +71 -71
- package/src/components/news/NewsCollageBannerRSSComponent.js +79 -79
- package/src/components/news/NewsColumnsComponent.js +125 -125
- package/src/components/news/NewsLanguageChangeComponent.js +74 -74
- package/src/components/news/NewsLayout1Component.js +80 -80
- package/src/components/news/NewsLayout2Component.js +80 -80
- package/src/components/news/NewsLayout3Component.js +81 -81
- package/src/components/news/NewsLayout4Component.js +80 -80
- package/src/components/news/NewsLayout5Component.js +61 -61
- package/src/components/news/NewsLayout6Component.js +55 -55
- package/src/components/news/NewsLayout7Component.js +58 -58
- package/src/components/news/NewsLayout8Component.js +57 -57
- package/src/components/news/NewsListComponent.js +291 -291
- package/src/components/news/NewsPopUpComponent.js +591 -591
- package/src/components/news/NewsRSSComponent.js +74 -74
- package/src/components/news/NewsSocialComponent.js +104 -104
- package/src/components/news/NewsSubHeaderComponent.js +19 -19
- package/src/components/password/AUChangePasswordComponent.js +189 -189
- package/src/components/password/AUCurrentPasswordComponent.js +72 -72
- package/src/components/password/AUNewPasswordComponent.js +151 -151
- package/src/components/password/AUPasswordActions.js +101 -101
- package/src/components/password/AUPasswordHooks.js +47 -47
- package/src/components/password/AUPasswordReducer.js +78 -78
- package/src/components/password/AUPasswordRequirementsComponent.js +29 -29
- package/src/components/profile/AUProfileActions.js +128 -128
- package/src/components/profile/AUProfileAvatar2016Component.js +99 -99
- package/src/components/profile/AUProfileAvatarComponent.js +83 -83
- package/src/components/profile/AUProfileAvatarV2Component.js +91 -91
- package/src/components/profile/AUProfileAvatarV3Component.js +80 -80
- package/src/components/profile/AUProfileContainerComponent.js +283 -283
- package/src/components/profile/AUProfileHooks.js +30 -30
- package/src/components/profile/AUProfileItemComponent.js +54 -54
- package/src/components/profile/AUProfileLanguageComponent.js +131 -131
- package/src/components/profile/AUProfileLoginComponent.js +41 -41
- package/src/components/profile/AUProfileMailComponent.js +307 -307
- package/src/components/profile/AUProfileMobileComponent.js +164 -164
- package/src/components/profile/AUProfileNameComponent.js +253 -253
- package/src/components/profile/AUProfileNextOfKinComponent.js +216 -216
- package/src/components/profile/AUProfileReducer.js +230 -230
- package/src/components/profile/AUProfileWidgetComponent.js +95 -95
- package/src/components/profile/AUProfileWidgetV2Component.js +116 -116
- package/src/components/profile/AUProfileWidgetV3Component.js +130 -130
- package/src/components/universe/StaffTopComponent.js +366 -366
- package/src/components/universe/StudentTopComponent.js +137 -137
- package/src/components/universe/UniverseContainerComponent.js +62 -62
- package/src/components/wrapping/AUEmbedComponent.js +47 -47
- package/src/config/webpack.dev.config.js +47 -47
- package/src/config/webpack.umd.config.js +86 -86
- package/src/index.js +6 -6
- package/src/lib/au-alphabox.js +102 -102
- package/src/lib/au-auth.js +227 -227
- package/src/lib/au-databox.js +403 -403
- package/src/lib/au-diagramme.js +87 -87
- package/src/lib/au-flowbox.js +95 -95
- package/src/lib/au-news.js +371 -371
- package/src/lib/helpers.js +222 -222
- package/src/lib/i18n.js +605 -605
- package/src/lib/menu.js +10 -10
- package/src/lib/tracking.js +65 -65
- package/src/lib/universe.js +9 -9
- package/src/lib/urlHandler.js +63 -63
- package/src/lib/validation.js +219 -219
- package/src/lib/wrapping.js +16 -16
- package/src/styles/_settings.scss +10 -10
- package/src/styles/alert.scss +39 -39
- package/src/styles/alphabox.scss +222 -222
- package/src/styles/app.scss +13 -13
- package/src/styles/autosuggest.scss +57 -57
- package/src/styles/calendar.scss +111 -111
- package/src/styles/databox.scss +563 -563
- package/src/styles/diagramme.scss +119 -119
- package/src/styles/filtercheckbox.scss +4 -4
- package/src/styles/flowbox.scss +72 -72
- package/src/styles/maps.scss +395 -395
- package/src/styles/modal.scss +34 -34
- package/src/styles/pagination.scss +10 -10
- package/src/styles/spinner.scss +30 -30
|
@@ -1,393 +1,393 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
|
|
4
|
-
const months = ['Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'December'];
|
|
5
|
-
const dayTitles = ['Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør', 'Søn'];
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* AU Kalender Komponent
|
|
9
|
-
*
|
|
10
|
-
* Eksempel:
|
|
11
|
-
* ```jsx
|
|
12
|
-
* <AUCalendarComponent />
|
|
13
|
-
* ```
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
class AUCalendarComponent extends React.Component {
|
|
17
|
-
static daysInMonth(year, month) {
|
|
18
|
-
return new Date(year, month, 0).getDate();
|
|
19
|
-
// Month er 0-index, så det, man returnerer, er reelt sidste dag i foregående måned:
|
|
20
|
-
// Fx er juni = 5, så første dag i måned 5 er 1. juni, mens 0. dag i måned 5 er 31. maj.
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
static calcEaster(year) {
|
|
24
|
-
const a = year % 19;
|
|
25
|
-
const b = Math.floor(year / 100);
|
|
26
|
-
const c = year % 100;
|
|
27
|
-
const d = Math.floor(b / 4);
|
|
28
|
-
const e = b % 4;
|
|
29
|
-
const f = Math.floor((b + 8) / 25);
|
|
30
|
-
const g = Math.floor((b - f + 1) / 3);
|
|
31
|
-
const h = (19 * a + b - d - g + 15) % 30;
|
|
32
|
-
const i = Math.floor(c / 4);
|
|
33
|
-
const k = c % 4;
|
|
34
|
-
const l = (32 + 2 * e + 2 * i - h - k) % 7;
|
|
35
|
-
const m = Math.floor((a + 11 * h + 22 * l) / 451);
|
|
36
|
-
const n0 = (h + l + 7 * m + 114);
|
|
37
|
-
const n = Math.floor(n0 / 31) - 1;
|
|
38
|
-
const p = (n0 % 31) + 1;
|
|
39
|
-
const date = new Date(year, n, p);
|
|
40
|
-
return date;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static addDays(days, date) {
|
|
44
|
-
return new Date(date.getTime() + days * 60 * 24 * 60000);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
static isHoliday(date) {
|
|
48
|
-
const year = date.getFullYear();
|
|
49
|
-
const holidays = [];
|
|
50
|
-
const newYear = new Date(year, 0, 1);
|
|
51
|
-
holidays.push(newYear);
|
|
52
|
-
const easter = AUCalendarComponent.calcEaster(year);
|
|
53
|
-
holidays.push(easter);
|
|
54
|
-
const easterThu = AUCalendarComponent.addDays(-3, easter);
|
|
55
|
-
holidays.push(easterThu);
|
|
56
|
-
const easterFri = AUCalendarComponent.addDays(-2, easter);
|
|
57
|
-
holidays.push(easterFri);
|
|
58
|
-
const easter2 = AUCalendarComponent.addDays(1, easter);
|
|
59
|
-
holidays.push(easter2);
|
|
60
|
-
const stBededag = AUCalendarComponent.addDays(26, easter);
|
|
61
|
-
holidays.push(stBededag);
|
|
62
|
-
const kristiHf = AUCalendarComponent.addDays(39, easter);
|
|
63
|
-
holidays.push(kristiHf);
|
|
64
|
-
const whitsun = AUCalendarComponent.addDays(49, easter);
|
|
65
|
-
holidays.push(whitsun);
|
|
66
|
-
const whitsun2 = AUCalendarComponent.addDays(1, whitsun);
|
|
67
|
-
holidays.push(whitsun2);
|
|
68
|
-
const grundlov = new Date(year, 5, 5);
|
|
69
|
-
holidays.push(grundlov);
|
|
70
|
-
const christmas = new Date(year, 11, 25);
|
|
71
|
-
holidays.push(christmas);
|
|
72
|
-
const christmas2 = AUCalendarComponent.addDays(1, christmas);
|
|
73
|
-
holidays.push(christmas2);
|
|
74
|
-
|
|
75
|
-
return holidays.map((h) => h.toString()).find((x) => x === date.toString());
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
constructor(props) {
|
|
79
|
-
super(props);
|
|
80
|
-
|
|
81
|
-
this.state = {
|
|
82
|
-
day: props.day,
|
|
83
|
-
month: props.month,
|
|
84
|
-
year: props.year,
|
|
85
|
-
hour: props.hour,
|
|
86
|
-
minute: props.minute,
|
|
87
|
-
selected: props.selected,
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
this.skipDays = [6, 0, 1, 2, 3, 4, 5];
|
|
91
|
-
this.goBack = this.goBack.bind(this);
|
|
92
|
-
this.goForward = this.goForward.bind(this);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
goBack() {
|
|
96
|
-
const { month, year } = this.state;
|
|
97
|
-
const newMonth = month - 1 < 1 ? 12 : (month - 1);
|
|
98
|
-
const newYear = newMonth === 12 ? (year - 1) : year;
|
|
99
|
-
this.setState({
|
|
100
|
-
month: newMonth,
|
|
101
|
-
year: newYear,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
goForward() {
|
|
106
|
-
const { month, year } = this.state;
|
|
107
|
-
const newMonth = month + 1 > 12 ? 1 : (month + 1);
|
|
108
|
-
const newYear = newMonth === 1 ? (year + 1) : year;
|
|
109
|
-
this.setState({
|
|
110
|
-
month: newMonth,
|
|
111
|
-
year: newYear,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
render() {
|
|
116
|
-
const {
|
|
117
|
-
day,
|
|
118
|
-
month,
|
|
119
|
-
year,
|
|
120
|
-
hour,
|
|
121
|
-
minute,
|
|
122
|
-
selected,
|
|
123
|
-
} = this.state;
|
|
124
|
-
const {
|
|
125
|
-
onSelected,
|
|
126
|
-
highlightWeekend,
|
|
127
|
-
highlightHolidays,
|
|
128
|
-
yearSpan,
|
|
129
|
-
minuteInterval,
|
|
130
|
-
showTime,
|
|
131
|
-
} = this.props;
|
|
132
|
-
|
|
133
|
-
const renderMonths = months.map(
|
|
134
|
-
(m, i) => (
|
|
135
|
-
<option key={m} value={i + 1}>
|
|
136
|
-
{m}
|
|
137
|
-
</option>
|
|
138
|
-
),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const yearArr = [];
|
|
142
|
-
for (let y = year - yearSpan; y <= year + yearSpan; y += 1) {
|
|
143
|
-
yearArr.push(y);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const renderYears = yearArr.map(
|
|
147
|
-
(y) => (
|
|
148
|
-
<option key={y}>
|
|
149
|
-
{y}
|
|
150
|
-
</option>
|
|
151
|
-
),
|
|
152
|
-
);
|
|
153
|
-
|
|
154
|
-
const renderWeekDays = dayTitles.map(
|
|
155
|
-
(w) => (
|
|
156
|
-
<span key={w}>
|
|
157
|
-
{w}
|
|
158
|
-
</span>
|
|
159
|
-
),
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
const firstDayInMonth = new Date(year, month - 1, 1);
|
|
163
|
-
const emptyDays = this.skipDays[firstDayInMonth.getDay()];
|
|
164
|
-
const prevYear = month === 1 ? year - 1 : year;
|
|
165
|
-
const prevMonth = month === 1 ? 12 : month - 1;
|
|
166
|
-
const numberOfDaysInPrevMonth = AUCalendarComponent.daysInMonth(
|
|
167
|
-
prevYear, prevMonth,
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
let rowCount = -1;
|
|
171
|
-
const renderEmptyDaysBefore = Array(emptyDays).fill().map((e, i) => {
|
|
172
|
-
rowCount = i;
|
|
173
|
-
const beforeDay = numberOfDaysInPrevMonth - emptyDays + i + 1;
|
|
174
|
-
const isWeekend = (highlightWeekend && rowCount > 4)
|
|
175
|
-
|| (highlightHolidays
|
|
176
|
-
&& AUCalendarComponent.isHoliday(new Date(prevYear, prevMonth - 1, beforeDay)));
|
|
177
|
-
return (
|
|
178
|
-
<button
|
|
179
|
-
type="button"
|
|
180
|
-
key={rowCount}
|
|
181
|
-
className={isWeekend ? 'weekend empty' : 'empty'}
|
|
182
|
-
onClick={() => {
|
|
183
|
-
this.goBack();
|
|
184
|
-
}}
|
|
185
|
-
>
|
|
186
|
-
{beforeDay}
|
|
187
|
-
</button>
|
|
188
|
-
);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
const renderDays = Array(AUCalendarComponent.daysInMonth(year, month)).fill().map((d, i) => {
|
|
192
|
-
const key = i; // suck it
|
|
193
|
-
if (rowCount === 6) {
|
|
194
|
-
rowCount = 0;
|
|
195
|
-
} else {
|
|
196
|
-
rowCount += 1;
|
|
197
|
-
}
|
|
198
|
-
const newDay = i + 1;
|
|
199
|
-
const isSelected = (
|
|
200
|
-
newDay === selected.getDate()
|
|
201
|
-
&& year === selected.getFullYear()
|
|
202
|
-
&& month === selected.getMonth() + 1
|
|
203
|
-
);
|
|
204
|
-
const isWeekend = (highlightWeekend && rowCount > 4)
|
|
205
|
-
|| (highlightHolidays && AUCalendarComponent.isHoliday(new Date(year, month - 1, newDay)));
|
|
206
|
-
let className = '';
|
|
207
|
-
if (isSelected) {
|
|
208
|
-
className = 'selected';
|
|
209
|
-
}
|
|
210
|
-
if (isWeekend) {
|
|
211
|
-
className += `${isSelected ? ' ' : ''}weekend`;
|
|
212
|
-
}
|
|
213
|
-
return (
|
|
214
|
-
<button
|
|
215
|
-
key={key}
|
|
216
|
-
type="button"
|
|
217
|
-
className={isWeekend || isSelected ? className : null}
|
|
218
|
-
onClick={() => {
|
|
219
|
-
const newSelected = new Date(year, month - 1, newDay, hour, minute);
|
|
220
|
-
this.setState({
|
|
221
|
-
day: newDay,
|
|
222
|
-
selected: newSelected,
|
|
223
|
-
}, () => {
|
|
224
|
-
onSelected(newSelected);
|
|
225
|
-
});
|
|
226
|
-
}}
|
|
227
|
-
>
|
|
228
|
-
{i + 1}
|
|
229
|
-
</button>
|
|
230
|
-
);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
const nextYear = month === 12 ? (year + 1) : year;
|
|
234
|
-
const nextMonth = month === 12 ? 1 : (month + 1);
|
|
235
|
-
const renderEmptyDaysAfter = Array(6 - rowCount).fill().map((e, i) => {
|
|
236
|
-
const key = i;
|
|
237
|
-
const afterDay = i + 1;
|
|
238
|
-
if (rowCount === 6) {
|
|
239
|
-
rowCount = 0;
|
|
240
|
-
} else {
|
|
241
|
-
rowCount += 1;
|
|
242
|
-
}
|
|
243
|
-
const isWeekend = (highlightWeekend && rowCount > 4)
|
|
244
|
-
|| (highlightHolidays
|
|
245
|
-
&& AUCalendarComponent.isHoliday(new Date(nextYear, nextMonth - 1, afterDay)));
|
|
246
|
-
return (
|
|
247
|
-
<button
|
|
248
|
-
type="button"
|
|
249
|
-
key={key}
|
|
250
|
-
className={isWeekend ? 'weekend empty' : 'empty'}
|
|
251
|
-
onClick={() => {
|
|
252
|
-
this.goForward();
|
|
253
|
-
}}
|
|
254
|
-
>
|
|
255
|
-
{afterDay}
|
|
256
|
-
</button>
|
|
257
|
-
);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
const renderHours = Array(24).fill().map((h, i) => {
|
|
261
|
-
const key = i;
|
|
262
|
-
const optHour = i < 10 ? `0${i}` : i;
|
|
263
|
-
return (
|
|
264
|
-
<option key={key} value={i}>
|
|
265
|
-
{optHour}
|
|
266
|
-
</option>
|
|
267
|
-
);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
const renderMinutes = Array(60).fill().map((h, i) => {
|
|
271
|
-
const key = i;
|
|
272
|
-
if (i % minuteInterval === 0) {
|
|
273
|
-
const optMinute = i < 10 ? `0${i}` : i;
|
|
274
|
-
return (
|
|
275
|
-
<option key={key} value={i}>
|
|
276
|
-
{optMinute}
|
|
277
|
-
</option>
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
return null;
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
return (
|
|
284
|
-
<div className="au-calendar">
|
|
285
|
-
<div className="au-calendar-year-month">
|
|
286
|
-
<select
|
|
287
|
-
value={month}
|
|
288
|
-
onChange={(e) => {
|
|
289
|
-
const newMonth = parseInt(e.target.value, 10);
|
|
290
|
-
const newSelected = new Date(year, newMonth - 1, day, hour, minute);
|
|
291
|
-
this.setState({
|
|
292
|
-
month: newMonth,
|
|
293
|
-
selected: newSelected,
|
|
294
|
-
}, () => {
|
|
295
|
-
onSelected(newSelected);
|
|
296
|
-
});
|
|
297
|
-
}}
|
|
298
|
-
>
|
|
299
|
-
{renderMonths}
|
|
300
|
-
</select>
|
|
301
|
-
<select
|
|
302
|
-
value={year}
|
|
303
|
-
onChange={(e) => {
|
|
304
|
-
const newYear = parseInt(e.target.value, 10);
|
|
305
|
-
const newSelected = new Date(newYear, month - 1, day, hour, minute);
|
|
306
|
-
this.setState({
|
|
307
|
-
year: newYear,
|
|
308
|
-
selected: newSelected,
|
|
309
|
-
}, () => {
|
|
310
|
-
onSelected(newSelected);
|
|
311
|
-
});
|
|
312
|
-
}}
|
|
313
|
-
>
|
|
314
|
-
{renderYears}
|
|
315
|
-
</select>
|
|
316
|
-
</div>
|
|
317
|
-
<div className="au-calendar-days">
|
|
318
|
-
{renderWeekDays}
|
|
319
|
-
{renderEmptyDaysBefore}
|
|
320
|
-
{renderDays}
|
|
321
|
-
{renderEmptyDaysAfter}
|
|
322
|
-
</div>
|
|
323
|
-
{(() => {
|
|
324
|
-
if (showTime) {
|
|
325
|
-
return (
|
|
326
|
-
<div className="au-calendar-time">
|
|
327
|
-
<select
|
|
328
|
-
value={hour}
|
|
329
|
-
onChange={(e) => {
|
|
330
|
-
const newHour = parseInt(e.target.value, 10);
|
|
331
|
-
const newSelected = new Date(year, month - 1, day, newHour, minute);
|
|
332
|
-
this.setState({
|
|
333
|
-
hour: newHour,
|
|
334
|
-
selected: newSelected,
|
|
335
|
-
}, () => {
|
|
336
|
-
onSelected(newSelected);
|
|
337
|
-
});
|
|
338
|
-
}}
|
|
339
|
-
>
|
|
340
|
-
{renderHours}
|
|
341
|
-
</select>
|
|
342
|
-
<select
|
|
343
|
-
value={minute}
|
|
344
|
-
onChange={(e) => {
|
|
345
|
-
const newMinute = parseInt(e.target.value, 10);
|
|
346
|
-
const newSelected = new Date(year, month - 1, day, hour, newMinute);
|
|
347
|
-
this.setState({
|
|
348
|
-
minute: parseInt(e.target.value, 10),
|
|
349
|
-
selected: newSelected,
|
|
350
|
-
}, () => {
|
|
351
|
-
onSelected(newSelected);
|
|
352
|
-
});
|
|
353
|
-
}}
|
|
354
|
-
>
|
|
355
|
-
{renderMinutes}
|
|
356
|
-
</select>
|
|
357
|
-
</div>
|
|
358
|
-
);
|
|
359
|
-
}
|
|
360
|
-
return null;
|
|
361
|
-
})()}
|
|
362
|
-
</div>
|
|
363
|
-
);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
AUCalendarComponent.defaultProps = {
|
|
368
|
-
selected: new Date(),
|
|
369
|
-
onSelected: () => { },
|
|
370
|
-
highlightWeekend: true,
|
|
371
|
-
highlightHolidays: true,
|
|
372
|
-
yearSpan: 5,
|
|
373
|
-
minuteInterval: 5,
|
|
374
|
-
showTime: true,
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
AUCalendarComponent.propTypes = {
|
|
378
|
-
selected: PropTypes.instanceOf(Date),
|
|
379
|
-
day: PropTypes.number.isRequired,
|
|
380
|
-
month: PropTypes.number.isRequired,
|
|
381
|
-
year: PropTypes.number.isRequired,
|
|
382
|
-
hour: PropTypes.number.isRequired,
|
|
383
|
-
minute: PropTypes.number.isRequired,
|
|
384
|
-
highlightWeekend: PropTypes.bool,
|
|
385
|
-
highlightHolidays: PropTypes.bool,
|
|
386
|
-
onSelected: PropTypes.func,
|
|
387
|
-
yearSpan: PropTypes.number,
|
|
388
|
-
minuteInterval: PropTypes.number,
|
|
389
|
-
showTime: PropTypes.bool,
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
AUCalendarComponent.displayName = 'AUCalendarComponent';
|
|
393
|
-
export default AUCalendarComponent;
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
const months = ['Januar', 'Februar', 'Marts', 'April', 'Maj', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'December'];
|
|
5
|
+
const dayTitles = ['Man', 'Tir', 'Ons', 'Tor', 'Fre', 'Lør', 'Søn'];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* AU Kalender Komponent
|
|
9
|
+
*
|
|
10
|
+
* Eksempel:
|
|
11
|
+
* ```jsx
|
|
12
|
+
* <AUCalendarComponent />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
class AUCalendarComponent extends React.Component {
|
|
17
|
+
static daysInMonth(year, month) {
|
|
18
|
+
return new Date(year, month, 0).getDate();
|
|
19
|
+
// Month er 0-index, så det, man returnerer, er reelt sidste dag i foregående måned:
|
|
20
|
+
// Fx er juni = 5, så første dag i måned 5 er 1. juni, mens 0. dag i måned 5 er 31. maj.
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static calcEaster(year) {
|
|
24
|
+
const a = year % 19;
|
|
25
|
+
const b = Math.floor(year / 100);
|
|
26
|
+
const c = year % 100;
|
|
27
|
+
const d = Math.floor(b / 4);
|
|
28
|
+
const e = b % 4;
|
|
29
|
+
const f = Math.floor((b + 8) / 25);
|
|
30
|
+
const g = Math.floor((b - f + 1) / 3);
|
|
31
|
+
const h = (19 * a + b - d - g + 15) % 30;
|
|
32
|
+
const i = Math.floor(c / 4);
|
|
33
|
+
const k = c % 4;
|
|
34
|
+
const l = (32 + 2 * e + 2 * i - h - k) % 7;
|
|
35
|
+
const m = Math.floor((a + 11 * h + 22 * l) / 451);
|
|
36
|
+
const n0 = (h + l + 7 * m + 114);
|
|
37
|
+
const n = Math.floor(n0 / 31) - 1;
|
|
38
|
+
const p = (n0 % 31) + 1;
|
|
39
|
+
const date = new Date(year, n, p);
|
|
40
|
+
return date;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static addDays(days, date) {
|
|
44
|
+
return new Date(date.getTime() + days * 60 * 24 * 60000);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static isHoliday(date) {
|
|
48
|
+
const year = date.getFullYear();
|
|
49
|
+
const holidays = [];
|
|
50
|
+
const newYear = new Date(year, 0, 1);
|
|
51
|
+
holidays.push(newYear);
|
|
52
|
+
const easter = AUCalendarComponent.calcEaster(year);
|
|
53
|
+
holidays.push(easter);
|
|
54
|
+
const easterThu = AUCalendarComponent.addDays(-3, easter);
|
|
55
|
+
holidays.push(easterThu);
|
|
56
|
+
const easterFri = AUCalendarComponent.addDays(-2, easter);
|
|
57
|
+
holidays.push(easterFri);
|
|
58
|
+
const easter2 = AUCalendarComponent.addDays(1, easter);
|
|
59
|
+
holidays.push(easter2);
|
|
60
|
+
const stBededag = AUCalendarComponent.addDays(26, easter);
|
|
61
|
+
holidays.push(stBededag);
|
|
62
|
+
const kristiHf = AUCalendarComponent.addDays(39, easter);
|
|
63
|
+
holidays.push(kristiHf);
|
|
64
|
+
const whitsun = AUCalendarComponent.addDays(49, easter);
|
|
65
|
+
holidays.push(whitsun);
|
|
66
|
+
const whitsun2 = AUCalendarComponent.addDays(1, whitsun);
|
|
67
|
+
holidays.push(whitsun2);
|
|
68
|
+
const grundlov = new Date(year, 5, 5);
|
|
69
|
+
holidays.push(grundlov);
|
|
70
|
+
const christmas = new Date(year, 11, 25);
|
|
71
|
+
holidays.push(christmas);
|
|
72
|
+
const christmas2 = AUCalendarComponent.addDays(1, christmas);
|
|
73
|
+
holidays.push(christmas2);
|
|
74
|
+
|
|
75
|
+
return holidays.map((h) => h.toString()).find((x) => x === date.toString());
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
constructor(props) {
|
|
79
|
+
super(props);
|
|
80
|
+
|
|
81
|
+
this.state = {
|
|
82
|
+
day: props.day,
|
|
83
|
+
month: props.month,
|
|
84
|
+
year: props.year,
|
|
85
|
+
hour: props.hour,
|
|
86
|
+
minute: props.minute,
|
|
87
|
+
selected: props.selected,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
this.skipDays = [6, 0, 1, 2, 3, 4, 5];
|
|
91
|
+
this.goBack = this.goBack.bind(this);
|
|
92
|
+
this.goForward = this.goForward.bind(this);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
goBack() {
|
|
96
|
+
const { month, year } = this.state;
|
|
97
|
+
const newMonth = month - 1 < 1 ? 12 : (month - 1);
|
|
98
|
+
const newYear = newMonth === 12 ? (year - 1) : year;
|
|
99
|
+
this.setState({
|
|
100
|
+
month: newMonth,
|
|
101
|
+
year: newYear,
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
goForward() {
|
|
106
|
+
const { month, year } = this.state;
|
|
107
|
+
const newMonth = month + 1 > 12 ? 1 : (month + 1);
|
|
108
|
+
const newYear = newMonth === 1 ? (year + 1) : year;
|
|
109
|
+
this.setState({
|
|
110
|
+
month: newMonth,
|
|
111
|
+
year: newYear,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
render() {
|
|
116
|
+
const {
|
|
117
|
+
day,
|
|
118
|
+
month,
|
|
119
|
+
year,
|
|
120
|
+
hour,
|
|
121
|
+
minute,
|
|
122
|
+
selected,
|
|
123
|
+
} = this.state;
|
|
124
|
+
const {
|
|
125
|
+
onSelected,
|
|
126
|
+
highlightWeekend,
|
|
127
|
+
highlightHolidays,
|
|
128
|
+
yearSpan,
|
|
129
|
+
minuteInterval,
|
|
130
|
+
showTime,
|
|
131
|
+
} = this.props;
|
|
132
|
+
|
|
133
|
+
const renderMonths = months.map(
|
|
134
|
+
(m, i) => (
|
|
135
|
+
<option key={m} value={i + 1}>
|
|
136
|
+
{m}
|
|
137
|
+
</option>
|
|
138
|
+
),
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
const yearArr = [];
|
|
142
|
+
for (let y = year - yearSpan; y <= year + yearSpan; y += 1) {
|
|
143
|
+
yearArr.push(y);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const renderYears = yearArr.map(
|
|
147
|
+
(y) => (
|
|
148
|
+
<option key={y}>
|
|
149
|
+
{y}
|
|
150
|
+
</option>
|
|
151
|
+
),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
const renderWeekDays = dayTitles.map(
|
|
155
|
+
(w) => (
|
|
156
|
+
<span key={w}>
|
|
157
|
+
{w}
|
|
158
|
+
</span>
|
|
159
|
+
),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const firstDayInMonth = new Date(year, month - 1, 1);
|
|
163
|
+
const emptyDays = this.skipDays[firstDayInMonth.getDay()];
|
|
164
|
+
const prevYear = month === 1 ? year - 1 : year;
|
|
165
|
+
const prevMonth = month === 1 ? 12 : month - 1;
|
|
166
|
+
const numberOfDaysInPrevMonth = AUCalendarComponent.daysInMonth(
|
|
167
|
+
prevYear, prevMonth,
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
let rowCount = -1;
|
|
171
|
+
const renderEmptyDaysBefore = Array(emptyDays).fill().map((e, i) => {
|
|
172
|
+
rowCount = i;
|
|
173
|
+
const beforeDay = numberOfDaysInPrevMonth - emptyDays + i + 1;
|
|
174
|
+
const isWeekend = (highlightWeekend && rowCount > 4)
|
|
175
|
+
|| (highlightHolidays
|
|
176
|
+
&& AUCalendarComponent.isHoliday(new Date(prevYear, prevMonth - 1, beforeDay)));
|
|
177
|
+
return (
|
|
178
|
+
<button
|
|
179
|
+
type="button"
|
|
180
|
+
key={rowCount}
|
|
181
|
+
className={isWeekend ? 'weekend empty' : 'empty'}
|
|
182
|
+
onClick={() => {
|
|
183
|
+
this.goBack();
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
{beforeDay}
|
|
187
|
+
</button>
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const renderDays = Array(AUCalendarComponent.daysInMonth(year, month)).fill().map((d, i) => {
|
|
192
|
+
const key = i; // suck it
|
|
193
|
+
if (rowCount === 6) {
|
|
194
|
+
rowCount = 0;
|
|
195
|
+
} else {
|
|
196
|
+
rowCount += 1;
|
|
197
|
+
}
|
|
198
|
+
const newDay = i + 1;
|
|
199
|
+
const isSelected = (
|
|
200
|
+
newDay === selected.getDate()
|
|
201
|
+
&& year === selected.getFullYear()
|
|
202
|
+
&& month === selected.getMonth() + 1
|
|
203
|
+
);
|
|
204
|
+
const isWeekend = (highlightWeekend && rowCount > 4)
|
|
205
|
+
|| (highlightHolidays && AUCalendarComponent.isHoliday(new Date(year, month - 1, newDay)));
|
|
206
|
+
let className = '';
|
|
207
|
+
if (isSelected) {
|
|
208
|
+
className = 'selected';
|
|
209
|
+
}
|
|
210
|
+
if (isWeekend) {
|
|
211
|
+
className += `${isSelected ? ' ' : ''}weekend`;
|
|
212
|
+
}
|
|
213
|
+
return (
|
|
214
|
+
<button
|
|
215
|
+
key={key}
|
|
216
|
+
type="button"
|
|
217
|
+
className={isWeekend || isSelected ? className : null}
|
|
218
|
+
onClick={() => {
|
|
219
|
+
const newSelected = new Date(year, month - 1, newDay, hour, minute);
|
|
220
|
+
this.setState({
|
|
221
|
+
day: newDay,
|
|
222
|
+
selected: newSelected,
|
|
223
|
+
}, () => {
|
|
224
|
+
onSelected(newSelected);
|
|
225
|
+
});
|
|
226
|
+
}}
|
|
227
|
+
>
|
|
228
|
+
{i + 1}
|
|
229
|
+
</button>
|
|
230
|
+
);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const nextYear = month === 12 ? (year + 1) : year;
|
|
234
|
+
const nextMonth = month === 12 ? 1 : (month + 1);
|
|
235
|
+
const renderEmptyDaysAfter = Array(6 - rowCount).fill().map((e, i) => {
|
|
236
|
+
const key = i;
|
|
237
|
+
const afterDay = i + 1;
|
|
238
|
+
if (rowCount === 6) {
|
|
239
|
+
rowCount = 0;
|
|
240
|
+
} else {
|
|
241
|
+
rowCount += 1;
|
|
242
|
+
}
|
|
243
|
+
const isWeekend = (highlightWeekend && rowCount > 4)
|
|
244
|
+
|| (highlightHolidays
|
|
245
|
+
&& AUCalendarComponent.isHoliday(new Date(nextYear, nextMonth - 1, afterDay)));
|
|
246
|
+
return (
|
|
247
|
+
<button
|
|
248
|
+
type="button"
|
|
249
|
+
key={key}
|
|
250
|
+
className={isWeekend ? 'weekend empty' : 'empty'}
|
|
251
|
+
onClick={() => {
|
|
252
|
+
this.goForward();
|
|
253
|
+
}}
|
|
254
|
+
>
|
|
255
|
+
{afterDay}
|
|
256
|
+
</button>
|
|
257
|
+
);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const renderHours = Array(24).fill().map((h, i) => {
|
|
261
|
+
const key = i;
|
|
262
|
+
const optHour = i < 10 ? `0${i}` : i;
|
|
263
|
+
return (
|
|
264
|
+
<option key={key} value={i}>
|
|
265
|
+
{optHour}
|
|
266
|
+
</option>
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
const renderMinutes = Array(60).fill().map((h, i) => {
|
|
271
|
+
const key = i;
|
|
272
|
+
if (i % minuteInterval === 0) {
|
|
273
|
+
const optMinute = i < 10 ? `0${i}` : i;
|
|
274
|
+
return (
|
|
275
|
+
<option key={key} value={i}>
|
|
276
|
+
{optMinute}
|
|
277
|
+
</option>
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
return null;
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
return (
|
|
284
|
+
<div className="au-calendar">
|
|
285
|
+
<div className="au-calendar-year-month">
|
|
286
|
+
<select
|
|
287
|
+
value={month}
|
|
288
|
+
onChange={(e) => {
|
|
289
|
+
const newMonth = parseInt(e.target.value, 10);
|
|
290
|
+
const newSelected = new Date(year, newMonth - 1, day, hour, minute);
|
|
291
|
+
this.setState({
|
|
292
|
+
month: newMonth,
|
|
293
|
+
selected: newSelected,
|
|
294
|
+
}, () => {
|
|
295
|
+
onSelected(newSelected);
|
|
296
|
+
});
|
|
297
|
+
}}
|
|
298
|
+
>
|
|
299
|
+
{renderMonths}
|
|
300
|
+
</select>
|
|
301
|
+
<select
|
|
302
|
+
value={year}
|
|
303
|
+
onChange={(e) => {
|
|
304
|
+
const newYear = parseInt(e.target.value, 10);
|
|
305
|
+
const newSelected = new Date(newYear, month - 1, day, hour, minute);
|
|
306
|
+
this.setState({
|
|
307
|
+
year: newYear,
|
|
308
|
+
selected: newSelected,
|
|
309
|
+
}, () => {
|
|
310
|
+
onSelected(newSelected);
|
|
311
|
+
});
|
|
312
|
+
}}
|
|
313
|
+
>
|
|
314
|
+
{renderYears}
|
|
315
|
+
</select>
|
|
316
|
+
</div>
|
|
317
|
+
<div className="au-calendar-days">
|
|
318
|
+
{renderWeekDays}
|
|
319
|
+
{renderEmptyDaysBefore}
|
|
320
|
+
{renderDays}
|
|
321
|
+
{renderEmptyDaysAfter}
|
|
322
|
+
</div>
|
|
323
|
+
{(() => {
|
|
324
|
+
if (showTime) {
|
|
325
|
+
return (
|
|
326
|
+
<div className="au-calendar-time">
|
|
327
|
+
<select
|
|
328
|
+
value={hour}
|
|
329
|
+
onChange={(e) => {
|
|
330
|
+
const newHour = parseInt(e.target.value, 10);
|
|
331
|
+
const newSelected = new Date(year, month - 1, day, newHour, minute);
|
|
332
|
+
this.setState({
|
|
333
|
+
hour: newHour,
|
|
334
|
+
selected: newSelected,
|
|
335
|
+
}, () => {
|
|
336
|
+
onSelected(newSelected);
|
|
337
|
+
});
|
|
338
|
+
}}
|
|
339
|
+
>
|
|
340
|
+
{renderHours}
|
|
341
|
+
</select>
|
|
342
|
+
<select
|
|
343
|
+
value={minute}
|
|
344
|
+
onChange={(e) => {
|
|
345
|
+
const newMinute = parseInt(e.target.value, 10);
|
|
346
|
+
const newSelected = new Date(year, month - 1, day, hour, newMinute);
|
|
347
|
+
this.setState({
|
|
348
|
+
minute: parseInt(e.target.value, 10),
|
|
349
|
+
selected: newSelected,
|
|
350
|
+
}, () => {
|
|
351
|
+
onSelected(newSelected);
|
|
352
|
+
});
|
|
353
|
+
}}
|
|
354
|
+
>
|
|
355
|
+
{renderMinutes}
|
|
356
|
+
</select>
|
|
357
|
+
</div>
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
return null;
|
|
361
|
+
})()}
|
|
362
|
+
</div>
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
AUCalendarComponent.defaultProps = {
|
|
368
|
+
selected: new Date(),
|
|
369
|
+
onSelected: () => { },
|
|
370
|
+
highlightWeekend: true,
|
|
371
|
+
highlightHolidays: true,
|
|
372
|
+
yearSpan: 5,
|
|
373
|
+
minuteInterval: 5,
|
|
374
|
+
showTime: true,
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
AUCalendarComponent.propTypes = {
|
|
378
|
+
selected: PropTypes.instanceOf(Date),
|
|
379
|
+
day: PropTypes.number.isRequired,
|
|
380
|
+
month: PropTypes.number.isRequired,
|
|
381
|
+
year: PropTypes.number.isRequired,
|
|
382
|
+
hour: PropTypes.number.isRequired,
|
|
383
|
+
minute: PropTypes.number.isRequired,
|
|
384
|
+
highlightWeekend: PropTypes.bool,
|
|
385
|
+
highlightHolidays: PropTypes.bool,
|
|
386
|
+
onSelected: PropTypes.func,
|
|
387
|
+
yearSpan: PropTypes.number,
|
|
388
|
+
minuteInterval: PropTypes.number,
|
|
389
|
+
showTime: PropTypes.bool,
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
AUCalendarComponent.displayName = 'AUCalendarComponent';
|
|
393
|
+
export default AUCalendarComponent;
|