@xsolla/xui-date-picker 0.117.0 → 0.118.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 +28 -115
- package/native/index.d.mts +3 -70
- package/native/index.d.ts +3 -70
- package/native/index.js +41 -478
- package/native/index.js.flow +17 -97
- package/native/index.js.map +1 -1
- package/native/index.mjs +42 -495
- package/native/index.mjs.map +1 -1
- package/package.json +5 -6
- package/web/index.d.mts +3 -70
- package/web/index.d.ts +3 -70
- package/web/index.js +41 -448
- package/web/index.js.flow +17 -97
- package/web/index.js.map +1 -1
- package/web/index.mjs +42 -462
- package/web/index.mjs.map +1 -1
package/web/index.js
CHANGED
|
@@ -30,15 +30,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.tsx
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
Calendar: () => Calendar,
|
|
33
|
+
Calendar: () => import_xui_calendar2.Calendar,
|
|
34
|
+
CalendarChips: () => import_xui_calendar2.CalendarChips,
|
|
35
|
+
CalendarGrid: () => import_xui_calendar2.CalendarGrid,
|
|
36
|
+
CalendarHeader: () => import_xui_calendar2.CalendarHeader,
|
|
34
37
|
DatePicker: () => DatePicker,
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
DualCalendar: () => import_xui_calendar2.DualCalendar,
|
|
39
|
+
formatDate: () => formatDate
|
|
37
40
|
});
|
|
38
41
|
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
var import_xui_calendar2 = require("@xsolla/xui-calendar");
|
|
39
43
|
|
|
40
44
|
// src/DatePicker.tsx
|
|
41
|
-
var
|
|
45
|
+
var import_react2 = require("react");
|
|
42
46
|
|
|
43
47
|
// ../primitives-web/src/Box.tsx
|
|
44
48
|
var import_react = __toESM(require("react"));
|
|
@@ -209,438 +213,13 @@ var Box = import_react.default.forwardRef(
|
|
|
209
213
|
);
|
|
210
214
|
Box.displayName = "Box";
|
|
211
215
|
|
|
212
|
-
// ../primitives-web/src/Text.tsx
|
|
213
|
-
var import_styled_components2 = __toESM(require("styled-components"));
|
|
214
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
215
|
-
var StyledText = import_styled_components2.default.span`
|
|
216
|
-
color: ${(props) => props.color || "inherit"};
|
|
217
|
-
font-size: ${(props) => typeof props.fontSize === "number" ? `${props.fontSize}px` : props.fontSize || "inherit"};
|
|
218
|
-
font-weight: ${(props) => props.fontWeight || "normal"};
|
|
219
|
-
font-family: ${(props) => props.fontFamily || '"Aktiv Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif'};
|
|
220
|
-
line-height: ${(props) => typeof props.lineHeight === "number" ? `${props.lineHeight}px` : props.lineHeight || "inherit"};
|
|
221
|
-
white-space: ${(props) => props.whiteSpace || "normal"};
|
|
222
|
-
text-align: ${(props) => props.textAlign || "inherit"};
|
|
223
|
-
text-decoration: ${(props) => props.textDecoration || "none"};
|
|
224
|
-
`;
|
|
225
|
-
var Text = ({
|
|
226
|
-
style,
|
|
227
|
-
className,
|
|
228
|
-
id,
|
|
229
|
-
role,
|
|
230
|
-
numberOfLines: _numberOfLines,
|
|
231
|
-
...props
|
|
232
|
-
}) => {
|
|
233
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
234
|
-
StyledText,
|
|
235
|
-
{
|
|
236
|
-
...props,
|
|
237
|
-
style,
|
|
238
|
-
className,
|
|
239
|
-
id,
|
|
240
|
-
role
|
|
241
|
-
}
|
|
242
|
-
);
|
|
243
|
-
};
|
|
244
|
-
|
|
245
216
|
// src/DatePicker.tsx
|
|
246
217
|
var import_xui_input = require("@xsolla/xui-input");
|
|
247
|
-
var import_xui_core2 = require("@xsolla/xui-core");
|
|
248
|
-
var import_date_fns3 = require("date-fns");
|
|
249
|
-
|
|
250
|
-
// src/Calendar.tsx
|
|
251
|
-
var import_react3 = require("react");
|
|
252
218
|
var import_xui_core = require("@xsolla/xui-core");
|
|
253
|
-
var import_date_fns2 = require("date-fns");
|
|
254
|
-
var locales2 = __toESM(require("date-fns/locale"));
|
|
255
|
-
|
|
256
|
-
// src/CalendarHeader.tsx
|
|
257
|
-
var import_react2 = require("react");
|
|
258
|
-
var import_xui_button = require("@xsolla/xui-button");
|
|
259
|
-
var import_xui_select = require("@xsolla/xui-select");
|
|
260
|
-
|
|
261
|
-
// src/utils.ts
|
|
262
219
|
var import_date_fns = require("date-fns");
|
|
263
|
-
var
|
|
264
|
-
var
|
|
265
|
-
|
|
266
|
-
const localeObj = locales[locale] || locales[defaultLocale];
|
|
267
|
-
return (0, import_date_fns.format)(date, formatStr, {
|
|
268
|
-
locale: localeObj
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
function getMonthInLocale(month, locale = defaultLocale) {
|
|
272
|
-
return formatDate((0, import_date_fns.setMonth)(/* @__PURE__ */ new Date(), month), "LLLL", locale);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// src/CalendarHeader.tsx
|
|
276
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
277
|
-
var ArrowLeft = () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
278
|
-
"svg",
|
|
279
|
-
{
|
|
280
|
-
viewBox: "0 0 24 24",
|
|
281
|
-
width: 16,
|
|
282
|
-
height: 16,
|
|
283
|
-
fill: "none",
|
|
284
|
-
stroke: "currentColor",
|
|
285
|
-
strokeWidth: "2",
|
|
286
|
-
strokeLinecap: "round",
|
|
287
|
-
strokeLinejoin: "round",
|
|
288
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("polyline", { points: "15 18 9 12 15 6" })
|
|
289
|
-
}
|
|
290
|
-
);
|
|
291
|
-
var ArrowRight = () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
292
|
-
"svg",
|
|
293
|
-
{
|
|
294
|
-
viewBox: "0 0 24 24",
|
|
295
|
-
width: 16,
|
|
296
|
-
height: 16,
|
|
297
|
-
fill: "none",
|
|
298
|
-
stroke: "currentColor",
|
|
299
|
-
strokeWidth: "2",
|
|
300
|
-
strokeLinecap: "round",
|
|
301
|
-
strokeLinejoin: "round",
|
|
302
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("polyline", { points: "9 18 15 12 9 6" })
|
|
303
|
-
}
|
|
304
|
-
);
|
|
305
|
-
var months = [
|
|
306
|
-
"january",
|
|
307
|
-
"february",
|
|
308
|
-
"march",
|
|
309
|
-
"april",
|
|
310
|
-
"may",
|
|
311
|
-
"june",
|
|
312
|
-
"july",
|
|
313
|
-
"august",
|
|
314
|
-
"september",
|
|
315
|
-
"october",
|
|
316
|
-
"november",
|
|
317
|
-
"december"
|
|
318
|
-
];
|
|
319
|
-
var CalendarHeader = ({
|
|
320
|
-
monthDate,
|
|
321
|
-
decreaseMonth,
|
|
322
|
-
increaseMonth,
|
|
323
|
-
changeYear,
|
|
324
|
-
changeMonth,
|
|
325
|
-
prevMonthButtonDisabled,
|
|
326
|
-
nextMonthButtonDisabled,
|
|
327
|
-
locale,
|
|
328
|
-
minDate,
|
|
329
|
-
maxDate
|
|
330
|
-
}) => {
|
|
331
|
-
const handleChangeMonth = (0, import_react2.useCallback)(
|
|
332
|
-
(value) => {
|
|
333
|
-
changeMonth(months.indexOf(value));
|
|
334
|
-
},
|
|
335
|
-
[changeMonth]
|
|
336
|
-
);
|
|
337
|
-
const handleChangeYear = (0, import_react2.useCallback)(
|
|
338
|
-
(value) => {
|
|
339
|
-
changeYear(parseInt(value, 10));
|
|
340
|
-
},
|
|
341
|
-
[changeYear]
|
|
342
|
-
);
|
|
343
|
-
const monthOptions = (0, import_react2.useMemo)(() => {
|
|
344
|
-
return months.map((month, index) => ({
|
|
345
|
-
label: getMonthInLocale(index, locale),
|
|
346
|
-
value: month
|
|
347
|
-
}));
|
|
348
|
-
}, [locale]);
|
|
349
|
-
const yearOptions = (0, import_react2.useMemo)(() => {
|
|
350
|
-
const options = [];
|
|
351
|
-
const yearStart = minDate ? minDate.getFullYear() : 1900;
|
|
352
|
-
const yearEnd = maxDate ? maxDate.getFullYear() : (/* @__PURE__ */ new Date()).getFullYear() + 100;
|
|
353
|
-
for (let i = yearEnd; i >= yearStart; i--) {
|
|
354
|
-
options.push({ value: i.toString(), label: i.toString() });
|
|
355
|
-
}
|
|
356
|
-
return options;
|
|
357
|
-
}, [minDate, maxDate]);
|
|
358
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
359
|
-
Box,
|
|
360
|
-
{
|
|
361
|
-
width: "100%",
|
|
362
|
-
flexDirection: "row",
|
|
363
|
-
justifyContent: "space-between",
|
|
364
|
-
alignItems: "center",
|
|
365
|
-
marginBottom: 16,
|
|
366
|
-
gap: 8,
|
|
367
|
-
children: [
|
|
368
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
369
|
-
import_xui_button.IconButton,
|
|
370
|
-
{
|
|
371
|
-
size: "xs",
|
|
372
|
-
tone: "mono",
|
|
373
|
-
variant: "secondary",
|
|
374
|
-
onPress: decreaseMonth,
|
|
375
|
-
disabled: prevMonthButtonDisabled,
|
|
376
|
-
icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ArrowLeft, {}),
|
|
377
|
-
"aria-label": "Previous month"
|
|
378
|
-
}
|
|
379
|
-
),
|
|
380
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Box, { flexDirection: "row", flex: 1, gap: 4, children: [
|
|
381
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box, { flex: 1.5, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
382
|
-
import_xui_select.Select,
|
|
383
|
-
{
|
|
384
|
-
value: months[monthDate.getMonth()],
|
|
385
|
-
onValueChange: handleChangeMonth,
|
|
386
|
-
options: monthOptions,
|
|
387
|
-
size: "sm"
|
|
388
|
-
}
|
|
389
|
-
) }),
|
|
390
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Box, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
391
|
-
import_xui_select.Select,
|
|
392
|
-
{
|
|
393
|
-
value: monthDate.getFullYear().toString(),
|
|
394
|
-
onValueChange: handleChangeYear,
|
|
395
|
-
options: yearOptions,
|
|
396
|
-
size: "sm"
|
|
397
|
-
}
|
|
398
|
-
) })
|
|
399
|
-
] }),
|
|
400
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
401
|
-
import_xui_button.IconButton,
|
|
402
|
-
{
|
|
403
|
-
size: "xs",
|
|
404
|
-
tone: "mono",
|
|
405
|
-
variant: "secondary",
|
|
406
|
-
onPress: increaseMonth,
|
|
407
|
-
disabled: nextMonthButtonDisabled,
|
|
408
|
-
icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ArrowRight, {}),
|
|
409
|
-
"aria-label": "Next month"
|
|
410
|
-
}
|
|
411
|
-
)
|
|
412
|
-
]
|
|
413
|
-
}
|
|
414
|
-
);
|
|
415
|
-
};
|
|
416
|
-
|
|
417
|
-
// src/Calendar.tsx
|
|
418
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
419
|
-
var Calendar = (0, import_react3.forwardRef)(
|
|
420
|
-
({
|
|
421
|
-
locale = "enUS",
|
|
422
|
-
onChange,
|
|
423
|
-
startDate,
|
|
424
|
-
endDate,
|
|
425
|
-
selectedDate,
|
|
426
|
-
selectsRange = false,
|
|
427
|
-
contextMenuMaxHeight,
|
|
428
|
-
topContent,
|
|
429
|
-
bottomContent,
|
|
430
|
-
testID,
|
|
431
|
-
minDate,
|
|
432
|
-
maxDate,
|
|
433
|
-
firstDayOfWeek = 0,
|
|
434
|
-
month,
|
|
435
|
-
initialMonth
|
|
436
|
-
}, ref) => {
|
|
437
|
-
const { theme } = (0, import_xui_core.useDesignSystem)();
|
|
438
|
-
const localeObj = locales2[locale] || locales2.enUS;
|
|
439
|
-
const [currentMonth, setCurrentMonth] = (0, import_react3.useState)(
|
|
440
|
-
month || initialMonth || selectedDate || startDate || /* @__PURE__ */ new Date()
|
|
441
|
-
);
|
|
442
|
-
const [selectedStartDate, setSelectedStartDate] = (0, import_react3.useState)(startDate);
|
|
443
|
-
const [selectedEndDate, setSelectedEndDate] = (0, import_react3.useState)(endDate);
|
|
444
|
-
const [locSelectedDate, setLocSelectedDate] = (0, import_react3.useState)(selectedDate);
|
|
445
|
-
const [selectingRange, setSelectingRange] = (0, import_react3.useState)(null);
|
|
446
|
-
(0, import_react3.useEffect)(() => {
|
|
447
|
-
setSelectedStartDate(startDate);
|
|
448
|
-
setSelectedEndDate(endDate);
|
|
449
|
-
setLocSelectedDate(selectedDate);
|
|
450
|
-
if (month !== void 0) {
|
|
451
|
-
setCurrentMonth(month);
|
|
452
|
-
}
|
|
453
|
-
}, [startDate, endDate, selectedDate, month]);
|
|
454
|
-
const handleChange = (0, import_react3.useCallback)(
|
|
455
|
-
(date) => {
|
|
456
|
-
const newDate = new Date(
|
|
457
|
-
currentMonth.getFullYear(),
|
|
458
|
-
currentMonth.getMonth(),
|
|
459
|
-
date.getDate()
|
|
460
|
-
);
|
|
461
|
-
if (!selectsRange) {
|
|
462
|
-
setLocSelectedDate(newDate);
|
|
463
|
-
onChange?.(newDate);
|
|
464
|
-
} else {
|
|
465
|
-
if (!selectedStartDate || selectedStartDate && selectedEndDate) {
|
|
466
|
-
setSelectedStartDate(newDate);
|
|
467
|
-
setSelectedEndDate(null);
|
|
468
|
-
setSelectingRange(newDate);
|
|
469
|
-
onChange?.([newDate, null]);
|
|
470
|
-
} else {
|
|
471
|
-
const start = selectedStartDate < newDate ? selectedStartDate : newDate;
|
|
472
|
-
const end = selectedStartDate < newDate ? newDate : selectedStartDate;
|
|
473
|
-
setSelectedStartDate(start);
|
|
474
|
-
setSelectedEndDate(end);
|
|
475
|
-
setSelectingRange(null);
|
|
476
|
-
onChange?.([start, end]);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
},
|
|
480
|
-
[onChange, selectsRange, selectedStartDate, selectedEndDate, currentMonth]
|
|
481
|
-
);
|
|
482
|
-
const decreaseMonth = (0, import_react3.useCallback)(
|
|
483
|
-
() => setCurrentMonth((prev) => (0, import_date_fns2.subMonths)(prev, 1)),
|
|
484
|
-
[]
|
|
485
|
-
);
|
|
486
|
-
const increaseMonth = (0, import_react3.useCallback)(
|
|
487
|
-
() => setCurrentMonth((prev) => (0, import_date_fns2.addMonths)(prev, 1)),
|
|
488
|
-
[]
|
|
489
|
-
);
|
|
490
|
-
const changeMonth = (0, import_react3.useCallback)(
|
|
491
|
-
(m) => setCurrentMonth((prev) => new Date(prev.getFullYear(), m, 1)),
|
|
492
|
-
[]
|
|
493
|
-
);
|
|
494
|
-
const changeYear = (0, import_react3.useCallback)(
|
|
495
|
-
(y) => setCurrentMonth((prev) => new Date(y, prev.getMonth(), 1)),
|
|
496
|
-
[]
|
|
497
|
-
);
|
|
498
|
-
const monthStart = (0, import_date_fns2.startOfMonth)(currentMonth);
|
|
499
|
-
const monthEnd = (0, import_date_fns2.endOfMonth)(currentMonth);
|
|
500
|
-
const weekStartsOn = firstDayOfWeek ?? 0;
|
|
501
|
-
const calendarStart = (0, import_date_fns2.startOfWeek)(monthStart, { weekStartsOn });
|
|
502
|
-
const calendarEnd = (0, import_date_fns2.endOfWeek)(monthEnd, { weekStartsOn });
|
|
503
|
-
const days = (0, import_date_fns2.eachDayOfInterval)({ start: calendarStart, end: calendarEnd });
|
|
504
|
-
const weekDays = (0, import_react3.useMemo)(() => {
|
|
505
|
-
return Array.from({ length: 7 }, (_, i) => {
|
|
506
|
-
const day = (0, import_date_fns2.addDays)(calendarStart, i);
|
|
507
|
-
return (0, import_date_fns2.format)(day, "EEEEEE", { locale: localeObj });
|
|
508
|
-
});
|
|
509
|
-
}, [calendarStart, localeObj]);
|
|
510
|
-
const weeks = (0, import_react3.useMemo)(() => {
|
|
511
|
-
const weekArray = [];
|
|
512
|
-
for (let i = 0; i < days.length; i += 7) {
|
|
513
|
-
weekArray.push(days.slice(i, i + 7));
|
|
514
|
-
}
|
|
515
|
-
return weekArray;
|
|
516
|
-
}, [days]);
|
|
517
|
-
const isDateDisabled = (0, import_react3.useCallback)(
|
|
518
|
-
(date) => {
|
|
519
|
-
if (minDate && (0, import_date_fns2.isBefore)(date, (0, import_date_fns2.startOfDay)(minDate))) return true;
|
|
520
|
-
if (maxDate && (0, import_date_fns2.isAfter)(date, (0, import_date_fns2.endOfDay)(maxDate))) return true;
|
|
521
|
-
return false;
|
|
522
|
-
},
|
|
523
|
-
[minDate, maxDate]
|
|
524
|
-
);
|
|
525
|
-
const isDateInRange = (0, import_react3.useCallback)(
|
|
526
|
-
(date) => {
|
|
527
|
-
if (!selectsRange || !selectedStartDate) return false;
|
|
528
|
-
const rangeEnd = selectedEndDate || selectingRange;
|
|
529
|
-
if (!rangeEnd) return false;
|
|
530
|
-
const start = selectedStartDate < rangeEnd ? selectedStartDate : rangeEnd;
|
|
531
|
-
const end = selectedStartDate < rangeEnd ? rangeEnd : selectedStartDate;
|
|
532
|
-
return (0, import_date_fns2.isWithinInterval)(date, {
|
|
533
|
-
start: (0, import_date_fns2.startOfDay)(start),
|
|
534
|
-
end: (0, import_date_fns2.endOfDay)(end)
|
|
535
|
-
});
|
|
536
|
-
},
|
|
537
|
-
[selectsRange, selectedStartDate, selectedEndDate, selectingRange]
|
|
538
|
-
);
|
|
539
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
540
|
-
Box,
|
|
541
|
-
{
|
|
542
|
-
ref,
|
|
543
|
-
testID,
|
|
544
|
-
backgroundColor: theme.colors.background.secondary,
|
|
545
|
-
borderRadius: 8,
|
|
546
|
-
padding: 16,
|
|
547
|
-
overflow: "hidden",
|
|
548
|
-
style: {
|
|
549
|
-
boxShadow: "0px 4px 16px 0px rgba(7, 7, 8, 0.1)",
|
|
550
|
-
width: 312
|
|
551
|
-
},
|
|
552
|
-
children: [
|
|
553
|
-
topContent?.({ close: () => {
|
|
554
|
-
} }),
|
|
555
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
556
|
-
CalendarHeader,
|
|
557
|
-
{
|
|
558
|
-
monthDate: currentMonth,
|
|
559
|
-
decreaseMonth,
|
|
560
|
-
increaseMonth,
|
|
561
|
-
changeYear,
|
|
562
|
-
changeMonth,
|
|
563
|
-
locale,
|
|
564
|
-
minDate,
|
|
565
|
-
maxDate,
|
|
566
|
-
contextMenuMaxHeight
|
|
567
|
-
}
|
|
568
|
-
),
|
|
569
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
570
|
-
Box,
|
|
571
|
-
{
|
|
572
|
-
flexDirection: "row",
|
|
573
|
-
justifyContent: "space-between",
|
|
574
|
-
marginBottom: 8,
|
|
575
|
-
children: weekDays.map((day, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box, { width: 40, alignItems: "center", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
576
|
-
Text,
|
|
577
|
-
{
|
|
578
|
-
fontSize: 12,
|
|
579
|
-
fontWeight: "600",
|
|
580
|
-
color: theme.colors.content.tertiary,
|
|
581
|
-
children: day.toUpperCase()
|
|
582
|
-
}
|
|
583
|
-
) }, i))
|
|
584
|
-
}
|
|
585
|
-
),
|
|
586
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box, { gap: 2, children: weeks.map((week, i) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Box, { flexDirection: "row", justifyContent: "space-between", children: week.map((day, j) => {
|
|
587
|
-
const isOutsideMonth = !(0, import_date_fns2.isSameMonth)(day, currentMonth);
|
|
588
|
-
const isSelected = !selectsRange && locSelectedDate && (0, import_date_fns2.isSameDay)(day, locSelectedDate) || selectsRange && selectedStartDate && selectedEndDate && (0, import_date_fns2.isSameDay)(day, selectedStartDate) && (0, import_date_fns2.isSameDay)(day, selectedEndDate);
|
|
589
|
-
const isRangeStart = selectsRange && selectedStartDate && (0, import_date_fns2.isSameDay)(day, selectedStartDate);
|
|
590
|
-
const isRangeEnd = selectsRange && selectedEndDate && (0, import_date_fns2.isSameDay)(day, selectedEndDate);
|
|
591
|
-
const inRange = isDateInRange(day);
|
|
592
|
-
const today = (0, import_date_fns2.isToday)(day);
|
|
593
|
-
const disabled = isDateDisabled(day);
|
|
594
|
-
let bgColor = "transparent";
|
|
595
|
-
let textColor = theme.colors.content.primary;
|
|
596
|
-
if (isSelected || isRangeStart || isRangeEnd) {
|
|
597
|
-
bgColor = theme.colors.background.brand.primary;
|
|
598
|
-
textColor = theme.colors.content.on.brand;
|
|
599
|
-
} else if (inRange) {
|
|
600
|
-
bgColor = theme.colors.overlay.brand;
|
|
601
|
-
} else if (today) {
|
|
602
|
-
bgColor = theme.colors.overlay.mono;
|
|
603
|
-
}
|
|
604
|
-
if (isOutsideMonth || disabled) {
|
|
605
|
-
textColor = theme.colors.content.tertiary;
|
|
606
|
-
}
|
|
607
|
-
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
608
|
-
Box,
|
|
609
|
-
{
|
|
610
|
-
width: 40,
|
|
611
|
-
height: 32,
|
|
612
|
-
alignItems: "center",
|
|
613
|
-
justifyContent: "center",
|
|
614
|
-
borderRadius: isSelected || isRangeStart || isRangeEnd ? 4 : 0,
|
|
615
|
-
backgroundColor: bgColor,
|
|
616
|
-
cursor: disabled || isOutsideMonth ? "default" : "pointer",
|
|
617
|
-
onPress: () => !disabled && !isOutsideMonth && handleChange(day),
|
|
618
|
-
hoverStyle: !disabled && !isOutsideMonth && !isSelected ? { backgroundColor: theme.colors.overlay.mono } : void 0,
|
|
619
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
620
|
-
Text,
|
|
621
|
-
{
|
|
622
|
-
color: textColor,
|
|
623
|
-
fontSize: 14,
|
|
624
|
-
fontWeight: isSelected || isRangeStart || isRangeEnd ? "600" : "400",
|
|
625
|
-
children: (0, import_date_fns2.format)(day, "d")
|
|
626
|
-
}
|
|
627
|
-
)
|
|
628
|
-
},
|
|
629
|
-
j
|
|
630
|
-
);
|
|
631
|
-
}) }, i)) }),
|
|
632
|
-
bottomContent?.({ close: () => {
|
|
633
|
-
} })
|
|
634
|
-
]
|
|
635
|
-
}
|
|
636
|
-
);
|
|
637
|
-
}
|
|
638
|
-
);
|
|
639
|
-
Calendar.displayName = "Calendar";
|
|
640
|
-
|
|
641
|
-
// src/DatePicker.tsx
|
|
642
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
643
|
-
var DatePicker = (0, import_react4.forwardRef)(
|
|
220
|
+
var import_xui_calendar = require("@xsolla/xui-calendar");
|
|
221
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
222
|
+
var DatePicker = (0, import_react2.forwardRef)(
|
|
644
223
|
({
|
|
645
224
|
onChange,
|
|
646
225
|
size = "md",
|
|
@@ -654,18 +233,18 @@ var DatePicker = (0, import_react4.forwardRef)(
|
|
|
654
233
|
testID,
|
|
655
234
|
...rest
|
|
656
235
|
}) => {
|
|
657
|
-
const [open, setOpen] = (0,
|
|
658
|
-
const [inputValue, setInputValue] = (0,
|
|
659
|
-
const containerRef = (0,
|
|
236
|
+
const [open, setOpen] = (0, import_react2.useState)(false);
|
|
237
|
+
const [inputValue, setInputValue] = (0, import_react2.useState)("");
|
|
238
|
+
const containerRef = (0, import_react2.useRef)(null);
|
|
660
239
|
const formatDateForDisplay = (date) => {
|
|
661
240
|
if (!date) return "";
|
|
662
241
|
try {
|
|
663
|
-
return (0,
|
|
242
|
+
return (0, import_date_fns.format)(date, "MM/dd/yyyy");
|
|
664
243
|
} catch {
|
|
665
244
|
return "";
|
|
666
245
|
}
|
|
667
246
|
};
|
|
668
|
-
const getDisplayValue = (0,
|
|
247
|
+
const getDisplayValue = (0, import_react2.useCallback)(() => {
|
|
669
248
|
if (selectsRange) {
|
|
670
249
|
if (startDate && endDate) {
|
|
671
250
|
return `${formatDateForDisplay(startDate)} - ${formatDateForDisplay(endDate)}`;
|
|
@@ -677,7 +256,7 @@ var DatePicker = (0, import_react4.forwardRef)(
|
|
|
677
256
|
return formatDateForDisplay(selectedDate);
|
|
678
257
|
}
|
|
679
258
|
}, [selectsRange, startDate, endDate, selectedDate]);
|
|
680
|
-
(0,
|
|
259
|
+
(0, import_react2.useEffect)(() => {
|
|
681
260
|
setInputValue(getDisplayValue());
|
|
682
261
|
}, [getDisplayValue]);
|
|
683
262
|
const handleInputChange = (text) => {
|
|
@@ -695,8 +274,8 @@ var DatePicker = (0, import_react4.forwardRef)(
|
|
|
695
274
|
}
|
|
696
275
|
}
|
|
697
276
|
};
|
|
698
|
-
(0,
|
|
699
|
-
if (
|
|
277
|
+
(0, import_react2.useEffect)(() => {
|
|
278
|
+
if (import_xui_core.isNative) return;
|
|
700
279
|
const handleClickOutside = (event) => {
|
|
701
280
|
if (containerRef.current && !containerRef.current.contains(event.target)) {
|
|
702
281
|
setOpen(false);
|
|
@@ -705,8 +284,8 @@ var DatePicker = (0, import_react4.forwardRef)(
|
|
|
705
284
|
document.addEventListener("mousedown", handleClickOutside);
|
|
706
285
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
707
286
|
}, []);
|
|
708
|
-
const renderCalendar = () => /* @__PURE__ */ (0,
|
|
709
|
-
Calendar,
|
|
287
|
+
const renderCalendar = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
288
|
+
import_xui_calendar.Calendar,
|
|
710
289
|
{
|
|
711
290
|
locale,
|
|
712
291
|
startDate,
|
|
@@ -717,8 +296,8 @@ var DatePicker = (0, import_react4.forwardRef)(
|
|
|
717
296
|
...rest
|
|
718
297
|
}
|
|
719
298
|
);
|
|
720
|
-
return /* @__PURE__ */ (0,
|
|
721
|
-
/* @__PURE__ */ (0,
|
|
299
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Box, { ref: containerRef, position: "relative", width: "100%", children: [
|
|
300
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
722
301
|
import_xui_input.Input,
|
|
723
302
|
{
|
|
724
303
|
...rest,
|
|
@@ -731,7 +310,7 @@ var DatePicker = (0, import_react4.forwardRef)(
|
|
|
731
310
|
testID
|
|
732
311
|
}
|
|
733
312
|
),
|
|
734
|
-
open && (
|
|
313
|
+
open && (import_xui_core.isWeb ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
735
314
|
Box,
|
|
736
315
|
{
|
|
737
316
|
position: "absolute",
|
|
@@ -745,17 +324,31 @@ var DatePicker = (0, import_react4.forwardRef)(
|
|
|
745
324
|
// Native implementation could use a Modal here
|
|
746
325
|
// For now, we just show it below the input if needed,
|
|
747
326
|
// but usually a bottom sheet or centered modal is better.
|
|
748
|
-
/* @__PURE__ */ (0,
|
|
327
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Box, { marginTop: 4, children: renderCalendar() })
|
|
749
328
|
))
|
|
750
329
|
] });
|
|
751
330
|
}
|
|
752
331
|
);
|
|
753
332
|
DatePicker.displayName = "DatePicker";
|
|
333
|
+
|
|
334
|
+
// src/utils.ts
|
|
335
|
+
var import_date_fns2 = require("date-fns");
|
|
336
|
+
var locales = __toESM(require("date-fns/locale"));
|
|
337
|
+
var defaultLocale = "enUS";
|
|
338
|
+
function formatDate(date, formatStr, locale = defaultLocale) {
|
|
339
|
+
const localeObj = locales[locale] || locales[defaultLocale];
|
|
340
|
+
return (0, import_date_fns2.format)(date, formatStr, {
|
|
341
|
+
locale: localeObj
|
|
342
|
+
});
|
|
343
|
+
}
|
|
754
344
|
// Annotate the CommonJS export names for ESM import in node:
|
|
755
345
|
0 && (module.exports = {
|
|
756
346
|
Calendar,
|
|
347
|
+
CalendarChips,
|
|
348
|
+
CalendarGrid,
|
|
349
|
+
CalendarHeader,
|
|
757
350
|
DatePicker,
|
|
758
|
-
|
|
759
|
-
|
|
351
|
+
DualCalendar,
|
|
352
|
+
formatDate
|
|
760
353
|
});
|
|
761
354
|
//# sourceMappingURL=index.js.map
|
package/web/index.js.flow
CHANGED
|
@@ -5,89 +5,22 @@
|
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { CalendarProps, CalendarLocaleType } from "@xsolla/xui-calendar";
|
|
9
|
+
declare export {
|
|
10
|
+
Calendar,
|
|
11
|
+
CalendarChipOption,
|
|
12
|
+
CalendarChips,
|
|
13
|
+
CalendarChipsProps,
|
|
14
|
+
CalendarGrid,
|
|
15
|
+
CalendarGridProps,
|
|
16
|
+
CalendarHeader,
|
|
17
|
+
CalendarHeaderProps,
|
|
18
|
+
CalendarLocaleType,
|
|
19
|
+
CalendarProps,
|
|
20
|
+
DualCalendar,
|
|
21
|
+
DualCalendarProps,
|
|
22
|
+
} from "@xsolla/xui-calendar";
|
|
8
23
|
import * as react from "react";
|
|
9
|
-
import { Node } from "react";
|
|
10
|
-
import * as locales from "date-fns/locale";
|
|
11
|
-
declare type CalendarLocaleType = $Keys<typeof locales>;
|
|
12
|
-
declare interface CalendarProps {
|
|
13
|
-
locale?: CalendarLocaleType;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The day to use as first day of the week, starting from 0 (Sunday) to 6 (Saturday).
|
|
17
|
-
*/
|
|
18
|
-
firstDayOfWeek?: number;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The month to display in the calendar at first render.
|
|
22
|
-
*/
|
|
23
|
-
initialMonth?: Date;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The month to display in the calendar.
|
|
27
|
-
*/
|
|
28
|
-
month?: Date;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Select in range mode for calendar
|
|
32
|
-
*/
|
|
33
|
-
selectsRange?: boolean;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The minimum selectable date
|
|
37
|
-
*/
|
|
38
|
-
minDate?: Date | null;
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* The maximum selectable date
|
|
42
|
-
*/
|
|
43
|
-
maxDate?: Date | null;
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* For range mode. Start date in selected period
|
|
47
|
-
*/
|
|
48
|
-
startDate?: Date | null;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* For range mode. End date in selected period
|
|
52
|
-
*/
|
|
53
|
-
endDate?: Date | null;
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* The selected date
|
|
57
|
-
*/
|
|
58
|
-
selectedDate?: Date | null;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Property sets the maximum height of a context menus for selecting month and year.
|
|
62
|
-
*/
|
|
63
|
-
contextMenuMaxHeight?: number;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Returns custom content to display above the calendar's date picker.
|
|
67
|
-
*/
|
|
68
|
-
topContent?: (datePicker: {
|
|
69
|
-
close: () => void,
|
|
70
|
-
...
|
|
71
|
-
}) => Node;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Returns custom content to display beneath the calendar's date picker.
|
|
75
|
-
*/
|
|
76
|
-
bottomContent?: (datePicker: {
|
|
77
|
-
close: () => void,
|
|
78
|
-
...
|
|
79
|
-
}) => Node;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Test ID for testing frameworks
|
|
83
|
-
*/
|
|
84
|
-
testID?: string;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Callback fired when the date changes
|
|
88
|
-
*/
|
|
89
|
-
onChange?: (date: Date | [Date | null, Date | null]) => void;
|
|
90
|
-
}
|
|
91
24
|
declare type DateRangeType = [Date | null, Date | null];
|
|
92
25
|
declare type DatePickerProps = {
|
|
93
26
|
/**
|
|
@@ -120,23 +53,10 @@ declare var DatePicker: react.ForwardRefExoticComponent<{
|
|
|
120
53
|
...DatePickerProps,
|
|
121
54
|
...react.RefAttributes<any>,
|
|
122
55
|
}>;
|
|
123
|
-
declare var Calendar: react.ForwardRefExoticComponent<{
|
|
124
|
-
...CalendarProps,
|
|
125
|
-
...react.RefAttributes<any>,
|
|
126
|
-
}>;
|
|
127
56
|
declare function formatDate(
|
|
128
57
|
date: Date,
|
|
129
58
|
formatStr: string,
|
|
130
59
|
locale?: CalendarLocaleType
|
|
131
60
|
): string;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
locale?: CalendarLocaleType
|
|
135
|
-
): string;
|
|
136
|
-
export type {
|
|
137
|
-
CalendarLocaleType,
|
|
138
|
-
CalendarProps,
|
|
139
|
-
DatePickerProps,
|
|
140
|
-
DateRangeType,
|
|
141
|
-
};
|
|
142
|
-
declare export { Calendar, DatePicker, formatDate, getMonthInLocale };
|
|
61
|
+
export type { DatePickerProps, DateRangeType };
|
|
62
|
+
declare export { DatePicker, formatDate };
|