@kodezen/kz-react-datepicker 1.0.0-beta.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.
- package/README.md +147 -0
- package/dist/index.cjs.css +2 -0
- package/dist/index.cjs.css.map +1 -0
- package/dist/index.cjs.js +1796 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.css +2 -0
- package/dist/index.css.map +1 -0
- package/dist/index.esm.css +2 -0
- package/dist/index.esm.css.map +1 -0
- package/dist/index.esm.js +1794 -0
- package/dist/index.esm.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,1796 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
function _arrayLikeToArray(r, a) {
|
|
6
|
+
(null == a || a > r.length) && (a = r.length);
|
|
7
|
+
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
8
|
+
return n;
|
|
9
|
+
}
|
|
10
|
+
function _arrayWithHoles(r) {
|
|
11
|
+
if (Array.isArray(r)) return r;
|
|
12
|
+
}
|
|
13
|
+
function _defineProperty(e, r, t) {
|
|
14
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
15
|
+
value: t,
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true
|
|
19
|
+
}) : e[r] = t, e;
|
|
20
|
+
}
|
|
21
|
+
function _iterableToArrayLimit(r, l) {
|
|
22
|
+
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
23
|
+
if (null != t) {
|
|
24
|
+
var e,
|
|
25
|
+
n,
|
|
26
|
+
i,
|
|
27
|
+
u,
|
|
28
|
+
a = [],
|
|
29
|
+
f = true,
|
|
30
|
+
o = false;
|
|
31
|
+
try {
|
|
32
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
33
|
+
if (Object(t) !== t) return;
|
|
34
|
+
f = !1;
|
|
35
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
36
|
+
} catch (r) {
|
|
37
|
+
o = true, n = r;
|
|
38
|
+
} finally {
|
|
39
|
+
try {
|
|
40
|
+
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
|
|
41
|
+
} finally {
|
|
42
|
+
if (o) throw n;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return a;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function _nonIterableRest() {
|
|
49
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
50
|
+
}
|
|
51
|
+
function ownKeys(e, r) {
|
|
52
|
+
var t = Object.keys(e);
|
|
53
|
+
if (Object.getOwnPropertySymbols) {
|
|
54
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
55
|
+
r && (o = o.filter(function (r) {
|
|
56
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
57
|
+
})), t.push.apply(t, o);
|
|
58
|
+
}
|
|
59
|
+
return t;
|
|
60
|
+
}
|
|
61
|
+
function _objectSpread2(e) {
|
|
62
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
63
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
64
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
65
|
+
_defineProperty(e, r, t[r]);
|
|
66
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
67
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return e;
|
|
71
|
+
}
|
|
72
|
+
function _slicedToArray(r, e) {
|
|
73
|
+
return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
|
|
74
|
+
}
|
|
75
|
+
function _toPrimitive(t, r) {
|
|
76
|
+
if ("object" != typeof t || !t) return t;
|
|
77
|
+
var e = t[Symbol.toPrimitive];
|
|
78
|
+
if (void 0 !== e) {
|
|
79
|
+
var i = e.call(t, r);
|
|
80
|
+
if ("object" != typeof i) return i;
|
|
81
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
82
|
+
}
|
|
83
|
+
return ("string" === r ? String : Number)(t);
|
|
84
|
+
}
|
|
85
|
+
function _toPropertyKey(t) {
|
|
86
|
+
var i = _toPrimitive(t, "string");
|
|
87
|
+
return "symbol" == typeof i ? i : i + "";
|
|
88
|
+
}
|
|
89
|
+
function _typeof(o) {
|
|
90
|
+
"@babel/helpers - typeof";
|
|
91
|
+
|
|
92
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
93
|
+
return typeof o;
|
|
94
|
+
} : function (o) {
|
|
95
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
96
|
+
}, _typeof(o);
|
|
97
|
+
}
|
|
98
|
+
function _unsupportedIterableToArray(r, a) {
|
|
99
|
+
if (r) {
|
|
100
|
+
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
101
|
+
var t = {}.toString.call(r).slice(8, -1);
|
|
102
|
+
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
var COLORS = ["blue", "orange", "yellow", "red", "purple", "amber", "lime", "green", "emerald", "teal", "cyan", "sky", "indigo", "violet", "fuchsia", "pink", "rose"];
|
|
107
|
+
var DEFAULT_COLOR = "blue";
|
|
108
|
+
var LANGUAGE = "en";
|
|
109
|
+
var DATE_FORMAT = "YYYY-MM-DD";
|
|
110
|
+
var START_WEEK = "sun";
|
|
111
|
+
var DAYS = [0, 1, 2, 3, 4, 5, 6];
|
|
112
|
+
var MONTHS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @typedef {Object} Period
|
|
116
|
+
* @property {string|null} start
|
|
117
|
+
* @property {string|null} end
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @typedef {Object} DateValueType
|
|
122
|
+
* @property {Date|string|null} startDate
|
|
123
|
+
* @property {Date|string|null} endDate
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @typedef {Object} DatepickerStore
|
|
128
|
+
* @property {import("react").RefObject} [input]
|
|
129
|
+
* @property {boolean} [asSingle]
|
|
130
|
+
* @property {string} primaryColor
|
|
131
|
+
* @property {Object} [configs]
|
|
132
|
+
* @property {import("react").RefObject} calendarContainer
|
|
133
|
+
* @property {import("react").RefObject} arrowContainer
|
|
134
|
+
* @property {() => void} hideDatepicker
|
|
135
|
+
* @property {Period} period
|
|
136
|
+
* @property {(period: Period) => void} changePeriod
|
|
137
|
+
* @property {string|null} dayHover
|
|
138
|
+
* @property {(day: string|null) => void} changeDayHover
|
|
139
|
+
* @property {string} inputText
|
|
140
|
+
* @property {(text: string) => void} changeInputText
|
|
141
|
+
* @property {(date: Date) => void} updateFirstDate
|
|
142
|
+
* @property {(value: DateValueType, e?: HTMLInputElement | null) => void} changeDatepickerValue
|
|
143
|
+
* @property {boolean} [showFooter]
|
|
144
|
+
* @property {string|null} [placeholder]
|
|
145
|
+
* @property {string} separator
|
|
146
|
+
* @property {string|null} shortcutText
|
|
147
|
+
* @property {string} i18n
|
|
148
|
+
* @property {DateValueType|null} value
|
|
149
|
+
* @property {boolean} [disabled]
|
|
150
|
+
* @property {((className: string) => string)|string|null} [inputClassName]
|
|
151
|
+
* @property {((className: string) => string)|string|null} [containerClassName]
|
|
152
|
+
* @property {((className: string) => string)|string|null} [toggleClassName]
|
|
153
|
+
* @property {(open: boolean) => import("react").ReactNode} [toggleIcon]
|
|
154
|
+
* @property {boolean} [readOnly]
|
|
155
|
+
* @property {string|null} [startWeekOn]
|
|
156
|
+
* @property {string} displayFormat
|
|
157
|
+
* @property {Date|string|null} [minDate]
|
|
158
|
+
* @property {Date|string|null} [maxDate]
|
|
159
|
+
* @property {"forward"|"backward"|"middle"} [dateLooking]
|
|
160
|
+
* @property {Array<{start: Date|string, end: Date|string}>|null} [disabledDates]
|
|
161
|
+
* @property {string} [inputId]
|
|
162
|
+
* @property {string} [inputName]
|
|
163
|
+
* @property {Object} [classNames]
|
|
164
|
+
* @property {string} [popoverDirection]
|
|
165
|
+
* @property {"auto"|"light"|"dark"} theme
|
|
166
|
+
* @property {"bottom"|"top"|"left"|"right"|"auto"} placement
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @type {import("react").Context<DatepickerStore>}
|
|
171
|
+
*/
|
|
172
|
+
var DatepickerContext = /*#__PURE__*/React.createContext({
|
|
173
|
+
input: undefined,
|
|
174
|
+
primaryColor: "blue",
|
|
175
|
+
configs: undefined,
|
|
176
|
+
calendarContainer: null,
|
|
177
|
+
arrowContainer: null,
|
|
178
|
+
period: {
|
|
179
|
+
start: null,
|
|
180
|
+
end: null
|
|
181
|
+
},
|
|
182
|
+
changePeriod: function changePeriod(period) {},
|
|
183
|
+
hideDatepicker: function hideDatepicker() {},
|
|
184
|
+
dayHover: null,
|
|
185
|
+
changeDayHover: function changeDayHover(day) {},
|
|
186
|
+
inputText: "",
|
|
187
|
+
changeInputText: function changeInputText(text) {},
|
|
188
|
+
updateFirstDate: function updateFirstDate(date) {},
|
|
189
|
+
changeDatepickerValue: function changeDatepickerValue(value, e) {},
|
|
190
|
+
showFooter: false,
|
|
191
|
+
value: null,
|
|
192
|
+
i18n: LANGUAGE,
|
|
193
|
+
disabled: false,
|
|
194
|
+
inputClassName: "",
|
|
195
|
+
containerClassName: "",
|
|
196
|
+
toggleClassName: "",
|
|
197
|
+
readOnly: false,
|
|
198
|
+
displayFormat: DATE_FORMAT,
|
|
199
|
+
minDate: null,
|
|
200
|
+
maxDate: null,
|
|
201
|
+
dateLooking: "forward",
|
|
202
|
+
disabledDates: null,
|
|
203
|
+
inputId: undefined,
|
|
204
|
+
inputName: undefined,
|
|
205
|
+
startWeekOn: START_WEEK,
|
|
206
|
+
toggleIcon: undefined,
|
|
207
|
+
classNames: undefined,
|
|
208
|
+
popoverDirection: undefined,
|
|
209
|
+
separator: "~",
|
|
210
|
+
shortcutText: null,
|
|
211
|
+
suffix: "",
|
|
212
|
+
theme: "auto",
|
|
213
|
+
placement: "bottom"
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
function generateArrayNumber() {
|
|
217
|
+
var start = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
218
|
+
var end = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
219
|
+
var array = [];
|
|
220
|
+
for (var i = start; i <= end; i++) {
|
|
221
|
+
array.push(i);
|
|
222
|
+
}
|
|
223
|
+
return array;
|
|
224
|
+
}
|
|
225
|
+
function shortString(value) {
|
|
226
|
+
var limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
|
|
227
|
+
return value.slice(0, limit);
|
|
228
|
+
}
|
|
229
|
+
function ucFirst(value) {
|
|
230
|
+
return "".concat(value[0].toUpperCase()).concat(value.slice(1));
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Parses a string to Date object or returns the Date if already a Date.
|
|
235
|
+
* Supports basic 'YYYY-MM-DD' parser fallback since removing dayjs.
|
|
236
|
+
* @param {Date|string} date
|
|
237
|
+
* @returns {Date}
|
|
238
|
+
*/
|
|
239
|
+
function parseDate(date) {
|
|
240
|
+
if (date instanceof Date) return new Date(date);
|
|
241
|
+
// Attempt simple parsing for YYYY-MM-DD
|
|
242
|
+
if (typeof date === "string" && /^\d{4}-\d{2}-\d{2}$/.test(date)) {
|
|
243
|
+
var _date$split$map = date.split("-").map(Number),
|
|
244
|
+
_date$split$map2 = _slicedToArray(_date$split$map, 3),
|
|
245
|
+
y = _date$split$map2[0],
|
|
246
|
+
m = _date$split$map2[1],
|
|
247
|
+
d = _date$split$map2[2];
|
|
248
|
+
return new Date(y, m - 1, d);
|
|
249
|
+
}
|
|
250
|
+
return new Date(date);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Format date nicely, replacing dayjs formatting
|
|
255
|
+
* Defaults to YYYY-MM-DD
|
|
256
|
+
* @param {Date|string} date
|
|
257
|
+
* @param {string} format
|
|
258
|
+
* @returns {string}
|
|
259
|
+
*/
|
|
260
|
+
function formatDate(date) {
|
|
261
|
+
var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DATE_FORMAT;
|
|
262
|
+
var d = parseDate(date);
|
|
263
|
+
if (!dateIsValid(d)) return "";
|
|
264
|
+
var map = {
|
|
265
|
+
YYYY: d.getFullYear(),
|
|
266
|
+
MM: String(d.getMonth() + 1).padStart(2, "0"),
|
|
267
|
+
DD: String(d.getDate()).padStart(2, "0"),
|
|
268
|
+
ddd: d.toLocaleDateString("en-US", {
|
|
269
|
+
weekday: "short"
|
|
270
|
+
})
|
|
271
|
+
};
|
|
272
|
+
var result = format;
|
|
273
|
+
for (var _i = 0, _Object$entries = Object.entries(map); _i < _Object$entries.length; _i++) {
|
|
274
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
275
|
+
key = _Object$entries$_i[0],
|
|
276
|
+
value = _Object$entries$_i[1];
|
|
277
|
+
result = result.replace(key, value);
|
|
278
|
+
}
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
function getFirstDayInMonth(date) {
|
|
282
|
+
var d = parseDate(date);
|
|
283
|
+
var firstDay = new Date(d.getFullYear(), d.getMonth(), 1);
|
|
284
|
+
return {
|
|
285
|
+
ddd: formatDate(firstDay, "ddd"),
|
|
286
|
+
basic: formatDate(firstDay),
|
|
287
|
+
object: firstDay
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function getDaysInMonth(date) {
|
|
291
|
+
var d = parseDate(date);
|
|
292
|
+
var days = new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
|
|
293
|
+
return generateArrayNumber(1, days);
|
|
294
|
+
}
|
|
295
|
+
function nextMonth(date) {
|
|
296
|
+
var d = parseDate(date);
|
|
297
|
+
return new Date(d.getFullYear(), d.getMonth() + 1, 1);
|
|
298
|
+
}
|
|
299
|
+
function previousMonth(date) {
|
|
300
|
+
var d = parseDate(date);
|
|
301
|
+
return new Date(d.getFullYear(), d.getMonth() - 1, 1);
|
|
302
|
+
}
|
|
303
|
+
function getFirstElementsInArray() {
|
|
304
|
+
var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
305
|
+
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
306
|
+
return array.slice(0, size);
|
|
307
|
+
}
|
|
308
|
+
function getLastElementsInArray() {
|
|
309
|
+
var array = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
310
|
+
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
311
|
+
var result = [];
|
|
312
|
+
if (Array.isArray(array) && size > 0) {
|
|
313
|
+
if (size >= array.length) {
|
|
314
|
+
return array;
|
|
315
|
+
}
|
|
316
|
+
var y = array.length - 1;
|
|
317
|
+
for (var i = 0; i < size; i++) {
|
|
318
|
+
result.push(array[y]);
|
|
319
|
+
y--;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
return result.reverse();
|
|
323
|
+
}
|
|
324
|
+
function getNumberOfDay(dayString) {
|
|
325
|
+
var startWeekOn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "sun";
|
|
326
|
+
var number = 0;
|
|
327
|
+
var startDateModifier = 0;
|
|
328
|
+
switch (startWeekOn) {
|
|
329
|
+
case "mon":
|
|
330
|
+
startDateModifier = 6;
|
|
331
|
+
break;
|
|
332
|
+
case "tue":
|
|
333
|
+
startDateModifier = 5;
|
|
334
|
+
break;
|
|
335
|
+
case "wed":
|
|
336
|
+
startDateModifier = 4;
|
|
337
|
+
break;
|
|
338
|
+
case "thu":
|
|
339
|
+
startDateModifier = 3;
|
|
340
|
+
break;
|
|
341
|
+
case "fri":
|
|
342
|
+
startDateModifier = 2;
|
|
343
|
+
break;
|
|
344
|
+
case "sat":
|
|
345
|
+
startDateModifier = 1;
|
|
346
|
+
break;
|
|
347
|
+
case "sun":
|
|
348
|
+
default:
|
|
349
|
+
startDateModifier = 0;
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
|
353
|
+
days.forEach(function (item, index) {
|
|
354
|
+
if (item.includes(dayString)) {
|
|
355
|
+
number = (index + startDateModifier) % 7;
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
return number;
|
|
359
|
+
}
|
|
360
|
+
function getLastDaysInMonth(date) {
|
|
361
|
+
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
362
|
+
return getLastElementsInArray(getDaysInMonth(date), size);
|
|
363
|
+
}
|
|
364
|
+
function getFirstDaysInMonth(date) {
|
|
365
|
+
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
366
|
+
return getFirstElementsInArray(getDaysInMonth(date), size);
|
|
367
|
+
}
|
|
368
|
+
function dateIsValid(date) {
|
|
369
|
+
return date instanceof Date && !isNaN(date.getTime());
|
|
370
|
+
}
|
|
371
|
+
function isSameDate(date1, date2) {
|
|
372
|
+
var d1 = parseDate(date1);
|
|
373
|
+
var d2 = parseDate(date2);
|
|
374
|
+
if (!dateIsValid(d1) || !dateIsValid(d2)) return false;
|
|
375
|
+
return d1.getFullYear() === d2.getFullYear() && d1.getMonth() === d2.getMonth() && d1.getDate() === d2.getDate();
|
|
376
|
+
}
|
|
377
|
+
function isBeforeDate(date1, date2) {
|
|
378
|
+
var d1 = parseDate(date1);
|
|
379
|
+
var d2 = parseDate(date2);
|
|
380
|
+
if (!dateIsValid(d1) || !dateIsValid(d2)) return false;
|
|
381
|
+
|
|
382
|
+
// Set time limits for strict date comparison
|
|
383
|
+
var t1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()).getTime();
|
|
384
|
+
var t2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()).getTime();
|
|
385
|
+
return t1 < t2;
|
|
386
|
+
}
|
|
387
|
+
function isAfterDate(date1, date2) {
|
|
388
|
+
var d1 = parseDate(date1);
|
|
389
|
+
var d2 = parseDate(date2);
|
|
390
|
+
if (!dateIsValid(d1) || !dateIsValid(d2)) return false;
|
|
391
|
+
var t1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()).getTime();
|
|
392
|
+
var t2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()).getTime();
|
|
393
|
+
return t1 > t2;
|
|
394
|
+
}
|
|
395
|
+
function isBetweenDates(target, date1, date2) {
|
|
396
|
+
var t = parseDate(target).getTime();
|
|
397
|
+
var d1 = parseDate(date1).getTime();
|
|
398
|
+
var d2 = parseDate(date2).getTime();
|
|
399
|
+
var start = Math.min(d1, d2);
|
|
400
|
+
var end = Math.max(d1, d2);
|
|
401
|
+
return t > start && t < end;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
var ChevronLeftIcon = function ChevronLeftIcon(_ref3) {
|
|
405
|
+
var _ref3$className = _ref3.className,
|
|
406
|
+
className = _ref3$className === void 0 ? "w-6 h-6" : _ref3$className;
|
|
407
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
408
|
+
className: className,
|
|
409
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
410
|
+
fill: "none",
|
|
411
|
+
viewBox: "0 0 24 24",
|
|
412
|
+
strokeWidth: 1.5,
|
|
413
|
+
stroke: "currentColor"
|
|
414
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
415
|
+
strokeLinecap: "round",
|
|
416
|
+
strokeLinejoin: "round",
|
|
417
|
+
d: "M15.75 19.5L8.25 12l7.5-7.5"
|
|
418
|
+
}));
|
|
419
|
+
};
|
|
420
|
+
var DoubleChevronLeftIcon = function DoubleChevronLeftIcon(_ref4) {
|
|
421
|
+
var _ref4$className = _ref4.className,
|
|
422
|
+
className = _ref4$className === void 0 ? "w-6 h-6" : _ref4$className;
|
|
423
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
424
|
+
className: className,
|
|
425
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
426
|
+
fill: "none",
|
|
427
|
+
viewBox: "0 0 24 24",
|
|
428
|
+
strokeWidth: 1.5,
|
|
429
|
+
stroke: "currentColor"
|
|
430
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
431
|
+
strokeLinecap: "round",
|
|
432
|
+
strokeLinejoin: "round",
|
|
433
|
+
d: "M18.75 19.5l-7.5-7.5 7.5-7.5m-6 15L5.25 12l7.5-7.5"
|
|
434
|
+
}));
|
|
435
|
+
};
|
|
436
|
+
var ChevronRightIcon = function ChevronRightIcon(_ref5) {
|
|
437
|
+
var _ref5$className = _ref5.className,
|
|
438
|
+
className = _ref5$className === void 0 ? "w-6 h-6" : _ref5$className;
|
|
439
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
440
|
+
className: className,
|
|
441
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
442
|
+
fill: "none",
|
|
443
|
+
viewBox: "0 0 24 24",
|
|
444
|
+
strokeWidth: 1.5,
|
|
445
|
+
stroke: "currentColor"
|
|
446
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
447
|
+
strokeLinecap: "round",
|
|
448
|
+
strokeLinejoin: "round",
|
|
449
|
+
d: "M8.25 4.5l7.5 7.5-7.5 7.5"
|
|
450
|
+
}));
|
|
451
|
+
};
|
|
452
|
+
var DoubleChevronRightIcon = function DoubleChevronRightIcon(_ref6) {
|
|
453
|
+
var _ref6$className = _ref6.className,
|
|
454
|
+
className = _ref6$className === void 0 ? "w-6 h-6" : _ref6$className;
|
|
455
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
456
|
+
className: className,
|
|
457
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
458
|
+
fill: "none",
|
|
459
|
+
viewBox: "0 0 24 24",
|
|
460
|
+
strokeWidth: 1.5,
|
|
461
|
+
stroke: "currentColor"
|
|
462
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
463
|
+
strokeLinecap: "round",
|
|
464
|
+
strokeLinejoin: "round",
|
|
465
|
+
d: "M11.25 4.5l7.5 7.5-7.5 7.5m-6-15l7.5 7.5-7.5 7.5"
|
|
466
|
+
}));
|
|
467
|
+
};
|
|
468
|
+
var Arrow = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
469
|
+
var _useContext = React.useContext(DatepickerContext),
|
|
470
|
+
suffix = _useContext.suffix;
|
|
471
|
+
var baseClass = "kz-arrow-indicator";
|
|
472
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
473
|
+
ref: ref,
|
|
474
|
+
className: baseClass + (suffix ? " ".concat(baseClass, "--").concat(suffix) : "")
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
var SecondaryButton = function SecondaryButton(_ref7) {
|
|
478
|
+
var children = _ref7.children,
|
|
479
|
+
onClick = _ref7.onClick,
|
|
480
|
+
_ref7$disabled = _ref7.disabled,
|
|
481
|
+
disabled = _ref7$disabled === void 0 ? false : _ref7$disabled;
|
|
482
|
+
var _useContext2 = React.useContext(DatepickerContext),
|
|
483
|
+
suffix = _useContext2.suffix;
|
|
484
|
+
var baseClass = "kz-secondary-btn";
|
|
485
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
486
|
+
type: "button",
|
|
487
|
+
className: baseClass + (suffix ? " ".concat(baseClass, "--").concat(suffix) : ""),
|
|
488
|
+
onClick: onClick,
|
|
489
|
+
disabled: disabled
|
|
490
|
+
}, children);
|
|
491
|
+
};
|
|
492
|
+
var PrimaryButton = function PrimaryButton(_ref8) {
|
|
493
|
+
var children = _ref8.children,
|
|
494
|
+
onClick = _ref8.onClick,
|
|
495
|
+
_ref8$disabled = _ref8.disabled,
|
|
496
|
+
disabled = _ref8$disabled === void 0 ? false : _ref8$disabled;
|
|
497
|
+
var _useContext3 = React.useContext(DatepickerContext),
|
|
498
|
+
suffix = _useContext3.suffix;
|
|
499
|
+
var baseClass = "kz-primary-btn";
|
|
500
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
501
|
+
type: "button",
|
|
502
|
+
className: baseClass + (suffix ? " ".concat(baseClass, "--").concat(suffix) : ""),
|
|
503
|
+
onClick: onClick,
|
|
504
|
+
disabled: disabled
|
|
505
|
+
}, children);
|
|
506
|
+
};
|
|
507
|
+
var RoundedButton = function RoundedButton(_ref9) {
|
|
508
|
+
var children = _ref9.children,
|
|
509
|
+
onClick = _ref9.onClick,
|
|
510
|
+
disabled = _ref9.disabled,
|
|
511
|
+
_ref9$roundedFull = _ref9.roundedFull,
|
|
512
|
+
roundedFull = _ref9$roundedFull === void 0 ? false : _ref9$roundedFull,
|
|
513
|
+
_ref9$active = _ref9.active,
|
|
514
|
+
active = _ref9$active === void 0 ? false : _ref9$active;
|
|
515
|
+
var _useContext4 = React.useContext(DatepickerContext),
|
|
516
|
+
suffix = _useContext4.suffix;
|
|
517
|
+
var baseClass = "kz-rounded-btn";
|
|
518
|
+
var cn = [baseClass];
|
|
519
|
+
if (suffix) cn.push("".concat(baseClass, "--").concat(suffix));
|
|
520
|
+
if (roundedFull) {
|
|
521
|
+
cn.push("is-rounded-full");
|
|
522
|
+
if (suffix) cn.push("is-rounded-full--".concat(suffix));
|
|
523
|
+
}
|
|
524
|
+
if (active) {
|
|
525
|
+
cn.push("is-active");
|
|
526
|
+
if (suffix) cn.push("is-active--".concat(suffix));
|
|
527
|
+
}
|
|
528
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
529
|
+
type: "button",
|
|
530
|
+
className: cn.join(" "),
|
|
531
|
+
onClick: onClick,
|
|
532
|
+
disabled: disabled
|
|
533
|
+
}, children);
|
|
534
|
+
};
|
|
535
|
+
var VerticalDash = function VerticalDash() {
|
|
536
|
+
var _useContext5 = React.useContext(DatepickerContext),
|
|
537
|
+
suffix = _useContext5.suffix;
|
|
538
|
+
var baseClass = "kz-vertical-dash";
|
|
539
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
540
|
+
className: baseClass + (suffix ? " ".concat(baseClass, "--").concat(suffix) : "")
|
|
541
|
+
});
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
var Days = function Days(_ref) {
|
|
545
|
+
var calendarData = _ref.calendarData,
|
|
546
|
+
onClickPreviousDays = _ref.onClickPreviousDays,
|
|
547
|
+
onClickDay = _ref.onClickDay,
|
|
548
|
+
onClickNextDays = _ref.onClickNextDays;
|
|
549
|
+
var _useContext = React.useContext(DatepickerContext),
|
|
550
|
+
period = _useContext.period,
|
|
551
|
+
dayHover = _useContext.dayHover,
|
|
552
|
+
changeDayHover = _useContext.changeDayHover,
|
|
553
|
+
minDate = _useContext.minDate,
|
|
554
|
+
maxDate = _useContext.maxDate,
|
|
555
|
+
disabledDates = _useContext.disabledDates,
|
|
556
|
+
suffix = _useContext.suffix;
|
|
557
|
+
var isDateDisabledInner = function isDateDisabledInner(day, type) {
|
|
558
|
+
var date = calendarData.date;
|
|
559
|
+
var m = date.getMonth();
|
|
560
|
+
var y = date.getFullYear();
|
|
561
|
+
if (type === "previous") m -= 1;
|
|
562
|
+
if (type === "next") m += 1;
|
|
563
|
+
var currentDayDate = new Date(y, m, day);
|
|
564
|
+
if (minDate && isBeforeDate(currentDayDate, minDate)) return true;
|
|
565
|
+
if (maxDate && isAfterDate(currentDayDate, maxDate)) return true;
|
|
566
|
+
if (disabledDates !== null && disabledDates !== void 0 && disabledDates.length) {
|
|
567
|
+
for (var i = 0; i < disabledDates.length; i++) {
|
|
568
|
+
if (isBetweenDates(currentDayDate, disabledDates[i].startDate, disabledDates[i].endDate) || currentDayDate.getTime() === new Date(disabledDates[i].startDate).getTime() || currentDayDate.getTime() === new Date(disabledDates[i].endDate).getTime()) {
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
return false;
|
|
574
|
+
};
|
|
575
|
+
var isDateDisabled = function isDateDisabled(day, type) {
|
|
576
|
+
return isDateDisabledInner(day, type);
|
|
577
|
+
};
|
|
578
|
+
var getButtonClass = function getButtonClass(day, type) {
|
|
579
|
+
var date = calendarData.date;
|
|
580
|
+
var m = date.getMonth();
|
|
581
|
+
var y = date.getFullYear();
|
|
582
|
+
if (type === "previous") m -= 1;
|
|
583
|
+
if (type === "next") m += 1;
|
|
584
|
+
var currentDayDate = new Date(y, m, day);
|
|
585
|
+
var today = new Date();
|
|
586
|
+
var isToday = today.getDate() === day && today.getMonth() === m && today.getFullYear() === y;
|
|
587
|
+
var start = period.start ? parseDate(period.start) : null;
|
|
588
|
+
var end = period.end ? parseDate(period.end) : null;
|
|
589
|
+
var hover = dayHover ? parseDate(dayHover) : null;
|
|
590
|
+
var baseClass = "kz-calendar-day";
|
|
591
|
+
if (suffix) baseClass += " kz-calendar-day--".concat(suffix);
|
|
592
|
+
if (type !== "current" || isDateDisabled(day, type)) {
|
|
593
|
+
baseClass += " kz-calendar-day-disabled";
|
|
594
|
+
if (suffix) baseClass += " kz-calendar-day-disabled--".concat(suffix);
|
|
595
|
+
return baseClass;
|
|
596
|
+
}
|
|
597
|
+
if (isToday) {
|
|
598
|
+
baseClass += " kz-calendar-day-today";
|
|
599
|
+
if (suffix) baseClass += " kz-calendar-day-today--".concat(suffix);
|
|
600
|
+
}
|
|
601
|
+
var isStart = start && isSameDate(start, currentDayDate);
|
|
602
|
+
var isEnd = end && isSameDate(end, currentDayDate);
|
|
603
|
+
|
|
604
|
+
// Initial click: make it rounded
|
|
605
|
+
if (start && !end && isStart) {
|
|
606
|
+
baseClass += " kz-calendar-day-active kz-calendar-day-rounded";
|
|
607
|
+
if (suffix) {
|
|
608
|
+
baseClass += " kz-calendar-day-active--".concat(suffix, " kz-calendar-day-rounded--").concat(suffix);
|
|
609
|
+
}
|
|
610
|
+
return baseClass;
|
|
611
|
+
}
|
|
612
|
+
if (isStart && isEnd) {
|
|
613
|
+
baseClass += " kz-calendar-day-active kz-calendar-day-rounded";
|
|
614
|
+
if (suffix) {
|
|
615
|
+
baseClass += " kz-calendar-day-active--".concat(suffix, " kz-calendar-day-rounded--").concat(suffix);
|
|
616
|
+
}
|
|
617
|
+
} else if (isStart) {
|
|
618
|
+
baseClass += " kz-calendar-day-active";
|
|
619
|
+
if (suffix) baseClass += " kz-calendar-day-active--".concat(suffix);
|
|
620
|
+
var isStartBeforeEnd = end && isBeforeDate(start, end);
|
|
621
|
+
var isStartBeforeHover = !end && hover && isBeforeDate(start, hover);
|
|
622
|
+
if (isStartBeforeEnd || isStartBeforeHover) {
|
|
623
|
+
baseClass += " kz-calendar-day-hover-left";
|
|
624
|
+
if (suffix) baseClass += " kz-calendar-day-hover-left--".concat(suffix);
|
|
625
|
+
} else {
|
|
626
|
+
baseClass += " kz-calendar-day-hover-right";
|
|
627
|
+
if (suffix) baseClass += " kz-calendar-day-hover-right--".concat(suffix);
|
|
628
|
+
}
|
|
629
|
+
} else if (isEnd) {
|
|
630
|
+
baseClass += " kz-calendar-day-active";
|
|
631
|
+
if (suffix) baseClass += " kz-calendar-day-active--".concat(suffix);
|
|
632
|
+
var isEndAfterStart = start && isAfterDate(end, start);
|
|
633
|
+
var isEndAfterHover = !start && hover && isAfterDate(end, hover);
|
|
634
|
+
if (isEndAfterStart || isEndAfterHover) {
|
|
635
|
+
baseClass += " kz-calendar-day-hover-right";
|
|
636
|
+
if (suffix) baseClass += " kz-calendar-day-hover-right--".concat(suffix);
|
|
637
|
+
} else {
|
|
638
|
+
baseClass += " kz-calendar-day-hover-left";
|
|
639
|
+
if (suffix) baseClass += " kz-calendar-day-hover-left--".concat(suffix);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
if (start && end && isBetweenDates(currentDayDate, start, end)) {
|
|
643
|
+
baseClass += " kz-calendar-day-in-range";
|
|
644
|
+
if (suffix) baseClass += " kz-calendar-day-in-range--".concat(suffix);
|
|
645
|
+
}
|
|
646
|
+
if (hover) {
|
|
647
|
+
if (start && !end && isBetweenDates(currentDayDate, start, hover)) {
|
|
648
|
+
baseClass += " kz-calendar-day-in-range";
|
|
649
|
+
if (suffix) baseClass += " kz-calendar-day-in-range--".concat(suffix);
|
|
650
|
+
}
|
|
651
|
+
if (end && !start && isBetweenDates(currentDayDate, hover, end)) {
|
|
652
|
+
baseClass += " kz-calendar-day-in-range";
|
|
653
|
+
if (suffix) baseClass += " kz-calendar-day-in-range--".concat(suffix);
|
|
654
|
+
}
|
|
655
|
+
if (hover.getTime() === currentDayDate.getTime() && !(isStart || isEnd)) {
|
|
656
|
+
baseClass += " kz-calendar-day-hover-end";
|
|
657
|
+
if (suffix) baseClass += " kz-calendar-day-hover-end--".concat(suffix);
|
|
658
|
+
if (start) {
|
|
659
|
+
if (isBeforeDate(currentDayDate, start)) {
|
|
660
|
+
baseClass += " kz-calendar-day-hover-left";
|
|
661
|
+
if (suffix) baseClass += " kz-calendar-day-hover-left--".concat(suffix);
|
|
662
|
+
} else {
|
|
663
|
+
baseClass += " kz-calendar-day-hover-right";
|
|
664
|
+
if (suffix) baseClass += " kz-calendar-day-hover-right--".concat(suffix);
|
|
665
|
+
}
|
|
666
|
+
} else if (end) {
|
|
667
|
+
if (isAfterDate(currentDayDate, end)) {
|
|
668
|
+
baseClass += " kz-calendar-day-hover-right";
|
|
669
|
+
if (suffix) baseClass += " kz-calendar-day-hover-right--".concat(suffix);
|
|
670
|
+
} else {
|
|
671
|
+
baseClass += " kz-calendar-day-hover-left";
|
|
672
|
+
if (suffix) baseClass += " kz-calendar-day-hover-left--".concat(suffix);
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
return baseClass;
|
|
678
|
+
};
|
|
679
|
+
var handleClick = function handleClick(day, type) {
|
|
680
|
+
if (isDateDisabled(day, type)) return;
|
|
681
|
+
if (type === "previous") onClickPreviousDays(day);
|
|
682
|
+
if (type === "current") onClickDay(day);
|
|
683
|
+
if (type === "next") onClickNextDays(day);
|
|
684
|
+
};
|
|
685
|
+
var processHover = function processHover(day, type) {
|
|
686
|
+
if (isDateDisabled(day, type)) return;
|
|
687
|
+
var date = calendarData.date;
|
|
688
|
+
var m = date.getMonth();
|
|
689
|
+
var y = date.getFullYear();
|
|
690
|
+
if (type === "previous") m -= 1;
|
|
691
|
+
if (type === "next") m += 1;
|
|
692
|
+
var dStr = "".concat(y, "-").concat(String(m + 1).padStart(2, '0'), "-").concat(String(day).padStart(2, '0'));
|
|
693
|
+
changeDayHover(dStr);
|
|
694
|
+
};
|
|
695
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
696
|
+
className: "kz-calendar-days-grid" + (suffix ? " kz-calendar-days-grid--".concat(suffix) : ""),
|
|
697
|
+
onMouseLeave: function onMouseLeave() {
|
|
698
|
+
return changeDayHover(null);
|
|
699
|
+
}
|
|
700
|
+
}, ["previous", "current", "next"].map(function (type) {
|
|
701
|
+
return calendarData.days[type].map(function (day, idx) {
|
|
702
|
+
return /*#__PURE__*/React.createElement("button", {
|
|
703
|
+
key: "".concat(type, "-").concat(idx),
|
|
704
|
+
className: getButtonClass(day, type),
|
|
705
|
+
onClick: function onClick() {
|
|
706
|
+
return handleClick(day, type);
|
|
707
|
+
},
|
|
708
|
+
onMouseOver: function onMouseOver() {
|
|
709
|
+
return processHover(day, type);
|
|
710
|
+
},
|
|
711
|
+
disabled: isDateDisabled(day, type)
|
|
712
|
+
}, day);
|
|
713
|
+
});
|
|
714
|
+
}));
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
var Months = function Months(_ref) {
|
|
718
|
+
var currentMonth = _ref.currentMonth,
|
|
719
|
+
clickMonth = _ref.clickMonth;
|
|
720
|
+
var _useContext = React.useContext(DatepickerContext),
|
|
721
|
+
i18n = _useContext.i18n,
|
|
722
|
+
suffix = _useContext.suffix;
|
|
723
|
+
var getMonthName = function getMonthName(monthNumber) {
|
|
724
|
+
var date = new Date(2022, monthNumber - 1, 1);
|
|
725
|
+
return date.toLocaleString(i18n || "en-US", {
|
|
726
|
+
month: "short"
|
|
727
|
+
});
|
|
728
|
+
};
|
|
729
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
730
|
+
className: "kz-calendar-months-grid" + (suffix ? " kz-calendar-months-grid--".concat(suffix) : "")
|
|
731
|
+
}, MONTHS.map(function (item) {
|
|
732
|
+
return /*#__PURE__*/React.createElement(RoundedButton, {
|
|
733
|
+
key: item,
|
|
734
|
+
padding: "py-3",
|
|
735
|
+
onClick: function onClick() {
|
|
736
|
+
return clickMonth(item);
|
|
737
|
+
},
|
|
738
|
+
active: currentMonth === item
|
|
739
|
+
}, getMonthName(item));
|
|
740
|
+
}));
|
|
741
|
+
};
|
|
742
|
+
|
|
743
|
+
var Week = function Week() {
|
|
744
|
+
var _useContext = React.useContext(DatepickerContext),
|
|
745
|
+
i18n = _useContext.i18n,
|
|
746
|
+
startWeekOn = _useContext.startWeekOn,
|
|
747
|
+
suffix = _useContext.suffix;
|
|
748
|
+
var startDateModifier = React.useMemo(function () {
|
|
749
|
+
switch (startWeekOn) {
|
|
750
|
+
case "mon":
|
|
751
|
+
return 1;
|
|
752
|
+
case "tue":
|
|
753
|
+
return 2;
|
|
754
|
+
case "wed":
|
|
755
|
+
return 3;
|
|
756
|
+
case "thu":
|
|
757
|
+
return 4;
|
|
758
|
+
case "fri":
|
|
759
|
+
return 5;
|
|
760
|
+
case "sat":
|
|
761
|
+
return 6;
|
|
762
|
+
case "sun":
|
|
763
|
+
default:
|
|
764
|
+
return 0;
|
|
765
|
+
}
|
|
766
|
+
}, [startWeekOn]);
|
|
767
|
+
var getDayName = function getDayName(dayIndex) {
|
|
768
|
+
// Nov 6, 2022 is a Sunday.
|
|
769
|
+
var date = new Date(2022, 10, 6 + dayIndex + startDateModifier);
|
|
770
|
+
return ucFirst(shortString(date.toLocaleDateString(i18n || "en-US", {
|
|
771
|
+
weekday: "short"
|
|
772
|
+
})));
|
|
773
|
+
};
|
|
774
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
775
|
+
className: "kz-calendar-week-grid" + (suffix ? " kz-calendar-week-grid--".concat(suffix) : "")
|
|
776
|
+
}, DAYS.map(function (item) {
|
|
777
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
778
|
+
key: item,
|
|
779
|
+
className: "kz-calendar-week-day" + (suffix ? " kz-calendar-week-day--".concat(suffix) : "")
|
|
780
|
+
}, getDayName(item));
|
|
781
|
+
}));
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
var Years = function Years(_ref) {
|
|
785
|
+
var year = _ref.year,
|
|
786
|
+
currentYear = _ref.currentYear,
|
|
787
|
+
minYear = _ref.minYear,
|
|
788
|
+
maxYear = _ref.maxYear,
|
|
789
|
+
clickYear = _ref.clickYear;
|
|
790
|
+
var _useContext = React.useContext(DatepickerContext),
|
|
791
|
+
dateLooking = _useContext.dateLooking,
|
|
792
|
+
suffix = _useContext.suffix;
|
|
793
|
+
var startDate = 0;
|
|
794
|
+
var endDate = 0;
|
|
795
|
+
switch (dateLooking) {
|
|
796
|
+
case "backward":
|
|
797
|
+
startDate = year - 11;
|
|
798
|
+
endDate = year;
|
|
799
|
+
break;
|
|
800
|
+
case "middle":
|
|
801
|
+
startDate = year - 4;
|
|
802
|
+
endDate = year + 7;
|
|
803
|
+
break;
|
|
804
|
+
case "forward":
|
|
805
|
+
default:
|
|
806
|
+
startDate = year;
|
|
807
|
+
endDate = year + 11;
|
|
808
|
+
break;
|
|
809
|
+
}
|
|
810
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
811
|
+
className: "kz-calendar-years-grid" + (suffix ? " kz-calendar-years-grid--".concat(suffix) : "")
|
|
812
|
+
}, generateArrayNumber(startDate, endDate).map(function (item, index) {
|
|
813
|
+
return /*#__PURE__*/React.createElement(RoundedButton, {
|
|
814
|
+
key: index,
|
|
815
|
+
padding: "py-3",
|
|
816
|
+
onClick: function onClick() {
|
|
817
|
+
return clickYear(item);
|
|
818
|
+
},
|
|
819
|
+
active: currentYear === item,
|
|
820
|
+
disabled: maxYear !== null && item > maxYear || minYear !== null && item < minYear
|
|
821
|
+
}, item);
|
|
822
|
+
}));
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
var Calendar = function Calendar(_ref) {
|
|
826
|
+
var date = _ref.date,
|
|
827
|
+
minDate = _ref.minDate,
|
|
828
|
+
maxDate = _ref.maxDate,
|
|
829
|
+
onClickPrevious = _ref.onClickPrevious,
|
|
830
|
+
onClickNext = _ref.onClickNext,
|
|
831
|
+
changeMonth = _ref.changeMonth,
|
|
832
|
+
changeYear = _ref.changeYear;
|
|
833
|
+
var _useContext = React.useContext(DatepickerContext),
|
|
834
|
+
asSingle = _useContext.asSingle,
|
|
835
|
+
showFooter = _useContext.showFooter,
|
|
836
|
+
changeDatepickerValue = _useContext.changeDatepickerValue,
|
|
837
|
+
hideDatepicker = _useContext.hideDatepicker,
|
|
838
|
+
period = _useContext.period,
|
|
839
|
+
changePeriod = _useContext.changePeriod,
|
|
840
|
+
changeDayHover = _useContext.changeDayHover,
|
|
841
|
+
startWeekOn = _useContext.startWeekOn,
|
|
842
|
+
input = _useContext.input,
|
|
843
|
+
suffix = _useContext.suffix;
|
|
844
|
+
var _useState = React.useState(false),
|
|
845
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
846
|
+
showMonths = _useState2[0],
|
|
847
|
+
setShowMonths = _useState2[1];
|
|
848
|
+
var _useState3 = React.useState(false),
|
|
849
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
850
|
+
showYears = _useState4[0],
|
|
851
|
+
setShowYears = _useState4[1];
|
|
852
|
+
var _useState5 = React.useState(date.getFullYear()),
|
|
853
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
854
|
+
year = _useState6[0],
|
|
855
|
+
setYear = _useState6[1];
|
|
856
|
+
var previous = function previous() {
|
|
857
|
+
return getLastDaysInMonth(previousMonth(date), getNumberOfDay(getFirstDayInMonth(date).ddd, startWeekOn));
|
|
858
|
+
};
|
|
859
|
+
var current = function current() {
|
|
860
|
+
return getDaysInMonth(date);
|
|
861
|
+
};
|
|
862
|
+
var next = function next() {
|
|
863
|
+
return getFirstDaysInMonth(previousMonth(date), 42 - (previous().length + current().length));
|
|
864
|
+
};
|
|
865
|
+
var hideMonths = function hideMonths() {
|
|
866
|
+
return showMonths && setShowMonths(false);
|
|
867
|
+
};
|
|
868
|
+
var hideYears = function hideYears() {
|
|
869
|
+
return showYears && setShowYears(false);
|
|
870
|
+
};
|
|
871
|
+
var clickMonth = function clickMonth(month) {
|
|
872
|
+
setTimeout(function () {
|
|
873
|
+
changeMonth(month);
|
|
874
|
+
setShowMonths(!showMonths);
|
|
875
|
+
}, 250);
|
|
876
|
+
};
|
|
877
|
+
var clickYear = function clickYear(year) {
|
|
878
|
+
setTimeout(function () {
|
|
879
|
+
changeYear(year);
|
|
880
|
+
setShowYears(!showYears);
|
|
881
|
+
}, 250);
|
|
882
|
+
};
|
|
883
|
+
var clickDay = function clickDay(day) {
|
|
884
|
+
var month = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : date.getMonth() + 1;
|
|
885
|
+
var year = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : date.getFullYear();
|
|
886
|
+
var fullDay = "".concat(year, "-").concat(String(month).padStart(2, "0"), "-").concat(String(day).padStart(2, "0"));
|
|
887
|
+
var newStart;
|
|
888
|
+
var newEnd = null;
|
|
889
|
+
function chosePeriod(start, end) {
|
|
890
|
+
changeDatepickerValue({
|
|
891
|
+
startDate: start,
|
|
892
|
+
endDate: end
|
|
893
|
+
}, input === null || input === void 0 ? void 0 : input.current);
|
|
894
|
+
hideDatepicker();
|
|
895
|
+
}
|
|
896
|
+
if (period.start && period.end) {
|
|
897
|
+
changeDayHover(null);
|
|
898
|
+
changePeriod({
|
|
899
|
+
start: null,
|
|
900
|
+
end: null
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
if (!period.start && !period.end || period.start && period.end) {
|
|
904
|
+
if (!period.start && !period.end) {
|
|
905
|
+
changeDayHover(fullDay);
|
|
906
|
+
}
|
|
907
|
+
newStart = fullDay;
|
|
908
|
+
if (asSingle) {
|
|
909
|
+
newEnd = fullDay;
|
|
910
|
+
chosePeriod(fullDay, fullDay);
|
|
911
|
+
}
|
|
912
|
+
} else {
|
|
913
|
+
if (period.start && !period.end) {
|
|
914
|
+
var startDate = new Date(period.start);
|
|
915
|
+
var clickedDate = new Date(fullDay);
|
|
916
|
+
var condition = clickedDate.getTime() >= startDate.getTime();
|
|
917
|
+
newStart = condition ? period.start : fullDay;
|
|
918
|
+
newEnd = condition ? fullDay : period.start;
|
|
919
|
+
} else {
|
|
920
|
+
var endDate = new Date(period.end);
|
|
921
|
+
var _clickedDate = new Date(fullDay);
|
|
922
|
+
var _condition = _clickedDate.getTime() <= endDate.getTime();
|
|
923
|
+
newStart = _condition ? fullDay : period.start;
|
|
924
|
+
newEnd = _condition ? period.end : fullDay;
|
|
925
|
+
}
|
|
926
|
+
if (!showFooter && newStart && newEnd) {
|
|
927
|
+
chosePeriod(newStart, newEnd);
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
if (!(newEnd && newStart) || showFooter) {
|
|
931
|
+
changePeriod({
|
|
932
|
+
start: newStart,
|
|
933
|
+
end: newEnd
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
};
|
|
937
|
+
var clickPreviousDays = function clickPreviousDays(day) {
|
|
938
|
+
var newDate = previousMonth(date);
|
|
939
|
+
clickDay(day, newDate.getMonth() + 1, newDate.getFullYear());
|
|
940
|
+
onClickPrevious();
|
|
941
|
+
};
|
|
942
|
+
var clickNextDays = function clickNextDays(day) {
|
|
943
|
+
var newDate = nextMonth(date);
|
|
944
|
+
clickDay(day, newDate.getMonth() + 1, newDate.getFullYear());
|
|
945
|
+
onClickNext();
|
|
946
|
+
};
|
|
947
|
+
React.useEffect(function () {
|
|
948
|
+
setYear(date.getFullYear());
|
|
949
|
+
}, [date]);
|
|
950
|
+
var calendarData = React.useMemo(function () {
|
|
951
|
+
return {
|
|
952
|
+
date: date,
|
|
953
|
+
days: {
|
|
954
|
+
previous: previous(),
|
|
955
|
+
current: current(),
|
|
956
|
+
next: next()
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
}, [date, previous, current, next]);
|
|
960
|
+
var minYear = React.useMemo(function () {
|
|
961
|
+
return minDate ? new Date(minDate).getFullYear() : null;
|
|
962
|
+
}, [minDate]);
|
|
963
|
+
var maxYear = React.useMemo(function () {
|
|
964
|
+
return maxDate ? new Date(maxDate).getFullYear() : null;
|
|
965
|
+
}, [maxDate]);
|
|
966
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
967
|
+
className: "kz-calendar" + (suffix ? " kz-calendar--".concat(suffix) : "")
|
|
968
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
969
|
+
className: "kz-calendar-header" + (suffix ? " kz-calendar-header--".concat(suffix) : "")
|
|
970
|
+
}, !showMonths && !showYears && /*#__PURE__*/React.createElement("div", {
|
|
971
|
+
className: "kz-calendar-header-nav" + (suffix ? " kz-calendar-header-nav--".concat(suffix) : "")
|
|
972
|
+
}, /*#__PURE__*/React.createElement(RoundedButton, {
|
|
973
|
+
roundedFull: true,
|
|
974
|
+
onClick: onClickPrevious
|
|
975
|
+
}, /*#__PURE__*/React.createElement(ChevronLeftIcon, null))), showYears && /*#__PURE__*/React.createElement("div", {
|
|
976
|
+
className: "kz-calendar-header-nav" + (suffix ? " kz-calendar-header-nav--".concat(suffix) : "")
|
|
977
|
+
}, /*#__PURE__*/React.createElement(RoundedButton, {
|
|
978
|
+
roundedFull: true,
|
|
979
|
+
onClick: function onClick() {
|
|
980
|
+
return setYear(year - 12);
|
|
981
|
+
}
|
|
982
|
+
}, /*#__PURE__*/React.createElement(DoubleChevronLeftIcon, null))), /*#__PURE__*/React.createElement("div", {
|
|
983
|
+
className: "kz-calendar-header-title" + (suffix ? " kz-calendar-header-title--".concat(suffix) : "")
|
|
984
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
985
|
+
className: "kz-calendar-header-month" + (suffix ? " kz-calendar-header-month--".concat(suffix) : "")
|
|
986
|
+
}, /*#__PURE__*/React.createElement(RoundedButton, {
|
|
987
|
+
onClick: function onClick() {
|
|
988
|
+
setShowMonths(!showMonths);
|
|
989
|
+
hideYears();
|
|
990
|
+
}
|
|
991
|
+
}, date.toLocaleDateString("en-US", {
|
|
992
|
+
month: "short"
|
|
993
|
+
}))), /*#__PURE__*/React.createElement("div", {
|
|
994
|
+
className: "kz-calendar-header-year" + (suffix ? " kz-calendar-header-year--".concat(suffix) : "")
|
|
995
|
+
}, /*#__PURE__*/React.createElement(RoundedButton, {
|
|
996
|
+
onClick: function onClick() {
|
|
997
|
+
setShowYears(!showYears);
|
|
998
|
+
hideMonths();
|
|
999
|
+
}
|
|
1000
|
+
}, date.getFullYear()))), showYears && /*#__PURE__*/React.createElement("div", {
|
|
1001
|
+
className: "kz-calendar-header-nav" + (suffix ? " kz-calendar-header-nav--".concat(suffix) : "")
|
|
1002
|
+
}, /*#__PURE__*/React.createElement(RoundedButton, {
|
|
1003
|
+
roundedFull: true,
|
|
1004
|
+
onClick: function onClick() {
|
|
1005
|
+
return setYear(year + 12);
|
|
1006
|
+
}
|
|
1007
|
+
}, /*#__PURE__*/React.createElement(DoubleChevronRightIcon, null))), !showMonths && !showYears && /*#__PURE__*/React.createElement("div", {
|
|
1008
|
+
className: "kz-calendar-header-nav" + (suffix ? " kz-calendar-header-nav--".concat(suffix) : "")
|
|
1009
|
+
}, /*#__PURE__*/React.createElement(RoundedButton, {
|
|
1010
|
+
roundedFull: true,
|
|
1011
|
+
onClick: onClickNext
|
|
1012
|
+
}, /*#__PURE__*/React.createElement(ChevronRightIcon, null)))), /*#__PURE__*/React.createElement("div", {
|
|
1013
|
+
className: "kz-calendar-body" + (suffix ? " kz-calendar-body--".concat(suffix) : "")
|
|
1014
|
+
}, showMonths && /*#__PURE__*/React.createElement(Months, {
|
|
1015
|
+
currentMonth: date.getMonth() + 1,
|
|
1016
|
+
clickMonth: clickMonth
|
|
1017
|
+
}), showYears && /*#__PURE__*/React.createElement(Years, {
|
|
1018
|
+
year: year,
|
|
1019
|
+
minYear: minYear,
|
|
1020
|
+
maxYear: maxYear,
|
|
1021
|
+
currentYear: date.getFullYear(),
|
|
1022
|
+
clickYear: clickYear
|
|
1023
|
+
}), !showMonths && !showYears && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Week, null), /*#__PURE__*/React.createElement(Days, {
|
|
1024
|
+
calendarData: calendarData,
|
|
1025
|
+
onClickPreviousDays: clickPreviousDays,
|
|
1026
|
+
onClickDay: clickDay,
|
|
1027
|
+
onClickNextDays: clickNextDays
|
|
1028
|
+
}))));
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1031
|
+
var Footer = function Footer() {
|
|
1032
|
+
var _configs$footer, _configs$footer2;
|
|
1033
|
+
var _useContext = React.useContext(DatepickerContext),
|
|
1034
|
+
hideDatepicker = _useContext.hideDatepicker,
|
|
1035
|
+
period = _useContext.period,
|
|
1036
|
+
changeDatepickerValue = _useContext.changeDatepickerValue,
|
|
1037
|
+
configs = _useContext.configs,
|
|
1038
|
+
suffix = _useContext.suffix;
|
|
1039
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1040
|
+
className: "kz-datepicker-footer" + (suffix ? " kz-datepicker-footer--".concat(suffix) : "")
|
|
1041
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1042
|
+
className: "kz-datepicker-footer-buttons" + (suffix ? " kz-datepicker-footer-buttons--".concat(suffix) : "")
|
|
1043
|
+
}, /*#__PURE__*/React.createElement(SecondaryButton, {
|
|
1044
|
+
onClick: hideDatepicker
|
|
1045
|
+
}, configs !== null && configs !== void 0 && (_configs$footer = configs.footer) !== null && _configs$footer !== void 0 && _configs$footer.cancel ? configs.footer.cancel : "Cancel"), /*#__PURE__*/React.createElement(PrimaryButton, {
|
|
1046
|
+
onClick: function onClick() {
|
|
1047
|
+
if (period.start && period.end) {
|
|
1048
|
+
changeDatepickerValue({
|
|
1049
|
+
startDate: formatDate(period.start, DATE_FORMAT),
|
|
1050
|
+
endDate: formatDate(period.end, DATE_FORMAT)
|
|
1051
|
+
});
|
|
1052
|
+
hideDatepicker();
|
|
1053
|
+
}
|
|
1054
|
+
},
|
|
1055
|
+
disabled: !(period.start && period.end)
|
|
1056
|
+
}, configs !== null && configs !== void 0 && (_configs$footer2 = configs.footer) !== null && _configs$footer2 !== void 0 && _configs$footer2.apply ? configs.footer.apply : "Apply")));
|
|
1057
|
+
};
|
|
1058
|
+
|
|
1059
|
+
var ToggleButton = function ToggleButton(_ref) {
|
|
1060
|
+
_ref.isEmpty;
|
|
1061
|
+
return /*#__PURE__*/React.createElement("svg", {
|
|
1062
|
+
className: "kz-datepicker-toggle-icon",
|
|
1063
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1064
|
+
fill: "none",
|
|
1065
|
+
viewBox: "0 0 24 24",
|
|
1066
|
+
strokeWidth: 1.5,
|
|
1067
|
+
stroke: "currentColor"
|
|
1068
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
1069
|
+
strokeLinecap: "round",
|
|
1070
|
+
strokeLinejoin: "round",
|
|
1071
|
+
d: "M6.75 3v2.25M17.25 3v2.25M3 18.75V7.5a2.25 2.25 0 012.25-2.25h13.5A2.25 2.25 0 0121 7.5v11.25m-18 0A2.25 2.25 0 005.25 21h13.5A2.25 2.25 0 0021 18.75m-18 0v-7.5A2.25 2.25 0 015.25 9h13.5A2.25 2.25 0 0121 11.25v7.5m-9-6h.008v.008H12v-.008zM12 15h.008v.008H12V15zm0 2.25h.008v.008H12v-.008zM9.75 15h.008v.008H9.75V15zm0 2.25h.008v.008H9.75v-.008zM7.5 15h.008v.008H7.5V15zm0 2.25h.008v.008H7.5v-.008zm6.75-4.5h.008v.008h-.008v-.008zm0 2.25h.008v.008h-.008V15zm0 2.25h.008v.008h-.008v-.008zm2.25-4.5h.008v.008H16.5v-.008zm0 2.25h.008v.008H16.5V15z"
|
|
1072
|
+
}));
|
|
1073
|
+
};
|
|
1074
|
+
var Input = function Input(_ref2) {
|
|
1075
|
+
var _shortcutTextRef$curr;
|
|
1076
|
+
var setContextRef = _ref2.setContextRef;
|
|
1077
|
+
var _useContext = React.useContext(DatepickerContext),
|
|
1078
|
+
period = _useContext.period,
|
|
1079
|
+
dayHover = _useContext.dayHover,
|
|
1080
|
+
changeDayHover = _useContext.changeDayHover,
|
|
1081
|
+
calendarContainer = _useContext.calendarContainer,
|
|
1082
|
+
arrowContainer = _useContext.arrowContainer,
|
|
1083
|
+
inputText = _useContext.inputText,
|
|
1084
|
+
changeInputText = _useContext.changeInputText,
|
|
1085
|
+
hideDatepicker = _useContext.hideDatepicker,
|
|
1086
|
+
changeDatepickerValue = _useContext.changeDatepickerValue,
|
|
1087
|
+
asSingle = _useContext.asSingle,
|
|
1088
|
+
placeholder = _useContext.placeholder,
|
|
1089
|
+
separator = _useContext.separator,
|
|
1090
|
+
shortcutText = _useContext.shortcutText,
|
|
1091
|
+
disabled = _useContext.disabled,
|
|
1092
|
+
readOnly = _useContext.readOnly,
|
|
1093
|
+
displayFormat = _useContext.displayFormat,
|
|
1094
|
+
inputId = _useContext.inputId,
|
|
1095
|
+
inputName = _useContext.inputName,
|
|
1096
|
+
popoverDirection = _useContext.popoverDirection,
|
|
1097
|
+
suffix = _useContext.suffix,
|
|
1098
|
+
placement = _useContext.placement;
|
|
1099
|
+
var buttonRef = React.useRef(null);
|
|
1100
|
+
var inputRef = React.useRef(null);
|
|
1101
|
+
var shortcutTextRef = React.useRef(null);
|
|
1102
|
+
var handleInputChange = function handleInputChange(e) {
|
|
1103
|
+
var inputValue = e.target.value;
|
|
1104
|
+
var dates = [];
|
|
1105
|
+
if (asSingle) {
|
|
1106
|
+
var date = parseDate(inputValue);
|
|
1107
|
+
if (dateIsValid(date)) {
|
|
1108
|
+
dates.push(formatDate(date, DATE_FORMAT));
|
|
1109
|
+
}
|
|
1110
|
+
} else {
|
|
1111
|
+
var parsed = inputValue.split(separator);
|
|
1112
|
+
var startDate = null;
|
|
1113
|
+
var endDate = null;
|
|
1114
|
+
if (parsed.length === 2) {
|
|
1115
|
+
startDate = parseDate(parsed[0].trim());
|
|
1116
|
+
endDate = parseDate(parsed[1].trim());
|
|
1117
|
+
} else {
|
|
1118
|
+
var middle = Math.floor(inputValue.length / 2);
|
|
1119
|
+
startDate = parseDate(inputValue.slice(0, middle));
|
|
1120
|
+
endDate = parseDate(inputValue.slice(middle));
|
|
1121
|
+
}
|
|
1122
|
+
if (dateIsValid(startDate) && dateIsValid(endDate) && startDate.getTime() <= endDate.getTime()) {
|
|
1123
|
+
dates.push(formatDate(startDate, DATE_FORMAT));
|
|
1124
|
+
dates.push(formatDate(endDate, DATE_FORMAT));
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
if (dates[0]) {
|
|
1128
|
+
changeDatepickerValue({
|
|
1129
|
+
startDate: dates[0],
|
|
1130
|
+
endDate: dates[1] || dates[0]
|
|
1131
|
+
}, e.target);
|
|
1132
|
+
var hoverD = dates[1] ? parseDate(dates[1]) : parseDate(dates[0]);
|
|
1133
|
+
if (dates[1]) hoverD.setDate(hoverD.getDate() - 1);
|
|
1134
|
+
changeDayHover(formatDate(hoverD, DATE_FORMAT));
|
|
1135
|
+
}
|
|
1136
|
+
changeInputText(e.target.value);
|
|
1137
|
+
};
|
|
1138
|
+
var handleInputKeyDown = function handleInputKeyDown(e) {
|
|
1139
|
+
if (e.key === "Enter") {
|
|
1140
|
+
var _inputRef$current;
|
|
1141
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.blur();
|
|
1142
|
+
hideDatepicker();
|
|
1143
|
+
}
|
|
1144
|
+
};
|
|
1145
|
+
React.useEffect(function () {
|
|
1146
|
+
if (inputRef && typeof setContextRef === "function") {
|
|
1147
|
+
setContextRef(inputRef);
|
|
1148
|
+
}
|
|
1149
|
+
}, [setContextRef, inputRef]);
|
|
1150
|
+
React.useEffect(function () {
|
|
1151
|
+
var button = buttonRef === null || buttonRef === void 0 ? void 0 : buttonRef.current;
|
|
1152
|
+
var shortcut = shortcutTextRef === null || shortcutTextRef === void 0 ? void 0 : shortcutTextRef.current;
|
|
1153
|
+
function focusInput(e) {
|
|
1154
|
+
var _inputRef$current2;
|
|
1155
|
+
e.stopPropagation();
|
|
1156
|
+
(_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 || _inputRef$current2.focus();
|
|
1157
|
+
}
|
|
1158
|
+
if (button) button.addEventListener("click", focusInput);
|
|
1159
|
+
if (shortcut) shortcut.addEventListener("click", focusInput);
|
|
1160
|
+
return function () {
|
|
1161
|
+
if (button) button.removeEventListener("click", focusInput);
|
|
1162
|
+
if (shortcut) shortcut.removeEventListener("click", focusInput);
|
|
1163
|
+
};
|
|
1164
|
+
}, [changeDatepickerValue, changeDayHover, changeInputText, dayHover, inputText, period.end, period.start]);
|
|
1165
|
+
React.useEffect(function () {
|
|
1166
|
+
var div = calendarContainer === null || calendarContainer === void 0 ? void 0 : calendarContainer.current;
|
|
1167
|
+
var input = inputRef.current;
|
|
1168
|
+
var arrow = arrowContainer === null || arrowContainer === void 0 ? void 0 : arrowContainer.current;
|
|
1169
|
+
function showCalendarContainer() {
|
|
1170
|
+
if (arrow && div && div.style.display === "none") {
|
|
1171
|
+
div.style.display = "block";
|
|
1172
|
+
var inputRect = input.getBoundingClientRect();
|
|
1173
|
+
var activePlacement = placement;
|
|
1174
|
+
if (placement === "auto") {
|
|
1175
|
+
var spaceBelow = window.innerHeight - inputRect.bottom;
|
|
1176
|
+
var spaceAbove = inputRect.top;
|
|
1177
|
+
activePlacement = spaceBelow > 350 || spaceBelow >= spaceAbove ? "bottom" : "top";
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// Reset inline styles
|
|
1181
|
+
div.style.top = "";
|
|
1182
|
+
div.style.bottom = "";
|
|
1183
|
+
div.style.left = "";
|
|
1184
|
+
div.style.right = "";
|
|
1185
|
+
div.style.marginTop = "";
|
|
1186
|
+
div.style.marginBottom = "";
|
|
1187
|
+
div.style.marginLeft = "";
|
|
1188
|
+
div.style.marginRight = "";
|
|
1189
|
+
if (activePlacement === "top") {
|
|
1190
|
+
div.style.bottom = "100%";
|
|
1191
|
+
div.style.top = "auto";
|
|
1192
|
+
div.style.marginBottom = "0.625rem";
|
|
1193
|
+
} else if (activePlacement === "bottom") {
|
|
1194
|
+
div.style.top = "100%";
|
|
1195
|
+
div.style.bottom = "auto";
|
|
1196
|
+
} else if (activePlacement === "left") {
|
|
1197
|
+
div.style.right = "100%";
|
|
1198
|
+
div.style.left = "auto";
|
|
1199
|
+
div.style.top = "0";
|
|
1200
|
+
div.style.marginRight = "0.625rem";
|
|
1201
|
+
} else if (activePlacement === "right") {
|
|
1202
|
+
div.style.left = "100%";
|
|
1203
|
+
div.style.right = "auto";
|
|
1204
|
+
div.style.top = "0";
|
|
1205
|
+
div.style.marginLeft = "0.625rem";
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
// Timeout to allow DOM layout
|
|
1209
|
+
setTimeout(function () {
|
|
1210
|
+
div.classList.add("kz-datepicker-open");
|
|
1211
|
+
if (suffix) div.classList.add("kz-datepicker-open--".concat(suffix));
|
|
1212
|
+
}, 10);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
if (div && input) {
|
|
1216
|
+
input.addEventListener("focus", showCalendarContainer);
|
|
1217
|
+
}
|
|
1218
|
+
return function () {
|
|
1219
|
+
if (input) {
|
|
1220
|
+
input.removeEventListener("focus", showCalendarContainer);
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
}, [calendarContainer, arrowContainer, popoverDirection, placement]);
|
|
1224
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1225
|
+
className: "kz-datepicker-input-wrapper" + (suffix ? " kz-datepicker-input-wrapper--".concat(suffix) : "")
|
|
1226
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
1227
|
+
ref: inputRef,
|
|
1228
|
+
type: "text",
|
|
1229
|
+
className: "kz-datepicker-input" + (suffix ? " kz-datepicker-input--".concat(suffix) : ""),
|
|
1230
|
+
disabled: disabled,
|
|
1231
|
+
readOnly: readOnly,
|
|
1232
|
+
placeholder: placeholder || "".concat(displayFormat).concat(asSingle ? "" : " ".concat(separator, " ").concat(displayFormat)),
|
|
1233
|
+
value: inputText,
|
|
1234
|
+
id: inputId,
|
|
1235
|
+
name: inputName,
|
|
1236
|
+
autoComplete: "off",
|
|
1237
|
+
role: "presentation",
|
|
1238
|
+
onChange: handleInputChange,
|
|
1239
|
+
onKeyDown: handleInputKeyDown,
|
|
1240
|
+
style: {
|
|
1241
|
+
paddingLeft: shortcutText ? "".concat(((_shortcutTextRef$curr = shortcutTextRef.current) === null || _shortcutTextRef$curr === void 0 ? void 0 : _shortcutTextRef$curr.clientWidth) || 0, "px") : undefined
|
|
1242
|
+
}
|
|
1243
|
+
}), shortcutText && /*#__PURE__*/React.createElement("span", {
|
|
1244
|
+
ref: shortcutTextRef,
|
|
1245
|
+
className: "kz-datepicker-shortcut-text" + (suffix ? " kz-datepicker-shortcut-text--".concat(suffix) : "")
|
|
1246
|
+
}, shortcutText), /*#__PURE__*/React.createElement("button", {
|
|
1247
|
+
type: "button",
|
|
1248
|
+
ref: buttonRef,
|
|
1249
|
+
disabled: disabled,
|
|
1250
|
+
className: "kz-datepicker-toggle-button" + (suffix ? " kz-datepicker-toggle-button--".concat(suffix) : "")
|
|
1251
|
+
}, /*#__PURE__*/React.createElement(ToggleButton, {
|
|
1252
|
+
isEmpty: !(inputText !== null && inputText !== void 0 && inputText.length)
|
|
1253
|
+
})));
|
|
1254
|
+
};
|
|
1255
|
+
|
|
1256
|
+
var _today = new Date();
|
|
1257
|
+
var DEFAULT_SHORTCUTS = {
|
|
1258
|
+
today: {
|
|
1259
|
+
text: "Today",
|
|
1260
|
+
period: {
|
|
1261
|
+
start: formatDate(_today),
|
|
1262
|
+
end: formatDate(_today)
|
|
1263
|
+
}
|
|
1264
|
+
},
|
|
1265
|
+
yesterday: {
|
|
1266
|
+
text: "Yesterday",
|
|
1267
|
+
period: {
|
|
1268
|
+
start: formatDate(new Date(new Date().setDate(_today.getDate() - 1))),
|
|
1269
|
+
end: formatDate(new Date(new Date().setDate(_today.getDate() - 1)))
|
|
1270
|
+
}
|
|
1271
|
+
},
|
|
1272
|
+
past: [{
|
|
1273
|
+
daysNumber: 7,
|
|
1274
|
+
text: "Last 7 days",
|
|
1275
|
+
period: {
|
|
1276
|
+
start: formatDate(new Date(new Date().setDate(_today.getDate() - 7))),
|
|
1277
|
+
end: formatDate(_today)
|
|
1278
|
+
}
|
|
1279
|
+
}, {
|
|
1280
|
+
daysNumber: 30,
|
|
1281
|
+
text: "Last 30 days",
|
|
1282
|
+
period: {
|
|
1283
|
+
start: formatDate(new Date(new Date().setDate(_today.getDate() - 30))),
|
|
1284
|
+
end: formatDate(_today)
|
|
1285
|
+
}
|
|
1286
|
+
}],
|
|
1287
|
+
currentMonth: {
|
|
1288
|
+
text: "This month",
|
|
1289
|
+
period: {
|
|
1290
|
+
start: formatDate(new Date(_today.getFullYear(), _today.getMonth(), 1)),
|
|
1291
|
+
end: formatDate(new Date(_today.getFullYear(), _today.getMonth() + 1, 0))
|
|
1292
|
+
}
|
|
1293
|
+
},
|
|
1294
|
+
pastMonth: {
|
|
1295
|
+
text: "Last month",
|
|
1296
|
+
period: {
|
|
1297
|
+
start: formatDate(new Date(_today.getFullYear(), _today.getMonth() - 1, 1)),
|
|
1298
|
+
end: formatDate(new Date(_today.getFullYear(), _today.getMonth(), 0))
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
};
|
|
1302
|
+
|
|
1303
|
+
var ItemTemplate = /*#__PURE__*/React.memo(function (_ref) {
|
|
1304
|
+
var children = _ref.children,
|
|
1305
|
+
item = _ref.item;
|
|
1306
|
+
var _useContext = React.useContext(DatepickerContext),
|
|
1307
|
+
period = _useContext.period,
|
|
1308
|
+
changePeriod = _useContext.changePeriod,
|
|
1309
|
+
updateFirstDate = _useContext.updateFirstDate,
|
|
1310
|
+
dayHover = _useContext.dayHover,
|
|
1311
|
+
changeDayHover = _useContext.changeDayHover,
|
|
1312
|
+
hideDatepicker = _useContext.hideDatepicker,
|
|
1313
|
+
changeDatepickerValue = _useContext.changeDatepickerValue,
|
|
1314
|
+
suffix = _useContext.suffix;
|
|
1315
|
+
var getClassName = function getClassName() {
|
|
1316
|
+
return "kz-datepicker-shortcut-item" + (suffix ? " kz-datepicker-shortcut-item--".concat(suffix) : "");
|
|
1317
|
+
};
|
|
1318
|
+
var chosePeriod = function chosePeriod(periodItem) {
|
|
1319
|
+
if (dayHover) changeDayHover(null);
|
|
1320
|
+
if (period.start || period.end) changePeriod({
|
|
1321
|
+
start: null,
|
|
1322
|
+
end: null
|
|
1323
|
+
});
|
|
1324
|
+
changePeriod(periodItem);
|
|
1325
|
+
changeDatepickerValue({
|
|
1326
|
+
startDate: periodItem.start,
|
|
1327
|
+
endDate: periodItem.end
|
|
1328
|
+
});
|
|
1329
|
+
updateFirstDate(parseDate(periodItem.start));
|
|
1330
|
+
hideDatepicker();
|
|
1331
|
+
};
|
|
1332
|
+
return /*#__PURE__*/React.createElement("li", {
|
|
1333
|
+
className: getClassName(),
|
|
1334
|
+
onClick: function onClick(e) {
|
|
1335
|
+
chosePeriod(item.period);
|
|
1336
|
+
if (item.onClick) item.onClick(item.text, e);
|
|
1337
|
+
}
|
|
1338
|
+
}, children);
|
|
1339
|
+
});
|
|
1340
|
+
var Shortcuts = function Shortcuts() {
|
|
1341
|
+
var _useContext2 = React.useContext(DatepickerContext),
|
|
1342
|
+
configs = _useContext2.configs,
|
|
1343
|
+
suffix = _useContext2.suffix;
|
|
1344
|
+
var callPastFunction = function callPastFunction(data, numberValue) {
|
|
1345
|
+
return typeof data === "function" ? data(numberValue) : null;
|
|
1346
|
+
};
|
|
1347
|
+
var shortcutOptions = React.useMemo(function () {
|
|
1348
|
+
if (!(configs !== null && configs !== void 0 && configs.shortcuts)) return Object.entries(DEFAULT_SHORTCUTS);
|
|
1349
|
+
return Object.entries(configs.shortcuts).flatMap(function (_ref2) {
|
|
1350
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
1351
|
+
key = _ref3[0],
|
|
1352
|
+
customConfig = _ref3[1];
|
|
1353
|
+
if (Object.prototype.hasOwnProperty.call(DEFAULT_SHORTCUTS, key)) {
|
|
1354
|
+
return [[key, DEFAULT_SHORTCUTS[key]]];
|
|
1355
|
+
}
|
|
1356
|
+
var text = customConfig.text,
|
|
1357
|
+
period = customConfig.period,
|
|
1358
|
+
onClick = customConfig.onClick;
|
|
1359
|
+
if (!text || !period) return [];
|
|
1360
|
+
var start = parseDate(period.start);
|
|
1361
|
+
var end = parseDate(period.end);
|
|
1362
|
+
if (start && end && start.getTime() <= end.getTime()) {
|
|
1363
|
+
return [[text, {
|
|
1364
|
+
text: text,
|
|
1365
|
+
period: {
|
|
1366
|
+
start: formatDate(start, DATE_FORMAT),
|
|
1367
|
+
end: formatDate(end, DATE_FORMAT)
|
|
1368
|
+
},
|
|
1369
|
+
onClick: onClick
|
|
1370
|
+
}]];
|
|
1371
|
+
}
|
|
1372
|
+
return [];
|
|
1373
|
+
});
|
|
1374
|
+
}, [configs]);
|
|
1375
|
+
var printItemText = function printItemText(item) {
|
|
1376
|
+
var _item$text;
|
|
1377
|
+
return (_item$text = item === null || item === void 0 ? void 0 : item.text) !== null && _item$text !== void 0 ? _item$text : null;
|
|
1378
|
+
};
|
|
1379
|
+
if (!(shortcutOptions !== null && shortcutOptions !== void 0 && shortcutOptions.length)) return null;
|
|
1380
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1381
|
+
className: "kz-datepicker-shortcuts" + (suffix ? " kz-datepicker-shortcuts--".concat(suffix) : "")
|
|
1382
|
+
}, /*#__PURE__*/React.createElement("ul", {
|
|
1383
|
+
className: "kz-datepicker-shortcuts-list" + (suffix ? " kz-datepicker-shortcuts-list--".concat(suffix) : "")
|
|
1384
|
+
}, shortcutOptions.map(function (_ref4, index) {
|
|
1385
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
1386
|
+
key = _ref5[0],
|
|
1387
|
+
item = _ref5[1];
|
|
1388
|
+
return Array.isArray(item) ? item.map(function (subItem, subIndex) {
|
|
1389
|
+
return /*#__PURE__*/React.createElement(ItemTemplate, {
|
|
1390
|
+
key: "".concat(index, "-").concat(subIndex),
|
|
1391
|
+
item: subItem
|
|
1392
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, key === "past" && configs !== null && configs !== void 0 && configs.shortcuts && key in configs.shortcuts && subItem.daysNumber ? callPastFunction(configs.shortcuts[key], subItem.daysNumber) : subItem.text));
|
|
1393
|
+
}) : /*#__PURE__*/React.createElement(ItemTemplate, {
|
|
1394
|
+
key: index,
|
|
1395
|
+
item: item
|
|
1396
|
+
}, /*#__PURE__*/React.createElement(React.Fragment, null, configs !== null && configs !== void 0 && configs.shortcuts && key in configs.shortcuts ? _typeof(configs.shortcuts[key]) === "object" ? printItemText(item) : configs.shortcuts[key] : printItemText(item)));
|
|
1397
|
+
})));
|
|
1398
|
+
};
|
|
1399
|
+
|
|
1400
|
+
/**
|
|
1401
|
+
* Hook that alerts clicks outside of the passed ref
|
|
1402
|
+
*
|
|
1403
|
+
* @param {import("react").RefObject} ref
|
|
1404
|
+
* @param {(e?: MouseEvent | TouchEvent) => void} handler
|
|
1405
|
+
*/
|
|
1406
|
+
function useOnClickOutside(ref, handler) {
|
|
1407
|
+
React.useEffect(function () {
|
|
1408
|
+
var listener = function listener(event) {
|
|
1409
|
+
if (!ref.current || ref.current.contains(event.target)) {
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
handler(event);
|
|
1413
|
+
};
|
|
1414
|
+
document.addEventListener("mousedown", listener);
|
|
1415
|
+
document.addEventListener("touchstart", listener);
|
|
1416
|
+
return function () {
|
|
1417
|
+
document.removeEventListener("mousedown", listener);
|
|
1418
|
+
document.removeEventListener("touchstart", listener);
|
|
1419
|
+
};
|
|
1420
|
+
}, [ref, handler]);
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
/**
|
|
1424
|
+
* kz-react-datepicker
|
|
1425
|
+
*
|
|
1426
|
+
* @param {Object} props
|
|
1427
|
+
* @param {import("./DatepickerContext").DateValueType|null} [props.value] - The selected date(s).
|
|
1428
|
+
* @param {(value: import("./DatepickerContext").DateValueType, e?: HTMLInputElement | null) => void} props.onChange - onChange callback.
|
|
1429
|
+
* @param {boolean} [props.useRange=true] - Whether to show two calendars for start and end dates.
|
|
1430
|
+
* @param {boolean} [props.asSingle=false] - If true, only a single date is selected.
|
|
1431
|
+
* @param {string} [props.placeholder] - Input placeholder.
|
|
1432
|
+
* @param {boolean} [props.disabled=false] - Disables the input.
|
|
1433
|
+
* @param {boolean} [props.readOnly=false] - Makes the input read-only.
|
|
1434
|
+
* @param {string} [props.displayFormat] - The display format for the input, defaults to YYYY-MM-DD.
|
|
1435
|
+
* @param {Date|string|null} [props.minDate=null] - Minimum selectable date.
|
|
1436
|
+
* @param {Date|string|null} [props.maxDate=null] - Maximum selectable date.
|
|
1437
|
+
* @param {string} [props.primaryColor="blue"] - Theme color.
|
|
1438
|
+
* @param {string} [props.separator="~"] - Separator between start and end date in input.
|
|
1439
|
+
* @param {string|null} [props.startFrom=null] - Date to open the calendar at.
|
|
1440
|
+
* @param {string} [props.i18n] - i18n locale, e.g., 'en'.
|
|
1441
|
+
* @param {boolean} [props.showFooter=false] - Show Action/Footer buttons.
|
|
1442
|
+
* @param {boolean} [props.showShortcuts=false] - Show quick shortcuts.
|
|
1443
|
+
* @param {string|null} [props.shortcutText] - Label for shortcut button input adornment.
|
|
1444
|
+
* @param {Object} [props.configs] - Additional configurations.
|
|
1445
|
+
* @param {((className: string) => string)|string|null} [props.inputClassName] - Custom input classes.
|
|
1446
|
+
* @param {((className: string) => string)|string|null} [props.containerClassName] - Custom wrapper classes.
|
|
1447
|
+
* @param {((className: string) => string)|string|null} [props.toggleClassName] - Toggle button classes.
|
|
1448
|
+
* @param {(open: boolean) => import("react").ReactNode} [props.toggleIcon] - Custom toggle icon.
|
|
1449
|
+
* @param {"forward"|"backward"|"middle"} [props.dateLooking="forward"] - Date looking direction for missing ranges.
|
|
1450
|
+
* @param {Array<{start: Date|string, end: Date|string}>|null} [props.disabledDates=null] - Dates to disable.
|
|
1451
|
+
* @param {string} [props.inputId] - ID for the input field.
|
|
1452
|
+
* @param {string} [props.inputName] - Name for the input field.
|
|
1453
|
+
* @param {string} [props.startWeekOn="sun"] - Day the week starts on.
|
|
1454
|
+
* @param {Object} [props.classNames] - Custom classes for different sub-components.
|
|
1455
|
+
* @param {string} [props.popoverDirection] - Popover direction.
|
|
1456
|
+
* @param {string} [props.suffix] - Suffix for classnames.
|
|
1457
|
+
* @param {"auto"|"light"|"dark"} [props.theme="auto"] - Color theme of the datepicker, defaults to system preferences (auto).
|
|
1458
|
+
* @param {"bottom"|"top"|"left"|"right"|"auto"} [props.placement="bottom"] - Where the datepicker calendar opens relative to input.
|
|
1459
|
+
*/
|
|
1460
|
+
var Datepicker = function Datepicker(_ref) {
|
|
1461
|
+
var _ref$primaryColor = _ref.primaryColor,
|
|
1462
|
+
primaryColor = _ref$primaryColor === void 0 ? "blue" : _ref$primaryColor,
|
|
1463
|
+
_ref$value = _ref.value,
|
|
1464
|
+
value = _ref$value === void 0 ? null : _ref$value,
|
|
1465
|
+
onChange = _ref.onChange,
|
|
1466
|
+
_ref$useRange = _ref.useRange,
|
|
1467
|
+
useRange = _ref$useRange === void 0 ? true : _ref$useRange,
|
|
1468
|
+
_ref$showFooter = _ref.showFooter,
|
|
1469
|
+
showFooter = _ref$showFooter === void 0 ? false : _ref$showFooter,
|
|
1470
|
+
_ref$showShortcuts = _ref.showShortcuts,
|
|
1471
|
+
showShortcuts = _ref$showShortcuts === void 0 ? false : _ref$showShortcuts,
|
|
1472
|
+
_ref$configs = _ref.configs,
|
|
1473
|
+
configs = _ref$configs === void 0 ? undefined : _ref$configs,
|
|
1474
|
+
_ref$asSingle = _ref.asSingle,
|
|
1475
|
+
asSingle = _ref$asSingle === void 0 ? false : _ref$asSingle,
|
|
1476
|
+
_ref$placeholder = _ref.placeholder,
|
|
1477
|
+
placeholder = _ref$placeholder === void 0 ? null : _ref$placeholder,
|
|
1478
|
+
_ref$separator = _ref.separator,
|
|
1479
|
+
separator = _ref$separator === void 0 ? "~" : _ref$separator,
|
|
1480
|
+
_ref$startFrom = _ref.startFrom,
|
|
1481
|
+
startFrom = _ref$startFrom === void 0 ? null : _ref$startFrom,
|
|
1482
|
+
_ref$i18n = _ref.i18n,
|
|
1483
|
+
i18n = _ref$i18n === void 0 ? LANGUAGE : _ref$i18n,
|
|
1484
|
+
_ref$disabled = _ref.disabled,
|
|
1485
|
+
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
1486
|
+
_ref$inputClassName = _ref.inputClassName,
|
|
1487
|
+
inputClassName = _ref$inputClassName === void 0 ? null : _ref$inputClassName,
|
|
1488
|
+
_ref$containerClassNa = _ref.containerClassName,
|
|
1489
|
+
containerClassName = _ref$containerClassNa === void 0 ? null : _ref$containerClassNa,
|
|
1490
|
+
_ref$toggleClassName = _ref.toggleClassName,
|
|
1491
|
+
toggleClassName = _ref$toggleClassName === void 0 ? null : _ref$toggleClassName,
|
|
1492
|
+
_ref$toggleIcon = _ref.toggleIcon,
|
|
1493
|
+
toggleIcon = _ref$toggleIcon === void 0 ? undefined : _ref$toggleIcon,
|
|
1494
|
+
_ref$shortcutText = _ref.shortcutText,
|
|
1495
|
+
shortcutText = _ref$shortcutText === void 0 ? null : _ref$shortcutText,
|
|
1496
|
+
_ref$displayFormat = _ref.displayFormat,
|
|
1497
|
+
displayFormat = _ref$displayFormat === void 0 ? DATE_FORMAT : _ref$displayFormat,
|
|
1498
|
+
_ref$readOnly = _ref.readOnly,
|
|
1499
|
+
readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
|
|
1500
|
+
_ref$minDate = _ref.minDate,
|
|
1501
|
+
minDate = _ref$minDate === void 0 ? null : _ref$minDate,
|
|
1502
|
+
_ref$maxDate = _ref.maxDate,
|
|
1503
|
+
maxDate = _ref$maxDate === void 0 ? null : _ref$maxDate,
|
|
1504
|
+
_ref$dateLooking = _ref.dateLooking,
|
|
1505
|
+
dateLooking = _ref$dateLooking === void 0 ? "forward" : _ref$dateLooking,
|
|
1506
|
+
_ref$disabledDates = _ref.disabledDates,
|
|
1507
|
+
disabledDates = _ref$disabledDates === void 0 ? null : _ref$disabledDates,
|
|
1508
|
+
inputId = _ref.inputId,
|
|
1509
|
+
inputName = _ref.inputName,
|
|
1510
|
+
_ref$startWeekOn = _ref.startWeekOn,
|
|
1511
|
+
startWeekOn = _ref$startWeekOn === void 0 ? "sun" : _ref$startWeekOn,
|
|
1512
|
+
_ref$classNames = _ref.classNames,
|
|
1513
|
+
classNames = _ref$classNames === void 0 ? undefined : _ref$classNames,
|
|
1514
|
+
_ref$popoverDirection = _ref.popoverDirection,
|
|
1515
|
+
popoverDirection = _ref$popoverDirection === void 0 ? undefined : _ref$popoverDirection,
|
|
1516
|
+
_ref$suffix = _ref.suffix,
|
|
1517
|
+
suffix = _ref$suffix === void 0 ? "" : _ref$suffix,
|
|
1518
|
+
_ref$theme = _ref.theme,
|
|
1519
|
+
theme = _ref$theme === void 0 ? "auto" : _ref$theme,
|
|
1520
|
+
_ref$placement = _ref.placement,
|
|
1521
|
+
placement = _ref$placement === void 0 ? "bottom" : _ref$placement;
|
|
1522
|
+
var containerRef = React.useRef(null);
|
|
1523
|
+
var calendarContainerRef = React.useRef(null);
|
|
1524
|
+
var arrowRef = React.useRef(null);
|
|
1525
|
+
var getInitialFirstDate = function getInitialFirstDate() {
|
|
1526
|
+
if (value !== null && value !== void 0 && value.startDate && dateIsValid(parseDate(value.startDate))) {
|
|
1527
|
+
return parseDate(value.startDate);
|
|
1528
|
+
}
|
|
1529
|
+
if (startFrom && dateIsValid(parseDate(startFrom))) {
|
|
1530
|
+
return parseDate(startFrom);
|
|
1531
|
+
}
|
|
1532
|
+
return new Date();
|
|
1533
|
+
};
|
|
1534
|
+
var _useState = React.useState(getInitialFirstDate()),
|
|
1535
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
1536
|
+
firstDate = _useState2[0],
|
|
1537
|
+
setFirstDate = _useState2[1];
|
|
1538
|
+
var _useState3 = React.useState(nextMonth(getInitialFirstDate())),
|
|
1539
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
1540
|
+
secondDate = _useState4[0],
|
|
1541
|
+
setSecondDate = _useState4[1];
|
|
1542
|
+
var _useState5 = React.useState(function () {
|
|
1543
|
+
return typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
1544
|
+
}),
|
|
1545
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
1546
|
+
systemTheme = _useState6[0],
|
|
1547
|
+
setSystemTheme = _useState6[1];
|
|
1548
|
+
React.useEffect(function () {
|
|
1549
|
+
if (theme === "auto" && typeof window !== "undefined" && window.matchMedia) {
|
|
1550
|
+
var mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
1551
|
+
var handleChange = function handleChange(e) {
|
|
1552
|
+
return setSystemTheme(e.matches ? "dark" : "light");
|
|
1553
|
+
};
|
|
1554
|
+
mediaQuery.addEventListener("change", handleChange);
|
|
1555
|
+
return function () {
|
|
1556
|
+
return mediaQuery.removeEventListener("change", handleChange);
|
|
1557
|
+
};
|
|
1558
|
+
}
|
|
1559
|
+
}, [theme]);
|
|
1560
|
+
var activeTheme = theme === "auto" ? systemTheme : theme;
|
|
1561
|
+
var _useState7 = React.useState({
|
|
1562
|
+
start: null,
|
|
1563
|
+
end: null
|
|
1564
|
+
}),
|
|
1565
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
1566
|
+
period = _useState8[0],
|
|
1567
|
+
setPeriod = _useState8[1];
|
|
1568
|
+
var _useState9 = React.useState(null),
|
|
1569
|
+
_useState0 = _slicedToArray(_useState9, 2),
|
|
1570
|
+
dayHover = _useState0[0],
|
|
1571
|
+
setDayHover = _useState0[1];
|
|
1572
|
+
var _useState1 = React.useState(""),
|
|
1573
|
+
_useState10 = _slicedToArray(_useState1, 2),
|
|
1574
|
+
inputText = _useState10[0],
|
|
1575
|
+
setInputText = _useState10[1];
|
|
1576
|
+
var _useState11 = React.useState(/*#__PURE__*/React.createRef()),
|
|
1577
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
1578
|
+
inputRef = _useState12[0],
|
|
1579
|
+
setInputRef = _useState12[1];
|
|
1580
|
+
useOnClickOutside(containerRef, function () {
|
|
1581
|
+
var container = containerRef.current;
|
|
1582
|
+
var div = calendarContainerRef.current;
|
|
1583
|
+
var openBaseClass = "kz-datepicker-open";
|
|
1584
|
+
var openModifierClass = suffix ? "kz-datepicker-open--".concat(suffix) : "";
|
|
1585
|
+
if (container && div && (div.classList.contains(openBaseClass) || openModifierClass && div.classList.contains(openModifierClass))) {
|
|
1586
|
+
onChange(_objectSpread2({
|
|
1587
|
+
endDate: null,
|
|
1588
|
+
startDate: null
|
|
1589
|
+
}, value));
|
|
1590
|
+
hideDatepicker();
|
|
1591
|
+
}
|
|
1592
|
+
});
|
|
1593
|
+
var hideDatepicker = React.useCallback(function () {
|
|
1594
|
+
var div = calendarContainerRef.current;
|
|
1595
|
+
var openBaseClass = "kz-datepicker-open";
|
|
1596
|
+
var openModifierClass = suffix ? "kz-datepicker-open--".concat(suffix) : "";
|
|
1597
|
+
var closeBaseClass = "kz-datepicker-close";
|
|
1598
|
+
var closeModifierClass = suffix ? "kz-datepicker-close--".concat(suffix) : "";
|
|
1599
|
+
if (div && (div.classList.contains(openBaseClass) || openModifierClass && div.classList.contains(openModifierClass))) {
|
|
1600
|
+
div.classList.remove(openBaseClass);
|
|
1601
|
+
if (openModifierClass) div.classList.remove(openModifierClass);
|
|
1602
|
+
div.classList.add(closeBaseClass);
|
|
1603
|
+
if (closeModifierClass) div.classList.add(closeModifierClass);
|
|
1604
|
+
setTimeout(function () {
|
|
1605
|
+
div.style.display = "none";
|
|
1606
|
+
div.classList.remove(closeBaseClass);
|
|
1607
|
+
if (closeModifierClass) div.classList.remove(closeModifierClass);
|
|
1608
|
+
}, 300);
|
|
1609
|
+
}
|
|
1610
|
+
}, [suffix]);
|
|
1611
|
+
var firstGotoDate = React.useCallback(function (date) {
|
|
1612
|
+
var newDate = parseDate(formatDate(date));
|
|
1613
|
+
var reformatDate = parseDate(formatDate(secondDate));
|
|
1614
|
+
if (newDate.getTime() >= reformatDate.getTime()) {
|
|
1615
|
+
setSecondDate(nextMonth(date));
|
|
1616
|
+
}
|
|
1617
|
+
setFirstDate(date);
|
|
1618
|
+
}, [secondDate]);
|
|
1619
|
+
var previousMonthFirst = React.useCallback(function () {
|
|
1620
|
+
return setFirstDate(previousMonth(firstDate));
|
|
1621
|
+
}, [firstDate]);
|
|
1622
|
+
var nextMonthFirst = React.useCallback(function () {
|
|
1623
|
+
return firstGotoDate(nextMonth(firstDate));
|
|
1624
|
+
}, [firstDate, firstGotoDate]);
|
|
1625
|
+
var changeFirstMonth = React.useCallback(function (month) {
|
|
1626
|
+
firstGotoDate(new Date(firstDate.getFullYear(), month - 1, 1));
|
|
1627
|
+
}, [firstDate, firstGotoDate]);
|
|
1628
|
+
var changeFirstYear = React.useCallback(function (year) {
|
|
1629
|
+
firstGotoDate(new Date(year, firstDate.getMonth(), 1));
|
|
1630
|
+
}, [firstDate, firstGotoDate]);
|
|
1631
|
+
var secondGotoDate = React.useCallback(function (date) {
|
|
1632
|
+
var newDate = parseDate(formatDate(date, displayFormat));
|
|
1633
|
+
var reformatDate = parseDate(formatDate(firstDate, displayFormat));
|
|
1634
|
+
if (newDate.getTime() <= reformatDate.getTime()) {
|
|
1635
|
+
setFirstDate(previousMonth(date));
|
|
1636
|
+
}
|
|
1637
|
+
setSecondDate(date);
|
|
1638
|
+
}, [firstDate, displayFormat]);
|
|
1639
|
+
var previousMonthSecond = React.useCallback(function () {
|
|
1640
|
+
return secondGotoDate(previousMonth(secondDate));
|
|
1641
|
+
}, [secondDate, secondGotoDate]);
|
|
1642
|
+
var nextMonthSecond = React.useCallback(function () {
|
|
1643
|
+
return setSecondDate(nextMonth(secondDate));
|
|
1644
|
+
}, [secondDate]);
|
|
1645
|
+
var changeSecondMonth = React.useCallback(function (month) {
|
|
1646
|
+
secondGotoDate(new Date(secondDate.getFullYear(), month - 1, 1));
|
|
1647
|
+
}, [secondDate, secondGotoDate]);
|
|
1648
|
+
var changeSecondYear = React.useCallback(function (year) {
|
|
1649
|
+
secondGotoDate(new Date(year, secondDate.getMonth(), 1));
|
|
1650
|
+
}, [secondDate, secondGotoDate]);
|
|
1651
|
+
React.useEffect(function () {
|
|
1652
|
+
if (value && value.startDate && value.endDate) {
|
|
1653
|
+
var startDate = parseDate(value.startDate);
|
|
1654
|
+
var endDate = parseDate(value.endDate);
|
|
1655
|
+
var validDate = dateIsValid(startDate) && dateIsValid(endDate);
|
|
1656
|
+
var condition = validDate && startDate.getTime() <= endDate.getTime();
|
|
1657
|
+
if (condition) {
|
|
1658
|
+
setPeriod({
|
|
1659
|
+
start: formatDate(startDate),
|
|
1660
|
+
end: formatDate(endDate)
|
|
1661
|
+
});
|
|
1662
|
+
setInputText("".concat(formatDate(startDate, displayFormat)).concat(asSingle ? "" : " ".concat(separator, " ").concat(formatDate(endDate, displayFormat))));
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
if (value && value.startDate === null && value.endDate === null) {
|
|
1666
|
+
setPeriod({
|
|
1667
|
+
start: null,
|
|
1668
|
+
end: null
|
|
1669
|
+
});
|
|
1670
|
+
setInputText("");
|
|
1671
|
+
}
|
|
1672
|
+
}, [asSingle, value, displayFormat, separator]);
|
|
1673
|
+
React.useEffect(function () {
|
|
1674
|
+
if (startFrom && dateIsValid(parseDate(startFrom))) {
|
|
1675
|
+
var startDate = value === null || value === void 0 ? void 0 : value.startDate;
|
|
1676
|
+
var endDate = value === null || value === void 0 ? void 0 : value.endDate;
|
|
1677
|
+
if (startDate && dateIsValid(parseDate(startDate))) {
|
|
1678
|
+
setFirstDate(parseDate(startDate));
|
|
1679
|
+
if (!asSingle) {
|
|
1680
|
+
if (endDate && dateIsValid(parseDate(endDate))) {
|
|
1681
|
+
var parsedEnd = parseDate(endDate);
|
|
1682
|
+
var startMonthEnd = new Date(parseDate(startDate).getFullYear(), parseDate(startDate).getMonth() + 1, 0, 23, 59, 59);
|
|
1683
|
+
if (parsedEnd.getTime() > startMonthEnd.getTime()) {
|
|
1684
|
+
setSecondDate(parsedEnd);
|
|
1685
|
+
} else {
|
|
1686
|
+
setSecondDate(nextMonth(parseDate(startDate)));
|
|
1687
|
+
}
|
|
1688
|
+
} else {
|
|
1689
|
+
setSecondDate(nextMonth(parseDate(startDate)));
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
} else {
|
|
1693
|
+
setFirstDate(parseDate(startFrom));
|
|
1694
|
+
setSecondDate(nextMonth(parseDate(startFrom)));
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
}, [asSingle, startFrom, value]);
|
|
1698
|
+
var safePrimaryColor = React.useMemo(function () {
|
|
1699
|
+
return COLORS.includes(primaryColor) ? primaryColor : DEFAULT_COLOR;
|
|
1700
|
+
}, [primaryColor]);
|
|
1701
|
+
var contextValues = React.useMemo(function () {
|
|
1702
|
+
return {
|
|
1703
|
+
asSingle: asSingle,
|
|
1704
|
+
primaryColor: safePrimaryColor,
|
|
1705
|
+
configs: configs,
|
|
1706
|
+
calendarContainer: calendarContainerRef,
|
|
1707
|
+
arrowContainer: arrowRef,
|
|
1708
|
+
hideDatepicker: hideDatepicker,
|
|
1709
|
+
period: period,
|
|
1710
|
+
changePeriod: setPeriod,
|
|
1711
|
+
dayHover: dayHover,
|
|
1712
|
+
changeDayHover: setDayHover,
|
|
1713
|
+
inputText: inputText,
|
|
1714
|
+
changeInputText: setInputText,
|
|
1715
|
+
updateFirstDate: firstGotoDate,
|
|
1716
|
+
changeDatepickerValue: onChange,
|
|
1717
|
+
showFooter: showFooter,
|
|
1718
|
+
placeholder: placeholder,
|
|
1719
|
+
separator: separator,
|
|
1720
|
+
shortcutText: shortcutText,
|
|
1721
|
+
i18n: i18n,
|
|
1722
|
+
value: value,
|
|
1723
|
+
disabled: disabled,
|
|
1724
|
+
inputClassName: inputClassName,
|
|
1725
|
+
containerClassName: containerClassName,
|
|
1726
|
+
toggleClassName: toggleClassName,
|
|
1727
|
+
toggleIcon: toggleIcon,
|
|
1728
|
+
readOnly: readOnly,
|
|
1729
|
+
displayFormat: displayFormat,
|
|
1730
|
+
minDate: minDate,
|
|
1731
|
+
maxDate: maxDate,
|
|
1732
|
+
dateLooking: dateLooking,
|
|
1733
|
+
disabledDates: disabledDates,
|
|
1734
|
+
inputId: inputId,
|
|
1735
|
+
inputName: inputName,
|
|
1736
|
+
startWeekOn: startWeekOn,
|
|
1737
|
+
classNames: classNames,
|
|
1738
|
+
onChange: onChange,
|
|
1739
|
+
input: inputRef,
|
|
1740
|
+
popoverDirection: popoverDirection,
|
|
1741
|
+
suffix: suffix,
|
|
1742
|
+
theme: activeTheme,
|
|
1743
|
+
placement: placement
|
|
1744
|
+
};
|
|
1745
|
+
}, [asSingle, safePrimaryColor, configs, hideDatepicker, period, dayHover, inputText, onChange, showFooter, placeholder, separator, shortcutText, i18n, value, disabled, inputClassName, containerClassName, toggleClassName, toggleIcon, readOnly, displayFormat, minDate, maxDate, dateLooking, disabledDates, inputId, inputName, startWeekOn, classNames, inputRef, popoverDirection, firstGotoDate, suffix, activeTheme, placement]);
|
|
1746
|
+
var containerClassNameOverload = React.useMemo(function () {
|
|
1747
|
+
var defaultClassName = "kz-datepicker-container" + (suffix ? " kz-datepicker-container--".concat(suffix) : "");
|
|
1748
|
+
if (activeTheme === "dark") {
|
|
1749
|
+
defaultClassName += " dark";
|
|
1750
|
+
}
|
|
1751
|
+
return typeof containerClassName === "function" ? containerClassName(defaultClassName) : typeof containerClassName === "string" && containerClassName !== "" ? containerClassName + (activeTheme === "dark" && !containerClassName.includes("dark") ? " dark" : "") : defaultClassName;
|
|
1752
|
+
}, [containerClassName, suffix, activeTheme]);
|
|
1753
|
+
return /*#__PURE__*/React.createElement(DatepickerContext.Provider, {
|
|
1754
|
+
value: contextValues
|
|
1755
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1756
|
+
className: containerClassNameOverload,
|
|
1757
|
+
ref: containerRef
|
|
1758
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
1759
|
+
setContextRef: setInputRef
|
|
1760
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
1761
|
+
className: "kz-datepicker-popup" + (suffix ? " kz-datepicker-popup--".concat(suffix) : ""),
|
|
1762
|
+
ref: calendarContainerRef,
|
|
1763
|
+
style: {
|
|
1764
|
+
display: "none"
|
|
1765
|
+
}
|
|
1766
|
+
}, /*#__PURE__*/React.createElement(Arrow, {
|
|
1767
|
+
ref: arrowRef
|
|
1768
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
1769
|
+
className: "kz-datepicker-popup-inner" + (suffix ? " kz-datepicker-popup-inner--".concat(suffix) : "")
|
|
1770
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
1771
|
+
className: "kz-datepicker-main-content" + (suffix ? " kz-datepicker-main-content--".concat(suffix) : "")
|
|
1772
|
+
}, showShortcuts && /*#__PURE__*/React.createElement(Shortcuts, null), /*#__PURE__*/React.createElement("div", {
|
|
1773
|
+
className: "kz-datepicker-calendars".concat(suffix ? " kz-datepicker-calendars--".concat(suffix) : "", " ").concat(showShortcuts ? "kz-has-shortcuts" + (suffix ? " kz-has-shortcuts--".concat(suffix) : "") : "")
|
|
1774
|
+
}, /*#__PURE__*/React.createElement(Calendar, {
|
|
1775
|
+
date: firstDate,
|
|
1776
|
+
onClickPrevious: previousMonthFirst,
|
|
1777
|
+
onClickNext: nextMonthFirst,
|
|
1778
|
+
changeMonth: changeFirstMonth,
|
|
1779
|
+
changeYear: changeFirstYear,
|
|
1780
|
+
minDate: minDate,
|
|
1781
|
+
maxDate: maxDate
|
|
1782
|
+
}), useRange && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
1783
|
+
className: "kz-datepicker-divider-wrapper" + (suffix ? " kz-datepicker-divider-wrapper--".concat(suffix) : "")
|
|
1784
|
+
}, /*#__PURE__*/React.createElement(VerticalDash, null)), /*#__PURE__*/React.createElement(Calendar, {
|
|
1785
|
+
date: secondDate,
|
|
1786
|
+
onClickPrevious: previousMonthSecond,
|
|
1787
|
+
onClickNext: nextMonthSecond,
|
|
1788
|
+
changeMonth: changeSecondMonth,
|
|
1789
|
+
changeYear: changeSecondYear,
|
|
1790
|
+
minDate: minDate,
|
|
1791
|
+
maxDate: maxDate
|
|
1792
|
+
})))), showFooter && /*#__PURE__*/React.createElement(Footer, null)))));
|
|
1793
|
+
};
|
|
1794
|
+
|
|
1795
|
+
module.exports = Datepicker;
|
|
1796
|
+
//# sourceMappingURL=index.cjs.js.map
|