@xsolla/xui-date-picker 0.64.0-pr56.1768440195

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.
@@ -0,0 +1,956 @@
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
+
30
+ // src/index.tsx
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ Calendar: () => Calendar,
34
+ DatePicker: () => DatePicker,
35
+ formatDate: () => formatDate,
36
+ getMonthInLocale: () => getMonthInLocale
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
39
+
40
+ // src/DatePicker.tsx
41
+ var import_react6 = require("react");
42
+
43
+ // ../primitives-native/src/Box.tsx
44
+ var import_react_native = require("react-native");
45
+ var import_jsx_runtime = require("react/jsx-runtime");
46
+ var Box = ({
47
+ children,
48
+ onPress,
49
+ onLayout,
50
+ onMoveShouldSetResponder,
51
+ onResponderGrant,
52
+ onResponderMove,
53
+ onResponderRelease,
54
+ onResponderTerminate,
55
+ backgroundColor,
56
+ borderColor,
57
+ borderWidth,
58
+ borderBottomWidth,
59
+ borderBottomColor,
60
+ borderTopWidth,
61
+ borderTopColor,
62
+ borderLeftWidth,
63
+ borderLeftColor,
64
+ borderRightWidth,
65
+ borderRightColor,
66
+ borderRadius,
67
+ borderStyle,
68
+ height,
69
+ padding,
70
+ paddingHorizontal,
71
+ paddingVertical,
72
+ margin,
73
+ marginTop,
74
+ marginBottom,
75
+ marginLeft,
76
+ marginRight,
77
+ flexDirection,
78
+ alignItems,
79
+ justifyContent,
80
+ position,
81
+ top,
82
+ bottom,
83
+ left,
84
+ right,
85
+ width,
86
+ flex,
87
+ overflow,
88
+ zIndex,
89
+ hoverStyle,
90
+ pressStyle,
91
+ style,
92
+ "data-testid": dataTestId,
93
+ testID,
94
+ as,
95
+ src,
96
+ alt,
97
+ ...rest
98
+ }) => {
99
+ const getContainerStyle = (pressed) => ({
100
+ backgroundColor: pressed && pressStyle?.backgroundColor ? pressStyle.backgroundColor : backgroundColor,
101
+ borderColor,
102
+ borderWidth,
103
+ borderBottomWidth,
104
+ borderBottomColor,
105
+ borderTopWidth,
106
+ borderTopColor,
107
+ borderLeftWidth,
108
+ borderLeftColor,
109
+ borderRightWidth,
110
+ borderRightColor,
111
+ borderRadius,
112
+ borderStyle,
113
+ overflow,
114
+ zIndex,
115
+ height,
116
+ width,
117
+ padding,
118
+ paddingHorizontal,
119
+ paddingVertical,
120
+ margin,
121
+ marginTop,
122
+ marginBottom,
123
+ marginLeft,
124
+ marginRight,
125
+ flexDirection,
126
+ alignItems,
127
+ justifyContent,
128
+ position,
129
+ top,
130
+ bottom,
131
+ left,
132
+ right,
133
+ flex,
134
+ ...style
135
+ });
136
+ const finalTestID = dataTestId || testID;
137
+ const {
138
+ role,
139
+ tabIndex,
140
+ onKeyDown,
141
+ onKeyUp,
142
+ "aria-label": _ariaLabel,
143
+ "aria-labelledby": _ariaLabelledBy,
144
+ "aria-current": _ariaCurrent,
145
+ "aria-disabled": _ariaDisabled,
146
+ "aria-live": _ariaLive,
147
+ className,
148
+ "data-testid": _dataTestId,
149
+ ...nativeRest
150
+ } = rest;
151
+ if (as === "img" && src) {
152
+ const imageStyle = {
153
+ width,
154
+ height,
155
+ borderRadius,
156
+ position,
157
+ top,
158
+ bottom,
159
+ left,
160
+ right,
161
+ ...style
162
+ };
163
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
164
+ import_react_native.Image,
165
+ {
166
+ source: { uri: src },
167
+ style: imageStyle,
168
+ testID: finalTestID,
169
+ resizeMode: "cover",
170
+ ...nativeRest
171
+ }
172
+ );
173
+ }
174
+ if (onPress) {
175
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
176
+ import_react_native.Pressable,
177
+ {
178
+ onPress,
179
+ onLayout,
180
+ onMoveShouldSetResponder,
181
+ onResponderGrant,
182
+ onResponderMove,
183
+ onResponderRelease,
184
+ onResponderTerminate,
185
+ style: ({ pressed }) => getContainerStyle(pressed),
186
+ testID: finalTestID,
187
+ ...nativeRest,
188
+ children
189
+ }
190
+ );
191
+ }
192
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
193
+ import_react_native.View,
194
+ {
195
+ style: getContainerStyle(),
196
+ testID: finalTestID,
197
+ onLayout,
198
+ onMoveShouldSetResponder,
199
+ onResponderGrant,
200
+ onResponderMove,
201
+ onResponderRelease,
202
+ onResponderTerminate,
203
+ ...nativeRest,
204
+ children
205
+ }
206
+ );
207
+ };
208
+
209
+ // ../primitives-native/src/Text.tsx
210
+ var import_react_native2 = require("react-native");
211
+ var import_jsx_runtime2 = require("react/jsx-runtime");
212
+ var roleMap = {
213
+ alert: "alert",
214
+ heading: "header",
215
+ button: "button",
216
+ link: "link",
217
+ text: "text"
218
+ };
219
+ var Text = ({
220
+ children,
221
+ color,
222
+ fontSize,
223
+ fontWeight,
224
+ fontFamily,
225
+ id,
226
+ role,
227
+ ...props
228
+ }) => {
229
+ let resolvedFontFamily = fontFamily ? fontFamily.split(",")[0].replace(/['"]/g, "").trim() : void 0;
230
+ if (resolvedFontFamily === "Pilat Wide Bold") {
231
+ resolvedFontFamily = void 0;
232
+ }
233
+ const style = {
234
+ color,
235
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
236
+ fontWeight,
237
+ fontFamily: resolvedFontFamily,
238
+ textDecorationLine: props.textDecoration
239
+ };
240
+ const accessibilityRole = role ? roleMap[role] : void 0;
241
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style, testID: id, accessibilityRole, children });
242
+ };
243
+
244
+ // ../primitives-native/src/Spinner.tsx
245
+ var import_react_native3 = require("react-native");
246
+ var import_jsx_runtime3 = require("react/jsx-runtime");
247
+ var Spinner = ({
248
+ color,
249
+ size,
250
+ role,
251
+ "aria-label": ariaLabel,
252
+ "aria-live": ariaLive,
253
+ "aria-describedby": ariaDescribedBy,
254
+ testID
255
+ }) => {
256
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
257
+ import_react_native3.View,
258
+ {
259
+ accessible: true,
260
+ accessibilityRole: role === "status" ? "none" : void 0,
261
+ accessibilityLabel: ariaLabel,
262
+ accessibilityLiveRegion: ariaLive === "polite" ? "polite" : ariaLive === "assertive" ? "assertive" : "none",
263
+ testID,
264
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
265
+ import_react_native3.ActivityIndicator,
266
+ {
267
+ color,
268
+ size: typeof size === "number" ? size : "small"
269
+ }
270
+ )
271
+ }
272
+ );
273
+ };
274
+ Spinner.displayName = "Spinner";
275
+
276
+ // ../primitives-native/src/Icon.tsx
277
+ var import_react = __toESM(require("react"));
278
+ var import_react_native4 = require("react-native");
279
+ var import_jsx_runtime4 = require("react/jsx-runtime");
280
+
281
+ // ../primitives-native/src/Divider.tsx
282
+ var import_react_native5 = require("react-native");
283
+ var import_jsx_runtime5 = require("react/jsx-runtime");
284
+
285
+ // ../primitives-native/src/Input.tsx
286
+ var import_react2 = require("react");
287
+ var import_react_native6 = require("react-native");
288
+ var import_jsx_runtime6 = require("react/jsx-runtime");
289
+ var keyboardTypeMap = {
290
+ text: "default",
291
+ number: "numeric",
292
+ email: "email-address",
293
+ tel: "phone-pad",
294
+ url: "url",
295
+ decimal: "decimal-pad"
296
+ };
297
+ var inputModeToKeyboardType = {
298
+ none: "default",
299
+ text: "default",
300
+ decimal: "decimal-pad",
301
+ numeric: "number-pad",
302
+ tel: "phone-pad",
303
+ search: "default",
304
+ email: "email-address",
305
+ url: "url"
306
+ };
307
+ var autoCompleteToTextContentType = {
308
+ "one-time-code": "oneTimeCode",
309
+ email: "emailAddress",
310
+ username: "username",
311
+ password: "password",
312
+ "new-password": "newPassword",
313
+ tel: "telephoneNumber",
314
+ "postal-code": "postalCode",
315
+ name: "name"
316
+ };
317
+ var InputPrimitive = (0, import_react2.forwardRef)(
318
+ ({
319
+ value,
320
+ placeholder,
321
+ onChange,
322
+ onChangeText,
323
+ onFocus,
324
+ onBlur,
325
+ onKeyDown,
326
+ disabled,
327
+ secureTextEntry,
328
+ style,
329
+ color,
330
+ fontSize,
331
+ placeholderTextColor,
332
+ maxLength,
333
+ name,
334
+ type,
335
+ inputMode,
336
+ autoComplete,
337
+ id,
338
+ "aria-invalid": ariaInvalid,
339
+ "aria-describedby": ariaDescribedBy,
340
+ "aria-labelledby": ariaLabelledBy,
341
+ "aria-label": ariaLabel,
342
+ "aria-disabled": ariaDisabled,
343
+ "data-testid": dataTestId
344
+ }, ref) => {
345
+ const handleChangeText = (text) => {
346
+ onChangeText?.(text);
347
+ if (onChange) {
348
+ const syntheticEvent = {
349
+ target: { value: text },
350
+ currentTarget: { value: text },
351
+ type: "change",
352
+ nativeEvent: { text },
353
+ preventDefault: () => {
354
+ },
355
+ stopPropagation: () => {
356
+ },
357
+ isTrusted: false
358
+ };
359
+ onChange(syntheticEvent);
360
+ }
361
+ };
362
+ const keyboardType = inputMode ? inputModeToKeyboardType[inputMode] || "default" : type ? keyboardTypeMap[type] || "default" : "default";
363
+ const textContentType = autoComplete ? autoCompleteToTextContentType[autoComplete] : void 0;
364
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
365
+ import_react_native6.TextInput,
366
+ {
367
+ ref,
368
+ value,
369
+ placeholder,
370
+ onChangeText: handleChangeText,
371
+ onFocus,
372
+ onBlur,
373
+ onKeyPress: (e) => {
374
+ if (onKeyDown) {
375
+ onKeyDown({
376
+ key: e.nativeEvent.key,
377
+ preventDefault: () => {
378
+ }
379
+ });
380
+ }
381
+ },
382
+ editable: !disabled,
383
+ secureTextEntry: secureTextEntry || type === "password",
384
+ keyboardType,
385
+ textContentType,
386
+ style: [
387
+ {
388
+ color,
389
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
390
+ flex: 1,
391
+ padding: 0,
392
+ textAlign: style?.textAlign || "left"
393
+ },
394
+ style
395
+ ],
396
+ placeholderTextColor,
397
+ maxLength,
398
+ testID: dataTestId || id,
399
+ accessibilityLabel: ariaLabel,
400
+ accessibilityHint: ariaDescribedBy,
401
+ accessibilityState: {
402
+ disabled: disabled || ariaDisabled
403
+ },
404
+ accessible: true
405
+ }
406
+ );
407
+ }
408
+ );
409
+ InputPrimitive.displayName = "InputPrimitive";
410
+
411
+ // ../primitives-native/src/TextArea.tsx
412
+ var import_react3 = require("react");
413
+ var import_react_native7 = require("react-native");
414
+ var import_jsx_runtime7 = require("react/jsx-runtime");
415
+ var TextAreaPrimitive = (0, import_react3.forwardRef)(
416
+ ({
417
+ value,
418
+ placeholder,
419
+ onChange,
420
+ onChangeText,
421
+ onFocus,
422
+ onBlur,
423
+ onKeyDown,
424
+ disabled,
425
+ style,
426
+ color,
427
+ fontSize,
428
+ placeholderTextColor,
429
+ maxLength,
430
+ rows,
431
+ id,
432
+ "aria-invalid": ariaInvalid,
433
+ "aria-describedby": ariaDescribedBy,
434
+ "aria-labelledby": ariaLabelledBy,
435
+ "aria-label": ariaLabel,
436
+ "aria-disabled": ariaDisabled,
437
+ "data-testid": dataTestId
438
+ }, ref) => {
439
+ const handleChangeText = (text) => {
440
+ onChangeText?.(text);
441
+ if (onChange) {
442
+ const syntheticEvent = {
443
+ target: { value: text },
444
+ currentTarget: { value: text },
445
+ type: "change",
446
+ nativeEvent: { text },
447
+ preventDefault: () => {
448
+ },
449
+ stopPropagation: () => {
450
+ },
451
+ isTrusted: false
452
+ };
453
+ onChange(syntheticEvent);
454
+ }
455
+ };
456
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
457
+ import_react_native7.TextInput,
458
+ {
459
+ ref,
460
+ value,
461
+ placeholder,
462
+ onChangeText: handleChangeText,
463
+ onFocus,
464
+ onBlur,
465
+ onKeyPress: (e) => {
466
+ if (onKeyDown) {
467
+ onKeyDown({
468
+ key: e.nativeEvent.key,
469
+ preventDefault: () => {
470
+ }
471
+ });
472
+ }
473
+ },
474
+ editable: !disabled,
475
+ multiline: true,
476
+ numberOfLines: rows || 4,
477
+ style: [
478
+ {
479
+ color,
480
+ fontSize: typeof fontSize === "number" ? fontSize : void 0,
481
+ flex: 1,
482
+ padding: 0,
483
+ textAlignVertical: "top",
484
+ textAlign: style?.textAlign || "left"
485
+ },
486
+ style
487
+ ],
488
+ placeholderTextColor,
489
+ maxLength,
490
+ testID: dataTestId || id,
491
+ accessibilityLabel: ariaLabel,
492
+ accessibilityHint: ariaDescribedBy,
493
+ accessibilityState: {
494
+ disabled: disabled || ariaDisabled
495
+ },
496
+ accessible: true
497
+ }
498
+ );
499
+ }
500
+ );
501
+ TextAreaPrimitive.displayName = "TextAreaPrimitive";
502
+
503
+ // src/DatePicker.tsx
504
+ var import_xui_input = require("@xsolla/xui-input");
505
+ var import_xui_core2 = require("@xsolla/xui-core");
506
+ var import_date_fns3 = require("date-fns");
507
+
508
+ // src/Calendar.tsx
509
+ var import_react5 = require("react");
510
+ var import_xui_core = require("@xsolla/xui-core");
511
+ var import_date_fns2 = require("date-fns");
512
+ var locales2 = __toESM(require("date-fns/locale"));
513
+
514
+ // src/CalendarHeader.tsx
515
+ var import_react4 = require("react");
516
+ var import_xui_button = require("@xsolla/xui-button");
517
+ var import_xui_select = require("@xsolla/xui-select");
518
+
519
+ // src/utils.ts
520
+ var import_date_fns = require("date-fns");
521
+ var locales = __toESM(require("date-fns/locale"));
522
+ var defaultLocale = "enUS";
523
+ function formatDate(date, formatStr, locale = defaultLocale) {
524
+ const localeObj = locales[locale] || locales[defaultLocale];
525
+ return (0, import_date_fns.format)(date, formatStr, {
526
+ locale: localeObj
527
+ });
528
+ }
529
+ function getMonthInLocale(month, locale = defaultLocale) {
530
+ return formatDate((0, import_date_fns.setMonth)(/* @__PURE__ */ new Date(), month), "LLLL", locale);
531
+ }
532
+
533
+ // src/CalendarHeader.tsx
534
+ var import_jsx_runtime8 = require("react/jsx-runtime");
535
+ var ArrowLeft = () => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("polyline", { points: "15 18 9 12 15 6" }) });
536
+ var ArrowRight = () => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("svg", { viewBox: "0 0 24 24", width: 16, height: 16, fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("polyline", { points: "9 18 15 12 9 6" }) });
537
+ var months = [
538
+ "january",
539
+ "february",
540
+ "march",
541
+ "april",
542
+ "may",
543
+ "june",
544
+ "july",
545
+ "august",
546
+ "september",
547
+ "october",
548
+ "november",
549
+ "december"
550
+ ];
551
+ var CalendarHeader = ({
552
+ monthDate,
553
+ decreaseMonth,
554
+ increaseMonth,
555
+ changeYear,
556
+ changeMonth,
557
+ prevMonthButtonDisabled,
558
+ nextMonthButtonDisabled,
559
+ locale,
560
+ minDate,
561
+ maxDate,
562
+ contextMenuMaxHeight = 240
563
+ }) => {
564
+ const handleChangeMonth = (0, import_react4.useCallback)(
565
+ (value) => {
566
+ changeMonth(months.indexOf(value));
567
+ },
568
+ [changeMonth]
569
+ );
570
+ const handleChangeYear = (0, import_react4.useCallback)(
571
+ (value) => {
572
+ changeYear(parseInt(value, 10));
573
+ },
574
+ [changeYear]
575
+ );
576
+ const monthOptions = (0, import_react4.useMemo)(() => {
577
+ return months.map((month, index) => ({
578
+ label: getMonthInLocale(index, locale),
579
+ value: month
580
+ }));
581
+ }, [locale]);
582
+ const yearOptions = (0, import_react4.useMemo)(() => {
583
+ const options = [];
584
+ const yearStart = minDate ? minDate.getFullYear() : 1900;
585
+ const yearEnd = maxDate ? maxDate.getFullYear() : (/* @__PURE__ */ new Date()).getFullYear() + 100;
586
+ for (let i = yearEnd; i >= yearStart; i--) {
587
+ options.push({ value: i.toString(), label: i.toString() });
588
+ }
589
+ return options;
590
+ }, [minDate, maxDate]);
591
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
592
+ Box,
593
+ {
594
+ width: "100%",
595
+ flexDirection: "row",
596
+ justifyContent: "space-between",
597
+ alignItems: "center",
598
+ marginBottom: 16,
599
+ gap: 8,
600
+ children: [
601
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
602
+ import_xui_button.IconButton,
603
+ {
604
+ size: "xs",
605
+ tone: "mono",
606
+ variant: "secondary",
607
+ onPress: decreaseMonth,
608
+ disabled: prevMonthButtonDisabled,
609
+ icon: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ArrowLeft, {}),
610
+ "aria-label": "Previous month"
611
+ }
612
+ ),
613
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(Box, { flexDirection: "row", flex: 1, gap: 4, children: [
614
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box, { flex: 1.5, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
615
+ import_xui_select.Select,
616
+ {
617
+ value: months[monthDate.getMonth()],
618
+ onValueChange: handleChangeMonth,
619
+ options: monthOptions,
620
+ size: "s"
621
+ }
622
+ ) }),
623
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Box, { flex: 1, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
624
+ import_xui_select.Select,
625
+ {
626
+ value: monthDate.getFullYear().toString(),
627
+ onValueChange: handleChangeYear,
628
+ options: yearOptions,
629
+ size: "s"
630
+ }
631
+ ) })
632
+ ] }),
633
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
634
+ import_xui_button.IconButton,
635
+ {
636
+ size: "xs",
637
+ tone: "mono",
638
+ variant: "secondary",
639
+ onPress: increaseMonth,
640
+ disabled: nextMonthButtonDisabled,
641
+ icon: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ArrowRight, {}),
642
+ "aria-label": "Next month"
643
+ }
644
+ )
645
+ ]
646
+ }
647
+ );
648
+ };
649
+
650
+ // src/Calendar.tsx
651
+ var import_jsx_runtime9 = require("react/jsx-runtime");
652
+ var Calendar = (0, import_react5.forwardRef)(
653
+ ({
654
+ locale = "enUS",
655
+ onChange,
656
+ startDate,
657
+ endDate,
658
+ selectedDate,
659
+ selectsRange = false,
660
+ contextMenuMaxHeight,
661
+ topContent,
662
+ bottomContent,
663
+ testID,
664
+ minDate,
665
+ maxDate,
666
+ firstDayOfWeek = 0,
667
+ month,
668
+ initialMonth
669
+ }, ref) => {
670
+ const { theme } = (0, import_xui_core.useDesignSystem)();
671
+ const localeObj = locales2[locale] || locales2.enUS;
672
+ const [currentMonth, setCurrentMonth] = (0, import_react5.useState)(
673
+ month || initialMonth || selectedDate || startDate || /* @__PURE__ */ new Date()
674
+ );
675
+ const [selectedStartDate, setSelectedStartDate] = (0, import_react5.useState)(startDate);
676
+ const [selectedEndDate, setSelectedEndDate] = (0, import_react5.useState)(endDate);
677
+ const [locSelectedDate, setLocSelectedDate] = (0, import_react5.useState)(selectedDate);
678
+ const [selectingRange, setSelectingRange] = (0, import_react5.useState)(null);
679
+ (0, import_react5.useEffect)(() => {
680
+ setSelectedStartDate(startDate);
681
+ setSelectedEndDate(endDate);
682
+ setLocSelectedDate(selectedDate);
683
+ if (month !== void 0) {
684
+ setCurrentMonth(month);
685
+ }
686
+ }, [startDate, endDate, selectedDate, month]);
687
+ const handleChange = (0, import_react5.useCallback)(
688
+ (date) => {
689
+ const newDate = new Date(
690
+ currentMonth.getFullYear(),
691
+ currentMonth.getMonth(),
692
+ date.getDate()
693
+ );
694
+ if (!selectsRange) {
695
+ setLocSelectedDate(newDate);
696
+ onChange?.(newDate);
697
+ } else {
698
+ if (!selectedStartDate || selectedStartDate && selectedEndDate) {
699
+ setSelectedStartDate(newDate);
700
+ setSelectedEndDate(null);
701
+ setSelectingRange(newDate);
702
+ onChange?.([newDate, null]);
703
+ } else {
704
+ const start = selectedStartDate < newDate ? selectedStartDate : newDate;
705
+ const end = selectedStartDate < newDate ? newDate : selectedStartDate;
706
+ setSelectedStartDate(start);
707
+ setSelectedEndDate(end);
708
+ setSelectingRange(null);
709
+ onChange?.([start, end]);
710
+ }
711
+ }
712
+ },
713
+ [onChange, selectsRange, selectedStartDate, selectedEndDate, currentMonth]
714
+ );
715
+ const decreaseMonth = (0, import_react5.useCallback)(() => setCurrentMonth((prev) => (0, import_date_fns2.subMonths)(prev, 1)), []);
716
+ const increaseMonth = (0, import_react5.useCallback)(() => setCurrentMonth((prev) => (0, import_date_fns2.addMonths)(prev, 1)), []);
717
+ const changeMonth = (0, import_react5.useCallback)((m) => setCurrentMonth((prev) => new Date(prev.getFullYear(), m, 1)), []);
718
+ const changeYear = (0, import_react5.useCallback)((y) => setCurrentMonth((prev) => new Date(y, prev.getMonth(), 1)), []);
719
+ const monthStart = (0, import_date_fns2.startOfMonth)(currentMonth);
720
+ const monthEnd = (0, import_date_fns2.endOfMonth)(currentMonth);
721
+ const weekStartsOn = firstDayOfWeek ?? 0;
722
+ const calendarStart = (0, import_date_fns2.startOfWeek)(monthStart, { weekStartsOn });
723
+ const calendarEnd = (0, import_date_fns2.endOfWeek)(monthEnd, { weekStartsOn });
724
+ const days = (0, import_date_fns2.eachDayOfInterval)({ start: calendarStart, end: calendarEnd });
725
+ const weekDays = (0, import_react5.useMemo)(() => {
726
+ return Array.from({ length: 7 }, (_, i) => {
727
+ const day = (0, import_date_fns2.addDays)(calendarStart, i);
728
+ return (0, import_date_fns2.format)(day, "EEEEEE", { locale: localeObj });
729
+ });
730
+ }, [calendarStart, localeObj]);
731
+ const weeks = (0, import_react5.useMemo)(() => {
732
+ const weekArray = [];
733
+ for (let i = 0; i < days.length; i += 7) {
734
+ weekArray.push(days.slice(i, i + 7));
735
+ }
736
+ return weekArray;
737
+ }, [days]);
738
+ const isDateDisabled = (0, import_react5.useCallback)(
739
+ (date) => {
740
+ if (minDate && (0, import_date_fns2.isBefore)(date, (0, import_date_fns2.startOfDay)(minDate))) return true;
741
+ if (maxDate && (0, import_date_fns2.isAfter)(date, (0, import_date_fns2.endOfDay)(maxDate))) return true;
742
+ return false;
743
+ },
744
+ [minDate, maxDate]
745
+ );
746
+ const isDateInRange = (0, import_react5.useCallback)(
747
+ (date) => {
748
+ if (!selectsRange || !selectedStartDate) return false;
749
+ const rangeEnd = selectedEndDate || selectingRange;
750
+ if (!rangeEnd) return false;
751
+ const start = selectedStartDate < rangeEnd ? selectedStartDate : rangeEnd;
752
+ const end = selectedStartDate < rangeEnd ? rangeEnd : selectedStartDate;
753
+ return (0, import_date_fns2.isWithinInterval)(date, { start: (0, import_date_fns2.startOfDay)(start), end: (0, import_date_fns2.endOfDay)(end) });
754
+ },
755
+ [selectsRange, selectedStartDate, selectedEndDate, selectingRange]
756
+ );
757
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
758
+ Box,
759
+ {
760
+ ref,
761
+ testID,
762
+ backgroundColor: theme.colors.background.secondary,
763
+ borderRadius: 8,
764
+ padding: 16,
765
+ overflow: "hidden",
766
+ style: {
767
+ boxShadow: "0px 4px 16px 0px rgba(7, 7, 8, 0.1)",
768
+ width: 312
769
+ },
770
+ children: [
771
+ topContent?.({ close: () => {
772
+ } }),
773
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
774
+ CalendarHeader,
775
+ {
776
+ monthDate: currentMonth,
777
+ decreaseMonth,
778
+ increaseMonth,
779
+ changeYear,
780
+ changeMonth,
781
+ locale,
782
+ minDate,
783
+ maxDate,
784
+ contextMenuMaxHeight
785
+ }
786
+ ),
787
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box, { flexDirection: "row", justifyContent: "space-between", marginBottom: 8, children: weekDays.map((day, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box, { width: 40, alignItems: "center", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { fontSize: 12, fontWeight: "600", color: theme.colors.content.tertiary, children: day.toUpperCase() }) }, i)) }),
788
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box, { gap: 2, children: weeks.map((week, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Box, { flexDirection: "row", justifyContent: "space-between", children: week.map((day, j) => {
789
+ const isOutsideMonth = !(0, import_date_fns2.isSameMonth)(day, currentMonth);
790
+ 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);
791
+ const isRangeStart = selectsRange && selectedStartDate && (0, import_date_fns2.isSameDay)(day, selectedStartDate);
792
+ const isRangeEnd = selectsRange && selectedEndDate && (0, import_date_fns2.isSameDay)(day, selectedEndDate);
793
+ const inRange = isDateInRange(day);
794
+ const today = (0, import_date_fns2.isToday)(day);
795
+ const disabled = isDateDisabled(day);
796
+ let bgColor = "transparent";
797
+ let textColor = theme.colors.content.primary;
798
+ if (isSelected || isRangeStart || isRangeEnd) {
799
+ bgColor = theme.colors.background.brand.primary;
800
+ textColor = theme.colors.content.on.brand;
801
+ } else if (inRange) {
802
+ bgColor = theme.colors.overlay.brand;
803
+ } else if (today) {
804
+ bgColor = theme.colors.overlay.mono;
805
+ }
806
+ if (isOutsideMonth || disabled) {
807
+ textColor = theme.colors.content.tertiary;
808
+ }
809
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
810
+ Box,
811
+ {
812
+ width: 40,
813
+ height: 32,
814
+ alignItems: "center",
815
+ justifyContent: "center",
816
+ borderRadius: isSelected || isRangeStart || isRangeEnd ? 4 : 0,
817
+ backgroundColor: bgColor,
818
+ cursor: disabled || isOutsideMonth ? "default" : "pointer",
819
+ onPress: () => !disabled && !isOutsideMonth && handleChange(day),
820
+ hoverStyle: !disabled && !isOutsideMonth && !isSelected ? { backgroundColor: theme.colors.overlay.mono } : void 0,
821
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Text, { color: textColor, fontSize: 14, fontWeight: isSelected || isRangeStart || isRangeEnd ? "600" : "400", children: (0, import_date_fns2.format)(day, "d") })
822
+ },
823
+ j
824
+ );
825
+ }) }, i)) }),
826
+ bottomContent?.({ close: () => {
827
+ } })
828
+ ]
829
+ }
830
+ );
831
+ }
832
+ );
833
+ Calendar.displayName = "Calendar";
834
+
835
+ // src/DatePicker.tsx
836
+ var import_jsx_runtime10 = require("react/jsx-runtime");
837
+ var DatePicker = (0, import_react6.forwardRef)(
838
+ ({
839
+ onChange,
840
+ size = "m",
841
+ locale = "enUS",
842
+ selectsRange = false,
843
+ startDate,
844
+ endDate,
845
+ selectedDate,
846
+ placeholder,
847
+ backgroundColor,
848
+ testID,
849
+ ...rest
850
+ }, ref) => {
851
+ const { theme } = (0, import_xui_core2.useDesignSystem)();
852
+ const [open, setOpen] = (0, import_react6.useState)(false);
853
+ const [inputValue, setInputValue] = (0, import_react6.useState)("");
854
+ const containerRef = (0, import_react6.useRef)(null);
855
+ const formatDateForDisplay = (date) => {
856
+ if (!date) return "";
857
+ try {
858
+ return (0, import_date_fns3.format)(date, "MM/dd/yyyy");
859
+ } catch {
860
+ return "";
861
+ }
862
+ };
863
+ const getDisplayValue = (0, import_react6.useCallback)(() => {
864
+ if (selectsRange) {
865
+ if (startDate && endDate) {
866
+ return `${formatDateForDisplay(startDate)} - ${formatDateForDisplay(endDate)}`;
867
+ } else if (startDate) {
868
+ return formatDateForDisplay(startDate);
869
+ }
870
+ return "";
871
+ } else {
872
+ return formatDateForDisplay(selectedDate);
873
+ }
874
+ }, [selectsRange, startDate, endDate, selectedDate]);
875
+ (0, import_react6.useEffect)(() => {
876
+ setInputValue(getDisplayValue());
877
+ }, [getDisplayValue]);
878
+ const handleInputChange = (text) => {
879
+ setInputValue(text);
880
+ };
881
+ const handleDateChange = (date) => {
882
+ if (!selectsRange) {
883
+ onChange?.(date);
884
+ setOpen(false);
885
+ } else {
886
+ const range = date;
887
+ onChange?.(range);
888
+ if (range[0] && range[1]) {
889
+ setOpen(false);
890
+ }
891
+ }
892
+ };
893
+ (0, import_react6.useEffect)(() => {
894
+ if (import_xui_core2.isNative) return;
895
+ const handleClickOutside = (event) => {
896
+ if (containerRef.current && !containerRef.current.contains(event.target)) {
897
+ setOpen(false);
898
+ }
899
+ };
900
+ document.addEventListener("mousedown", handleClickOutside);
901
+ return () => document.removeEventListener("mousedown", handleClickOutside);
902
+ }, []);
903
+ const renderCalendar = () => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
904
+ Calendar,
905
+ {
906
+ locale,
907
+ startDate,
908
+ endDate,
909
+ selectedDate,
910
+ onChange: handleDateChange,
911
+ selectsRange,
912
+ ...rest
913
+ }
914
+ );
915
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(Box, { ref: containerRef, position: "relative", width: "100%", children: [
916
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
917
+ import_xui_input.Input,
918
+ {
919
+ ...rest,
920
+ size,
921
+ placeholder: placeholder || (selectsRange ? "MM/DD/YYYY - MM/DD/YYYY" : "MM/DD/YYYY"),
922
+ value: inputValue,
923
+ onChangeText: handleInputChange,
924
+ onFocus: () => setOpen(true),
925
+ backgroundColor,
926
+ testID
927
+ }
928
+ ),
929
+ open && (import_xui_core2.isWeb ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
930
+ Box,
931
+ {
932
+ position: "absolute",
933
+ top: "100%",
934
+ left: 0,
935
+ marginTop: 4,
936
+ zIndex: 1e3,
937
+ children: renderCalendar()
938
+ }
939
+ ) : (
940
+ // Native implementation could use a Modal here
941
+ // For now, we just show it below the input if needed,
942
+ // but usually a bottom sheet or centered modal is better.
943
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Box, { marginTop: 4, children: renderCalendar() })
944
+ ))
945
+ ] });
946
+ }
947
+ );
948
+ DatePicker.displayName = "DatePicker";
949
+ // Annotate the CommonJS export names for ESM import in node:
950
+ 0 && (module.exports = {
951
+ Calendar,
952
+ DatePicker,
953
+ formatDate,
954
+ getMonthInLocale
955
+ });
956
+ //# sourceMappingURL=index.js.map