clayui-date-picker 3.165.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/LICENSE.md +30 -0
- package/README.md +19 -0
- package/lib/cjs/DateNavigation.js +124 -0
- package/lib/cjs/DayNumber.js +116 -0
- package/lib/cjs/DaysTable.js +49 -0
- package/lib/cjs/Helpers.js +98 -0
- package/lib/cjs/Hooks.js +298 -0
- package/lib/cjs/InputDate.js +58 -0
- package/lib/cjs/Select.js +56 -0
- package/lib/cjs/TimePicker.js +82 -0
- package/lib/cjs/Weekday.js +38 -0
- package/lib/cjs/WeekdayHeader.js +57 -0
- package/lib/cjs/index.js +705 -0
- package/lib/cjs/types.js +33 -0
- package/lib/esm/DateNavigation.js +94 -0
- package/lib/esm/DayNumber.js +86 -0
- package/lib/esm/DaysTable.js +19 -0
- package/lib/esm/Helpers.js +68 -0
- package/lib/esm/Hooks.js +278 -0
- package/lib/esm/InputDate.js +28 -0
- package/lib/esm/Select.js +26 -0
- package/lib/esm/TimePicker.js +52 -0
- package/lib/esm/Weekday.js +8 -0
- package/lib/esm/WeekdayHeader.js +27 -0
- package/lib/esm/index.js +697 -0
- package/lib/esm/types.js +13 -0
- package/package.json +51 -0
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,705 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var index_exports = {};
|
|
30
|
+
__export(index_exports, {
|
|
31
|
+
FirstDayOfWeek: () => FirstDayOfWeek,
|
|
32
|
+
default: () => index_default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(index_exports);
|
|
35
|
+
var import_button = __toESM(require("@clayui/button"));
|
|
36
|
+
var import_core = require("@clayui/core");
|
|
37
|
+
var import_drop_down = __toESM(require("@clayui/drop-down"));
|
|
38
|
+
var import_form = require("@clayui/form");
|
|
39
|
+
var import_icon = __toESM(require("@clayui/icon"));
|
|
40
|
+
var import_shared = require("@clayui/shared");
|
|
41
|
+
var import_react = __toESM(require("react"));
|
|
42
|
+
var import_DateNavigation = __toESM(require("./DateNavigation"));
|
|
43
|
+
var import_DayNumber = __toESM(require("./DayNumber"));
|
|
44
|
+
var import_DaysTable = __toESM(require("./DaysTable"));
|
|
45
|
+
var import_Helpers = require("./Helpers");
|
|
46
|
+
var import_Hooks = require("./Hooks");
|
|
47
|
+
var import_InputDate = __toESM(require("./InputDate"));
|
|
48
|
+
var import_TimePicker = __toESM(require("./TimePicker"));
|
|
49
|
+
var import_Weekday = __toESM(require("./Weekday"));
|
|
50
|
+
var import_WeekdayHeader = __toESM(require("./WeekdayHeader"));
|
|
51
|
+
var FirstDayOfWeek = /* @__PURE__ */ ((FirstDayOfWeek2) => {
|
|
52
|
+
FirstDayOfWeek2[FirstDayOfWeek2["Sunday"] = 0] = "Sunday";
|
|
53
|
+
FirstDayOfWeek2[FirstDayOfWeek2["Monday"] = 1] = "Monday";
|
|
54
|
+
FirstDayOfWeek2[FirstDayOfWeek2["Tuesday"] = 2] = "Tuesday";
|
|
55
|
+
FirstDayOfWeek2[FirstDayOfWeek2["Wednesday"] = 3] = "Wednesday";
|
|
56
|
+
FirstDayOfWeek2[FirstDayOfWeek2["Thursday"] = 4] = "Thursday";
|
|
57
|
+
FirstDayOfWeek2[FirstDayOfWeek2["Friday"] = 5] = "Friday";
|
|
58
|
+
FirstDayOfWeek2[FirstDayOfWeek2["Saturday"] = 6] = "Saturday";
|
|
59
|
+
return FirstDayOfWeek2;
|
|
60
|
+
})(FirstDayOfWeek || {});
|
|
61
|
+
const DEFAULT_DATE_TIME = {
|
|
62
|
+
hours: 12,
|
|
63
|
+
milliseconds: 0,
|
|
64
|
+
minutes: 0,
|
|
65
|
+
seconds: 0
|
|
66
|
+
};
|
|
67
|
+
const NEW_DATE = /* @__PURE__ */ new Date();
|
|
68
|
+
const TIME_FORMAT = "HH:mm";
|
|
69
|
+
const TIME_FORMAT_12H = "hh:mm aa";
|
|
70
|
+
function normalizeTime(date) {
|
|
71
|
+
return (0, import_Helpers.setDate)(date, { hours: 12, milliseconds: 0, minutes: 0, seconds: 0 });
|
|
72
|
+
}
|
|
73
|
+
const DatePicker = import_react.default.forwardRef(
|
|
74
|
+
({
|
|
75
|
+
ariaLabels = {
|
|
76
|
+
buttonChooseDate: "Choose date",
|
|
77
|
+
buttonDot: "Select current date",
|
|
78
|
+
buttonNextMonth: "Select the next month",
|
|
79
|
+
buttonPreviousMonth: "Select the previous month",
|
|
80
|
+
chooseDate: "Use the calendar to choose a Date. Current selection {0}",
|
|
81
|
+
dialog: "Choose date",
|
|
82
|
+
openCalendar: "Open Calendar Picker",
|
|
83
|
+
outOfRange: "The entered value is outside the allowed range and was not applied",
|
|
84
|
+
selectMonth: "Select a month",
|
|
85
|
+
selectYear: "Select a year"
|
|
86
|
+
},
|
|
87
|
+
dateFormat = "yyyy-MM-dd",
|
|
88
|
+
defaultExpanded,
|
|
89
|
+
defaultMonth,
|
|
90
|
+
defaultValue,
|
|
91
|
+
disabled,
|
|
92
|
+
displayKeyboardArrowsIndicator = false,
|
|
93
|
+
expanded,
|
|
94
|
+
firstDayOfWeek = 0,
|
|
95
|
+
footerElement,
|
|
96
|
+
id,
|
|
97
|
+
initialExpanded = false,
|
|
98
|
+
initialMonth,
|
|
99
|
+
inputName,
|
|
100
|
+
max,
|
|
101
|
+
min,
|
|
102
|
+
months = [
|
|
103
|
+
"January",
|
|
104
|
+
"February",
|
|
105
|
+
"March",
|
|
106
|
+
"April",
|
|
107
|
+
"May",
|
|
108
|
+
"June",
|
|
109
|
+
"July",
|
|
110
|
+
"August",
|
|
111
|
+
"September",
|
|
112
|
+
"October",
|
|
113
|
+
"November",
|
|
114
|
+
"December"
|
|
115
|
+
],
|
|
116
|
+
onChange,
|
|
117
|
+
onExpandedChange,
|
|
118
|
+
onNavigation = () => {
|
|
119
|
+
},
|
|
120
|
+
onValueChange,
|
|
121
|
+
placeholder,
|
|
122
|
+
range,
|
|
123
|
+
spritemap,
|
|
124
|
+
time = false,
|
|
125
|
+
timezone,
|
|
126
|
+
use12Hours = false,
|
|
127
|
+
useNative = false,
|
|
128
|
+
value,
|
|
129
|
+
weekdaysShort = ["S", "M", "T", "W", "T", "F", "S"],
|
|
130
|
+
years = {
|
|
131
|
+
end: NEW_DATE.getFullYear(),
|
|
132
|
+
start: NEW_DATE.getFullYear()
|
|
133
|
+
},
|
|
134
|
+
yearsCheck = true,
|
|
135
|
+
...otherProps
|
|
136
|
+
}, ref) => {
|
|
137
|
+
const [parsedMin, parsedMax] = (0, import_react.useMemo)(() => {
|
|
138
|
+
const parseBound = (value2) => {
|
|
139
|
+
if (!value2) {
|
|
140
|
+
return void 0;
|
|
141
|
+
}
|
|
142
|
+
const parsed = (0, import_Helpers.parseDate)(
|
|
143
|
+
value2,
|
|
144
|
+
time ? `${dateFormat} ${use12Hours ? TIME_FORMAT_12H : TIME_FORMAT}` : dateFormat,
|
|
145
|
+
NEW_DATE
|
|
146
|
+
);
|
|
147
|
+
return (0, import_Helpers.isValid)(parsed) ? parsed : void 0;
|
|
148
|
+
};
|
|
149
|
+
const minDate = parseBound(min);
|
|
150
|
+
const maxDate = parseBound(max);
|
|
151
|
+
if (minDate && maxDate && !(0, import_Helpers.isBefore)(minDate, maxDate)) {
|
|
152
|
+
console.warn(
|
|
153
|
+
"ClayDatePicker: `min` must be earlier than `max`. Both bounds will be ignored."
|
|
154
|
+
);
|
|
155
|
+
return [void 0, void 0];
|
|
156
|
+
}
|
|
157
|
+
return [minDate, maxDate];
|
|
158
|
+
}, [min, max, dateFormat, time, use12Hours]);
|
|
159
|
+
const isDayDisabled = (0, import_react.useCallback)(
|
|
160
|
+
(date) => {
|
|
161
|
+
if (parsedMin && (0, import_Helpers.isBefore)(date, parsedMin) && !(0, import_Helpers.isSameDay)(date, parsedMin)) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
if (parsedMax && (0, import_Helpers.isAfter)(date, parsedMax) && !(0, import_Helpers.isSameDay)(date, parsedMax)) {
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
},
|
|
169
|
+
[parsedMin, parsedMax]
|
|
170
|
+
);
|
|
171
|
+
const isDateTimeOutOfRange = (0, import_react.useCallback)(
|
|
172
|
+
(date) => {
|
|
173
|
+
if (parsedMin && (0, import_Helpers.isBefore)(date, parsedMin)) {
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
if (parsedMax && (0, import_Helpers.isAfter)(date, parsedMax)) {
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
},
|
|
181
|
+
[parsedMin, parsedMax]
|
|
182
|
+
);
|
|
183
|
+
const getDefaultMonth = (0, import_react.useCallback)(
|
|
184
|
+
() => (0, import_Helpers.clamp)(
|
|
185
|
+
defaultMonth ?? initialMonth ?? /* @__PURE__ */ new Date(),
|
|
186
|
+
parsedMin,
|
|
187
|
+
parsedMax
|
|
188
|
+
),
|
|
189
|
+
[defaultMonth, initialMonth, parsedMin, parsedMax]
|
|
190
|
+
);
|
|
191
|
+
const [internalValue, setValue, isUncontrolled] = (0, import_shared.useControlledState)({
|
|
192
|
+
defaultName: "defaultValue",
|
|
193
|
+
defaultValue,
|
|
194
|
+
handleName: "onChange",
|
|
195
|
+
name: "value",
|
|
196
|
+
onChange: onChange ?? onValueChange,
|
|
197
|
+
value
|
|
198
|
+
});
|
|
199
|
+
const [daysSelected, setDaysSelected] = (0, import_Hooks.useDaysSelected)(() => {
|
|
200
|
+
if (internalValue) {
|
|
201
|
+
const days = hasDaysSelected({
|
|
202
|
+
checkRangeYears: yearsCheck,
|
|
203
|
+
dateFormat,
|
|
204
|
+
is12Hours: use12Hours,
|
|
205
|
+
isTime: time,
|
|
206
|
+
value: internalValue,
|
|
207
|
+
years
|
|
208
|
+
});
|
|
209
|
+
if (days) {
|
|
210
|
+
return [normalizeTime(days[0]), normalizeTime(days[1])];
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const date = normalizeTime(getDefaultMonth());
|
|
214
|
+
return [date, date];
|
|
215
|
+
});
|
|
216
|
+
const [currentMonth, setCurrentMonth] = (0, import_react.useState)(
|
|
217
|
+
() => (
|
|
218
|
+
// Normalize the date to always set noon to avoid time zone problems
|
|
219
|
+
// and to the 1st of the month.
|
|
220
|
+
(0, import_Helpers.setDate)(daysSelected[0], { date: 1, ...DEFAULT_DATE_TIME })
|
|
221
|
+
)
|
|
222
|
+
);
|
|
223
|
+
const chooseDateRef = (0, import_react.useRef)(null);
|
|
224
|
+
const [currentTime, setCurrentTime] = (0, import_Hooks.useCurrentTime)(() => {
|
|
225
|
+
if (time && internalValue) {
|
|
226
|
+
const [startDate] = fromStringToRange(
|
|
227
|
+
internalValue,
|
|
228
|
+
`${dateFormat} ${use12Hours ? TIME_FORMAT_12H : TIME_FORMAT}`,
|
|
229
|
+
NEW_DATE
|
|
230
|
+
);
|
|
231
|
+
if (startDate.toString() !== "Invalid Date") {
|
|
232
|
+
const hours = use12Hours ? (0, import_Helpers.formatDate)(startDate, "hh") : (0, import_Helpers.formatDate)(startDate, "HH");
|
|
233
|
+
const minutes = (0, import_Helpers.formatDate)(startDate, "mm");
|
|
234
|
+
return use12Hours ? `${hours}:${minutes} ${(0, import_Helpers.formatDate)(startDate, "a")}` : `${hours}:${minutes}`;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return "--:--";
|
|
238
|
+
}, use12Hours);
|
|
239
|
+
const [weeks, setWeeks] = (0, import_Hooks.useWeeks)(currentMonth, firstDayOfWeek);
|
|
240
|
+
const [expandedValue, setExpandedValue] = (0, import_shared.useControlledState)({
|
|
241
|
+
defaultName: "defaultExpanded",
|
|
242
|
+
defaultValue: defaultExpanded === void 0 ? initialExpanded : defaultExpanded,
|
|
243
|
+
handleName: "onExpandedChange",
|
|
244
|
+
name: "expanded",
|
|
245
|
+
onChange: onExpandedChange,
|
|
246
|
+
value: expanded
|
|
247
|
+
});
|
|
248
|
+
const triggerElementRef = (0, import_react.useRef)(null);
|
|
249
|
+
const liveRegionRef = (0, import_react.useRef)(null);
|
|
250
|
+
const announceOutOfRange = (0, import_react.useCallback)(() => {
|
|
251
|
+
const node = liveRegionRef.current;
|
|
252
|
+
if (!node || !ariaLabels.outOfRange) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
node.textContent = "";
|
|
256
|
+
node.textContent = ariaLabels.outOfRange;
|
|
257
|
+
}, [ariaLabels.outOfRange]);
|
|
258
|
+
const menuElementRef = (0, import_react.useRef)(null);
|
|
259
|
+
const changeMonth = (date) => {
|
|
260
|
+
const dateNormalized = (0, import_Helpers.setDate)(date, {
|
|
261
|
+
date: 1,
|
|
262
|
+
...DEFAULT_DATE_TIME
|
|
263
|
+
});
|
|
264
|
+
setCurrentMonth(dateNormalized);
|
|
265
|
+
onNavigation(dateNormalized);
|
|
266
|
+
if (!useNative) {
|
|
267
|
+
setWeeks(dateNormalized);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
const timePickerConfig = (0, import_react.useMemo)(() => {
|
|
271
|
+
if (!time || use12Hours || !parsedMin && !parsedMax) {
|
|
272
|
+
return void 0;
|
|
273
|
+
}
|
|
274
|
+
const [day] = daysSelected;
|
|
275
|
+
let hoursMin = 0;
|
|
276
|
+
let hoursMax = 23;
|
|
277
|
+
let minutesMin = 0;
|
|
278
|
+
let minutesMax = 59;
|
|
279
|
+
const currentHours = Number(currentTime.split(":")[0]);
|
|
280
|
+
if (parsedMin && (0, import_Helpers.isSameDay)(day, parsedMin)) {
|
|
281
|
+
hoursMin = parsedMin.getHours();
|
|
282
|
+
if (currentHours === hoursMin) {
|
|
283
|
+
minutesMin = parsedMin.getMinutes();
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (parsedMax && (0, import_Helpers.isSameDay)(day, parsedMax)) {
|
|
287
|
+
hoursMax = parsedMax.getHours();
|
|
288
|
+
if (currentHours === hoursMax) {
|
|
289
|
+
minutesMax = parsedMax.getMinutes();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
use12Hours: {
|
|
294
|
+
ampm: { am: "AM", pm: "PM" },
|
|
295
|
+
hours: { max: 12, min: 1 },
|
|
296
|
+
minutes: { max: 59, min: 0 }
|
|
297
|
+
},
|
|
298
|
+
use24Hours: {
|
|
299
|
+
ampm: { am: "AM", pm: "PM" },
|
|
300
|
+
hours: { max: hoursMax, min: hoursMin },
|
|
301
|
+
minutes: { max: minutesMax, min: minutesMin }
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
}, [time, use12Hours, daysSelected, currentTime, parsedMin, parsedMax]);
|
|
305
|
+
const memoizedYears = (0, import_react.useMemo)(
|
|
306
|
+
() => (0, import_Helpers.range)(years).map((elem) => {
|
|
307
|
+
return {
|
|
308
|
+
label: elem,
|
|
309
|
+
value: elem
|
|
310
|
+
};
|
|
311
|
+
}),
|
|
312
|
+
[years]
|
|
313
|
+
);
|
|
314
|
+
const memoizedMonths = (0, import_react.useMemo)(
|
|
315
|
+
() => months.map((month, index) => {
|
|
316
|
+
return {
|
|
317
|
+
label: month,
|
|
318
|
+
value: index
|
|
319
|
+
};
|
|
320
|
+
}),
|
|
321
|
+
[months]
|
|
322
|
+
);
|
|
323
|
+
const handleDayClicked = (date) => {
|
|
324
|
+
if (isDayDisabled(date)) {
|
|
325
|
+
announceOutOfRange();
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const [startDate, endDate] = daysSelected;
|
|
329
|
+
let newDaysSelected;
|
|
330
|
+
let daysSelectedToString;
|
|
331
|
+
if (range) {
|
|
332
|
+
if (startDate.toString() !== endDate.toString()) {
|
|
333
|
+
newDaysSelected = [date, date];
|
|
334
|
+
} else if (date < startDate) {
|
|
335
|
+
newDaysSelected = [date, endDate];
|
|
336
|
+
} else {
|
|
337
|
+
newDaysSelected = [startDate, date];
|
|
338
|
+
}
|
|
339
|
+
daysSelectedToString = fromRangeToString(
|
|
340
|
+
newDaysSelected,
|
|
341
|
+
dateFormat
|
|
342
|
+
);
|
|
343
|
+
const [newStartDate, newEndDate] = newDaysSelected;
|
|
344
|
+
if (newStartDate.getMonth() !== newEndDate.getMonth()) {
|
|
345
|
+
changeMonth(startDate);
|
|
346
|
+
}
|
|
347
|
+
} else {
|
|
348
|
+
newDaysSelected = [date, date];
|
|
349
|
+
daysSelectedToString = (0, import_Helpers.formatDate)(date, dateFormat);
|
|
350
|
+
if (time) {
|
|
351
|
+
daysSelectedToString = `${daysSelectedToString} ${currentTime}`;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
setDaysSelected(newDaysSelected);
|
|
355
|
+
setValue(daysSelectedToString);
|
|
356
|
+
};
|
|
357
|
+
const updateDate = (0, import_react.useCallback)(
|
|
358
|
+
(value2) => {
|
|
359
|
+
const currentDate = getDefaultMonth();
|
|
360
|
+
if (!value2) {
|
|
361
|
+
changeMonth(currentDate);
|
|
362
|
+
setDaysSelected([currentDate, currentDate]);
|
|
363
|
+
if (time) {
|
|
364
|
+
setCurrentTime(
|
|
365
|
+
"--",
|
|
366
|
+
"--",
|
|
367
|
+
use12Hours ? "--" : void 0
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
} else {
|
|
371
|
+
const days = hasDaysSelected({
|
|
372
|
+
checkRangeYears: yearsCheck,
|
|
373
|
+
dateFormat,
|
|
374
|
+
is12Hours: use12Hours,
|
|
375
|
+
isTime: time,
|
|
376
|
+
value: value2,
|
|
377
|
+
years
|
|
378
|
+
});
|
|
379
|
+
if (days) {
|
|
380
|
+
const [startDate, endDate] = days;
|
|
381
|
+
const referenceStart = time ? startDate : (0, import_Helpers.setDate)(startDate, {
|
|
382
|
+
hours: 12,
|
|
383
|
+
milliseconds: 0,
|
|
384
|
+
minutes: 0,
|
|
385
|
+
seconds: 0
|
|
386
|
+
});
|
|
387
|
+
const referenceEnd = time ? endDate : (0, import_Helpers.setDate)(endDate, {
|
|
388
|
+
hours: 12,
|
|
389
|
+
milliseconds: 0,
|
|
390
|
+
minutes: 0,
|
|
391
|
+
seconds: 0
|
|
392
|
+
});
|
|
393
|
+
const startOutOfRange = time ? isDateTimeOutOfRange(referenceStart) : isDayDisabled(referenceStart);
|
|
394
|
+
const endOutOfRange = time ? isDateTimeOutOfRange(referenceEnd) : isDayDisabled(referenceEnd);
|
|
395
|
+
if (startOutOfRange || endOutOfRange) {
|
|
396
|
+
announceOutOfRange();
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
if (time) {
|
|
400
|
+
setCurrentTime(
|
|
401
|
+
startDate.getHours(),
|
|
402
|
+
startDate.getMinutes(),
|
|
403
|
+
use12Hours ? (0, import_Helpers.formatDate)(
|
|
404
|
+
startDate,
|
|
405
|
+
"a"
|
|
406
|
+
) : void 0
|
|
407
|
+
);
|
|
408
|
+
} else {
|
|
409
|
+
changeMonth(startDate);
|
|
410
|
+
setDaysSelected([startDate, endDate]);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
[
|
|
416
|
+
dateFormat,
|
|
417
|
+
use12Hours,
|
|
418
|
+
time,
|
|
419
|
+
years,
|
|
420
|
+
yearsCheck,
|
|
421
|
+
isDayDisabled,
|
|
422
|
+
isDateTimeOutOfRange,
|
|
423
|
+
announceOutOfRange
|
|
424
|
+
]
|
|
425
|
+
);
|
|
426
|
+
const inputChange = (event) => {
|
|
427
|
+
const { value: value2 } = event.target;
|
|
428
|
+
updateDate(value2);
|
|
429
|
+
setValue(value2);
|
|
430
|
+
};
|
|
431
|
+
(0, import_react.useEffect)(() => {
|
|
432
|
+
if (!isUncontrolled) {
|
|
433
|
+
updateDate(internalValue);
|
|
434
|
+
}
|
|
435
|
+
}, [isUncontrolled, internalValue]);
|
|
436
|
+
const handleDotClicked = () => {
|
|
437
|
+
const currentDateTime = getDefaultMonth();
|
|
438
|
+
if (isDayDisabled(currentDateTime)) {
|
|
439
|
+
announceOutOfRange();
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
const [, endDate] = daysSelected;
|
|
443
|
+
changeMonth(currentDateTime);
|
|
444
|
+
const newDaysSelected = range && endDate < currentDateTime ? [endDate, currentDateTime] : [currentDateTime, endDate];
|
|
445
|
+
let dateFormatted;
|
|
446
|
+
if (range) {
|
|
447
|
+
dateFormatted = fromRangeToString(newDaysSelected, dateFormat);
|
|
448
|
+
} else if (time) {
|
|
449
|
+
dateFormatted = `${(0, import_Helpers.formatDate)(
|
|
450
|
+
currentDateTime,
|
|
451
|
+
dateFormat
|
|
452
|
+
)} ${setCurrentTime(
|
|
453
|
+
currentDateTime.getHours(),
|
|
454
|
+
currentDateTime.getMinutes(),
|
|
455
|
+
use12Hours ? (0, import_Helpers.formatDate)(currentDateTime, "a") : void 0
|
|
456
|
+
)}`;
|
|
457
|
+
} else {
|
|
458
|
+
dateFormatted = (0, import_Helpers.formatDate)(currentDateTime, dateFormat);
|
|
459
|
+
}
|
|
460
|
+
setDaysSelected(newDaysSelected);
|
|
461
|
+
setValue(dateFormatted);
|
|
462
|
+
};
|
|
463
|
+
const handleTimeChange = (hours, minutes, ampm) => {
|
|
464
|
+
const [day] = daysSelected;
|
|
465
|
+
if (hours === "--" && typeof minutes === "number") {
|
|
466
|
+
hours = 0;
|
|
467
|
+
}
|
|
468
|
+
if (minutes === "--" && typeof hours === "number") {
|
|
469
|
+
minutes = 0;
|
|
470
|
+
}
|
|
471
|
+
if (typeof hours === "number" && typeof minutes === "number" && (parsedMin || parsedMax)) {
|
|
472
|
+
let hours24 = hours;
|
|
473
|
+
if (use12Hours) {
|
|
474
|
+
if (ampm === "PM" && hours < 12) {
|
|
475
|
+
hours24 = hours + 12;
|
|
476
|
+
} else if (ampm === "AM" && hours === 12) {
|
|
477
|
+
hours24 = 0;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
const dateTimeSelected = (0, import_Helpers.setDate)(day, {
|
|
481
|
+
hours: hours24,
|
|
482
|
+
minutes
|
|
483
|
+
});
|
|
484
|
+
if (isDateTimeOutOfRange(dateTimeSelected)) {
|
|
485
|
+
announceOutOfRange();
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (internalValue) {
|
|
490
|
+
let date = typeof hours === "string" && typeof minutes === "string" ? `${(0, import_Helpers.formatDate)(day, dateFormat)} ${hours}:${minutes}` : (0, import_Helpers.formatDate)(
|
|
491
|
+
(0, import_Helpers.setDate)(day, { hours, minutes }),
|
|
492
|
+
`${dateFormat} ${TIME_FORMAT}`
|
|
493
|
+
);
|
|
494
|
+
if (use12Hours) {
|
|
495
|
+
date += ` ${ampm}`;
|
|
496
|
+
}
|
|
497
|
+
setValue(date);
|
|
498
|
+
}
|
|
499
|
+
setCurrentTime(hours, minutes, use12Hours ? ampm : void 0);
|
|
500
|
+
};
|
|
501
|
+
const handleCalendarButtonClicked = () => setExpandedValue(!expandedValue);
|
|
502
|
+
const calendarNavigation = (0, import_Hooks.useCalendarNavigation)({
|
|
503
|
+
daysSelected,
|
|
504
|
+
isOpen: expandedValue,
|
|
505
|
+
onChangeMonth: (month, year) => {
|
|
506
|
+
if (typeof year === "number") {
|
|
507
|
+
changeMonth(
|
|
508
|
+
(0, import_Helpers.setDate)(currentMonth, {
|
|
509
|
+
year: currentMonth.getFullYear() + year
|
|
510
|
+
})
|
|
511
|
+
);
|
|
512
|
+
} else {
|
|
513
|
+
const date = (0, import_Helpers.setMonth)(memoizedYears, month, currentMonth);
|
|
514
|
+
if (date) {
|
|
515
|
+
changeMonth(date);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
},
|
|
519
|
+
weeks
|
|
520
|
+
});
|
|
521
|
+
const ariaControls = (0, import_shared.useId)();
|
|
522
|
+
return /* @__PURE__ */ import_react.default.createElement(import_shared.FocusScope, { arrowKeysUpDown: false }, /* @__PURE__ */ import_react.default.createElement("div", { className: "date-picker" }, /* @__PURE__ */ import_react.default.createElement(
|
|
523
|
+
"div",
|
|
524
|
+
{
|
|
525
|
+
"aria-atomic": "true",
|
|
526
|
+
"aria-live": "polite",
|
|
527
|
+
className: "sr-only",
|
|
528
|
+
ref: liveRegionRef
|
|
529
|
+
}
|
|
530
|
+
), /* @__PURE__ */ import_react.default.createElement(import_form.ClayInput.Group, { ref: triggerElementRef }, /* @__PURE__ */ import_react.default.createElement(import_form.ClayInput.GroupItem, { className: "input-group-item-focusable" }, /* @__PURE__ */ import_react.default.createElement(
|
|
531
|
+
import_InputDate.default,
|
|
532
|
+
{
|
|
533
|
+
...otherProps,
|
|
534
|
+
ariaLabel: ariaLabels.input,
|
|
535
|
+
disabled,
|
|
536
|
+
id,
|
|
537
|
+
inputName,
|
|
538
|
+
onChange: inputChange,
|
|
539
|
+
placeholder,
|
|
540
|
+
ref,
|
|
541
|
+
useNative,
|
|
542
|
+
value: internalValue
|
|
543
|
+
}
|
|
544
|
+
), !useNative && /* @__PURE__ */ import_react.default.createElement(import_form.ClayInput.GroupInsetItem, { after: true }, /* @__PURE__ */ import_react.default.createElement(
|
|
545
|
+
import_button.default,
|
|
546
|
+
{
|
|
547
|
+
"aria-controls": ariaControls,
|
|
548
|
+
"aria-expanded": expandedValue,
|
|
549
|
+
"aria-haspopup": "dialog",
|
|
550
|
+
"aria-label": ariaLabels.buttonChooseDate,
|
|
551
|
+
className: "date-picker-dropdown-toggle",
|
|
552
|
+
"data-testid": "date-button",
|
|
553
|
+
disabled,
|
|
554
|
+
displayType: "unstyled",
|
|
555
|
+
onClick: handleCalendarButtonClicked,
|
|
556
|
+
ref: chooseDateRef,
|
|
557
|
+
title: ariaLabels.openCalendar
|
|
558
|
+
},
|
|
559
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
560
|
+
import_icon.default,
|
|
561
|
+
{
|
|
562
|
+
spritemap,
|
|
563
|
+
symbol: "calendar"
|
|
564
|
+
}
|
|
565
|
+
)
|
|
566
|
+
)))), !useNative && /* @__PURE__ */ import_react.default.createElement(
|
|
567
|
+
import_drop_down.default.Menu,
|
|
568
|
+
{
|
|
569
|
+
active: expandedValue,
|
|
570
|
+
alignElementRef: triggerElementRef,
|
|
571
|
+
"aria-label": ariaLabels.dialog,
|
|
572
|
+
className: "date-picker date-picker-dropdown-menu",
|
|
573
|
+
"data-testid": "dropdown",
|
|
574
|
+
id: ariaControls,
|
|
575
|
+
lock: true,
|
|
576
|
+
onActiveChange: setExpandedValue,
|
|
577
|
+
ref: menuElementRef,
|
|
578
|
+
role: "dialog",
|
|
579
|
+
triggerRef: chooseDateRef
|
|
580
|
+
},
|
|
581
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
582
|
+
"div",
|
|
583
|
+
{
|
|
584
|
+
"aria-label": ariaLabels.chooseDate && (0, import_shared.sub)(ariaLabels.chooseDate, [
|
|
585
|
+
(0, import_Helpers.formatDate)(currentMonth, "MMMM yyyy")
|
|
586
|
+
]),
|
|
587
|
+
className: "date-picker-calendar",
|
|
588
|
+
role: "group"
|
|
589
|
+
},
|
|
590
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
591
|
+
import_DateNavigation.default,
|
|
592
|
+
{
|
|
593
|
+
ariaLabels,
|
|
594
|
+
currentMonth,
|
|
595
|
+
disabled,
|
|
596
|
+
months: memoizedMonths,
|
|
597
|
+
onDotClicked: handleDotClicked,
|
|
598
|
+
onMonthChange: changeMonth,
|
|
599
|
+
spritemap,
|
|
600
|
+
years: memoizedYears
|
|
601
|
+
}
|
|
602
|
+
),
|
|
603
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
604
|
+
"div",
|
|
605
|
+
{
|
|
606
|
+
...calendarNavigation.gridProps,
|
|
607
|
+
className: "date-picker-calendar-body",
|
|
608
|
+
role: "grid"
|
|
609
|
+
},
|
|
610
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
611
|
+
import_WeekdayHeader.default,
|
|
612
|
+
{
|
|
613
|
+
firstDayOfWeek,
|
|
614
|
+
weekdaysShort
|
|
615
|
+
},
|
|
616
|
+
({ key, weekday }) => /* @__PURE__ */ import_react.default.createElement(
|
|
617
|
+
import_Weekday.default,
|
|
618
|
+
{
|
|
619
|
+
key,
|
|
620
|
+
weekday
|
|
621
|
+
}
|
|
622
|
+
)
|
|
623
|
+
),
|
|
624
|
+
/* @__PURE__ */ import_react.default.createElement(import_DaysTable.default, { weeks }, ({ day, key }) => /* @__PURE__ */ import_react.default.createElement(
|
|
625
|
+
import_DayNumber.default,
|
|
626
|
+
{
|
|
627
|
+
day,
|
|
628
|
+
daysSelected,
|
|
629
|
+
disabled,
|
|
630
|
+
index: key,
|
|
631
|
+
isFocused: calendarNavigation.isFocused(
|
|
632
|
+
day
|
|
633
|
+
),
|
|
634
|
+
key,
|
|
635
|
+
onClick: handleDayClicked,
|
|
636
|
+
outOfRange: isDayDisabled(
|
|
637
|
+
day.date
|
|
638
|
+
),
|
|
639
|
+
range
|
|
640
|
+
}
|
|
641
|
+
))
|
|
642
|
+
),
|
|
643
|
+
(footerElement || time) && /* @__PURE__ */ import_react.default.createElement("div", { className: "date-picker-calendar-footer" }, time && /* @__PURE__ */ import_react.default.createElement(
|
|
644
|
+
import_TimePicker.default,
|
|
645
|
+
{
|
|
646
|
+
config: timePickerConfig,
|
|
647
|
+
currentTime,
|
|
648
|
+
disabled,
|
|
649
|
+
onTimeChange: handleTimeChange,
|
|
650
|
+
spritemap,
|
|
651
|
+
timezone,
|
|
652
|
+
use12Hours
|
|
653
|
+
}
|
|
654
|
+
), !time && footerElement && import_react.default.Children.only(
|
|
655
|
+
footerElement({ spritemap })
|
|
656
|
+
))
|
|
657
|
+
)
|
|
658
|
+
), !useNative && expandedValue && displayKeyboardArrowsIndicator && /* @__PURE__ */ import_react.default.createElement(import_shared.ClayPortal, null, /* @__PURE__ */ import_react.default.createElement(
|
|
659
|
+
import_core.KeyboardArrowsIndicator,
|
|
660
|
+
{
|
|
661
|
+
anchorRef: menuElementRef,
|
|
662
|
+
direction: "all"
|
|
663
|
+
}
|
|
664
|
+
))));
|
|
665
|
+
}
|
|
666
|
+
);
|
|
667
|
+
const RANGE_SEPARATOR = " - ";
|
|
668
|
+
function isYearWithinYears(year, years) {
|
|
669
|
+
return years.start <= year && year <= years.end;
|
|
670
|
+
}
|
|
671
|
+
function fromStringToRange(value, dateFormat, referenceDate) {
|
|
672
|
+
const [startDateString, endDateString] = value.split(RANGE_SEPARATOR);
|
|
673
|
+
const startDate = (0, import_Helpers.parseDate)(startDateString, dateFormat, referenceDate);
|
|
674
|
+
return [
|
|
675
|
+
startDate,
|
|
676
|
+
endDateString ? (0, import_Helpers.parseDate)(endDateString, dateFormat, referenceDate) : startDate
|
|
677
|
+
];
|
|
678
|
+
}
|
|
679
|
+
function hasDaysSelected({
|
|
680
|
+
checkRangeYears,
|
|
681
|
+
dateFormat,
|
|
682
|
+
is12Hours,
|
|
683
|
+
isTime,
|
|
684
|
+
value,
|
|
685
|
+
years
|
|
686
|
+
}) {
|
|
687
|
+
const [startDate, endDate] = fromStringToRange(
|
|
688
|
+
value,
|
|
689
|
+
isTime ? `${dateFormat} ${is12Hours ? TIME_FORMAT_12H : TIME_FORMAT}` : dateFormat,
|
|
690
|
+
NEW_DATE
|
|
691
|
+
);
|
|
692
|
+
const isValidYear = checkRangeYears ? isYearWithinYears(startDate.getFullYear(), years) && isYearWithinYears(endDate.getFullYear(), years) : true;
|
|
693
|
+
if ((0, import_Helpers.isValid)(startDate) && (0, import_Helpers.isValid)(endDate) && isValidYear) {
|
|
694
|
+
return [startDate, endDate];
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
function fromRangeToString(range, dateFormat) {
|
|
698
|
+
const [startDate, endDate] = range;
|
|
699
|
+
return `${(0, import_Helpers.formatDate)(startDate, dateFormat)}${RANGE_SEPARATOR}${(0, import_Helpers.formatDate)(
|
|
700
|
+
endDate,
|
|
701
|
+
dateFormat
|
|
702
|
+
)}`;
|
|
703
|
+
}
|
|
704
|
+
DatePicker.displayName = "ClayDatePicker";
|
|
705
|
+
var index_default = DatePicker;
|