@kalyx/react 0.3.0 → 0.4.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/CHANGELOG.md +24 -0
- package/dist/index.cjs +102 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -4
- package/dist/index.d.ts +33 -4
- package/dist/index.js +103 -63
- package/dist/index.js.map +1 -1
- package/package.json +12 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createContext, forwardRef, useState, useCallback, useContext, useId, useRef, useMemo, useEffect } from 'react';
|
|
2
|
-
import { parseInputValue, formatTimeString, parseTimeString, getTime, DateFnsAdapter, DEFAULT_DATEPICKER_LABELS, getMonthName, getWeekdayNames, getCalendarDays, formatMonthYear, isDateDisabled, DEFAULT_RANGEPICKER_LABELS, DEFAULT_TIMEPICKER_LABELS, setTime, to12Hour, to24Hour, generateMinutes, generateHours, formatFullDate } from '@kalyx/core';
|
|
2
|
+
import { parseInputValue, formatTimeString, parseTimeString, getTimeInTimezone, getTime, DateFnsAdapter, DEFAULT_DATEPICKER_LABELS, civilMidnightFromUtcDay, getMonthName, getWeekdayNames, getCalendarDays, formatMonthYear, isDateDisabled, DEFAULT_RANGEPICKER_LABELS, DEFAULT_TIMEPICKER_LABELS, setTimeInTimezone, setTime, to12Hour, to24Hour, generateMinutes, generateHours, formatFullDate } from '@kalyx/core';
|
|
3
3
|
export { DateFnsAdapter } from '@kalyx/core';
|
|
4
4
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
5
|
import { useFloating, autoUpdate, offset, flip, shift } from '@floating-ui/react';
|
|
@@ -29,6 +29,7 @@ function DatePickerRoot({
|
|
|
29
29
|
weekStartsOn = 0,
|
|
30
30
|
displayFormat = "yyyy-MM-dd",
|
|
31
31
|
locale = "en-US",
|
|
32
|
+
displayTimezone,
|
|
32
33
|
adapter = DateFnsAdapter,
|
|
33
34
|
labels: labelsProp,
|
|
34
35
|
children
|
|
@@ -42,10 +43,10 @@ function DatePickerRoot({
|
|
|
42
43
|
const currentValue = isControlled ? controlledValue ?? null : uncontrolledValue;
|
|
43
44
|
const [isOpen, setIsOpen] = useState(false);
|
|
44
45
|
const [viewMonth, setViewMonth] = useState(
|
|
45
|
-
currentValue ?? adapter.today()
|
|
46
|
+
currentValue ?? adapter.today(displayTimezone)
|
|
46
47
|
);
|
|
47
48
|
const [focusedDate, setFocusedDate] = useState(
|
|
48
|
-
currentValue ?? adapter.today()
|
|
49
|
+
currentValue ?? adapter.today(displayTimezone)
|
|
49
50
|
);
|
|
50
51
|
const mergedLabels = useMemo(
|
|
51
52
|
() => ({ ...DEFAULT_DATEPICKER_LABELS, ...labelsProp }),
|
|
@@ -59,21 +60,22 @@ function DatePickerRoot({
|
|
|
59
60
|
const selectDate = useCallback(
|
|
60
61
|
(iso) => {
|
|
61
62
|
if (isDisabled || readOnly) return;
|
|
63
|
+
const normalized = iso && displayTimezone ? civilMidnightFromUtcDay(iso, displayTimezone) : iso;
|
|
62
64
|
if (!isControlled) {
|
|
63
|
-
setUncontrolledValue(
|
|
65
|
+
setUncontrolledValue(normalized);
|
|
64
66
|
}
|
|
65
|
-
onChange?.(
|
|
67
|
+
onChange?.(normalized);
|
|
66
68
|
setIsOpen(false);
|
|
67
69
|
},
|
|
68
|
-
[isControlled, isDisabled, readOnly, onChange]
|
|
70
|
+
[isControlled, isDisabled, readOnly, onChange, displayTimezone]
|
|
69
71
|
);
|
|
70
72
|
const open = useCallback(() => {
|
|
71
73
|
if (isDisabled || readOnly) return;
|
|
72
74
|
setIsOpen(true);
|
|
73
|
-
const target = currentValue ?? adapter.today();
|
|
75
|
+
const target = currentValue ?? adapter.today(displayTimezone);
|
|
74
76
|
setViewMonth(target);
|
|
75
77
|
setFocusedDate(target);
|
|
76
|
-
}, [isDisabled, readOnly, currentValue, adapter]);
|
|
78
|
+
}, [isDisabled, readOnly, currentValue, adapter, displayTimezone]);
|
|
77
79
|
const close = useCallback(() => {
|
|
78
80
|
setIsOpen(false);
|
|
79
81
|
}, []);
|
|
@@ -102,6 +104,7 @@ function DatePickerRoot({
|
|
|
102
104
|
weekStartsOn,
|
|
103
105
|
displayFormat,
|
|
104
106
|
locale,
|
|
107
|
+
displayTimezone,
|
|
105
108
|
isDisabled,
|
|
106
109
|
isReadOnly: readOnly,
|
|
107
110
|
pickerId,
|
|
@@ -121,6 +124,7 @@ function DatePickerRoot({
|
|
|
121
124
|
weekStartsOn,
|
|
122
125
|
displayFormat,
|
|
123
126
|
locale,
|
|
127
|
+
displayTimezone,
|
|
124
128
|
isDisabled,
|
|
125
129
|
readOnly,
|
|
126
130
|
pickerId,
|
|
@@ -137,7 +141,7 @@ var DatePickerInput = forwardRef(
|
|
|
137
141
|
let formattedValue = "";
|
|
138
142
|
if (ctx.value) {
|
|
139
143
|
try {
|
|
140
|
-
formattedValue = ctx.adapter.format(ctx.value, displayFormat);
|
|
144
|
+
formattedValue = ctx.adapter.format(ctx.value, displayFormat, ctx.displayTimezone);
|
|
141
145
|
} catch {
|
|
142
146
|
formattedValue = ctx.value;
|
|
143
147
|
}
|
|
@@ -385,13 +389,14 @@ function DatePickerCalendar({ classNames, onTitleClick, ...props }) {
|
|
|
385
389
|
const ctx = useDatePickerContext("DatePicker.Calendar");
|
|
386
390
|
const gridRef = useRef(null);
|
|
387
391
|
const [announcement, setAnnouncement] = useState("");
|
|
388
|
-
const { adapter, viewMonth, focusedDate, weekStartsOn, disabled, locale } = ctx;
|
|
392
|
+
const { adapter, viewMonth, focusedDate, weekStartsOn, disabled, locale, displayTimezone } = ctx;
|
|
389
393
|
const weekdays = getWeekdayNames(locale, weekStartsOn);
|
|
390
394
|
const weeks = getCalendarDays(viewMonth, adapter, {
|
|
391
395
|
weekStartsOn,
|
|
392
396
|
selected: ctx.value,
|
|
393
397
|
focusedDate,
|
|
394
|
-
disabled
|
|
398
|
+
disabled,
|
|
399
|
+
timezone: displayTimezone
|
|
395
400
|
});
|
|
396
401
|
const year = adapter.getYear(viewMonth);
|
|
397
402
|
const month = adapter.getMonth(viewMonth);
|
|
@@ -807,6 +812,7 @@ function RangePickerRoot({
|
|
|
807
812
|
weekStartsOn = 0,
|
|
808
813
|
displayFormat = "yyyy-MM-dd",
|
|
809
814
|
locale = "en-US",
|
|
815
|
+
displayTimezone,
|
|
810
816
|
adapter = DateFnsAdapter,
|
|
811
817
|
labels: labelsProp,
|
|
812
818
|
children
|
|
@@ -822,10 +828,10 @@ function RangePickerRoot({
|
|
|
822
828
|
const [selectingTarget, setSelectingTarget] = useState("start");
|
|
823
829
|
const [hoverDate, setHoverDate] = useState(null);
|
|
824
830
|
const [viewMonth, setViewMonth] = useState(
|
|
825
|
-
currentValue.start ?? adapter.today()
|
|
831
|
+
currentValue.start ?? adapter.today(displayTimezone)
|
|
826
832
|
);
|
|
827
833
|
const [focusedDate, setFocusedDate] = useState(
|
|
828
|
-
currentValue.start ?? adapter.today()
|
|
834
|
+
currentValue.start ?? adapter.today(displayTimezone)
|
|
829
835
|
);
|
|
830
836
|
const mergedLabels = useMemo(
|
|
831
837
|
() => ({ ...DEFAULT_RANGEPICKER_LABELS, ...labelsProp }),
|
|
@@ -849,23 +855,24 @@ function RangePickerRoot({
|
|
|
849
855
|
const selectDate = useCallback(
|
|
850
856
|
(iso) => {
|
|
851
857
|
if (isDisabled || readOnly) return;
|
|
858
|
+
const normalized = displayTimezone ? civilMidnightFromUtcDay(iso, displayTimezone) : iso;
|
|
852
859
|
if (selectingTarget === "start") {
|
|
853
|
-
const newRange = { start:
|
|
860
|
+
const newRange = { start: normalized, end: null };
|
|
854
861
|
setRange(newRange);
|
|
855
862
|
setSelectingTarget("end");
|
|
856
863
|
setHoverDate(null);
|
|
857
864
|
} else {
|
|
858
865
|
const start = currentValue.start;
|
|
859
866
|
if (!start) {
|
|
860
|
-
setRange({ start:
|
|
867
|
+
setRange({ start: normalized, end: null });
|
|
861
868
|
setSelectingTarget("end");
|
|
862
869
|
return;
|
|
863
870
|
}
|
|
864
871
|
let newRange;
|
|
865
|
-
if (adapter.isBefore(
|
|
866
|
-
newRange = { start:
|
|
872
|
+
if (adapter.isBefore(normalized, start)) {
|
|
873
|
+
newRange = { start: normalized, end: start };
|
|
867
874
|
} else {
|
|
868
|
-
newRange = { start, end:
|
|
875
|
+
newRange = { start, end: normalized };
|
|
869
876
|
}
|
|
870
877
|
setRange(newRange);
|
|
871
878
|
setSelectingTarget("start");
|
|
@@ -873,18 +880,18 @@ function RangePickerRoot({
|
|
|
873
880
|
setIsOpen(false);
|
|
874
881
|
}
|
|
875
882
|
},
|
|
876
|
-
[isDisabled, readOnly, selectingTarget, currentValue.start, adapter, setRange]
|
|
883
|
+
[isDisabled, readOnly, selectingTarget, currentValue.start, adapter, setRange, displayTimezone]
|
|
877
884
|
);
|
|
878
885
|
const open = useCallback(() => {
|
|
879
886
|
if (isDisabled || readOnly) return;
|
|
880
887
|
setIsOpen(true);
|
|
881
|
-
const target = currentValue.start ?? adapter.today();
|
|
888
|
+
const target = currentValue.start ?? adapter.today(displayTimezone);
|
|
882
889
|
setViewMonth(target);
|
|
883
890
|
setFocusedDate(target);
|
|
884
891
|
if (currentValue.start && currentValue.end) {
|
|
885
892
|
setSelectingTarget("start");
|
|
886
893
|
}
|
|
887
|
-
}, [isDisabled, readOnly, currentValue, adapter]);
|
|
894
|
+
}, [isDisabled, readOnly, currentValue, adapter, displayTimezone]);
|
|
888
895
|
const close = useCallback(() => {
|
|
889
896
|
setIsOpen(false);
|
|
890
897
|
setHoverDate(null);
|
|
@@ -915,6 +922,7 @@ function RangePickerRoot({
|
|
|
915
922
|
weekStartsOn,
|
|
916
923
|
displayFormat,
|
|
917
924
|
locale,
|
|
925
|
+
displayTimezone,
|
|
918
926
|
isDisabled,
|
|
919
927
|
isReadOnly: readOnly,
|
|
920
928
|
pickerId,
|
|
@@ -937,6 +945,7 @@ function RangePickerRoot({
|
|
|
937
945
|
weekStartsOn,
|
|
938
946
|
displayFormat,
|
|
939
947
|
locale,
|
|
948
|
+
displayTimezone,
|
|
940
949
|
isDisabled,
|
|
941
950
|
readOnly,
|
|
942
951
|
pickerId,
|
|
@@ -953,7 +962,7 @@ var RangePickerInput = forwardRef(
|
|
|
953
962
|
let displayValue = "";
|
|
954
963
|
if (value) {
|
|
955
964
|
try {
|
|
956
|
-
displayValue = ctx.adapter.format(value, displayFormat);
|
|
965
|
+
displayValue = ctx.adapter.format(value, displayFormat, ctx.displayTimezone);
|
|
957
966
|
} catch {
|
|
958
967
|
displayValue = value;
|
|
959
968
|
}
|
|
@@ -1058,7 +1067,8 @@ function RangePickerCalendar({ classNames, ...props }) {
|
|
|
1058
1067
|
disabled,
|
|
1059
1068
|
value,
|
|
1060
1069
|
hoverDate,
|
|
1061
|
-
selectingTarget
|
|
1070
|
+
selectingTarget,
|
|
1071
|
+
displayTimezone
|
|
1062
1072
|
} = ctx;
|
|
1063
1073
|
const { locale } = ctx;
|
|
1064
1074
|
const weekdays = getWeekdayNames(locale, weekStartsOn);
|
|
@@ -1067,7 +1077,8 @@ function RangePickerCalendar({ classNames, ...props }) {
|
|
|
1067
1077
|
focusedDate,
|
|
1068
1078
|
disabled,
|
|
1069
1079
|
range: value,
|
|
1070
|
-
rangeHover: hoverDate
|
|
1080
|
+
rangeHover: hoverDate,
|
|
1081
|
+
timezone: displayTimezone
|
|
1071
1082
|
});
|
|
1072
1083
|
const year = adapter.getYear(viewMonth);
|
|
1073
1084
|
const month = adapter.getMonth(viewMonth);
|
|
@@ -1390,6 +1401,7 @@ function TimePickerRoot({
|
|
|
1390
1401
|
format = "24h",
|
|
1391
1402
|
step = 1,
|
|
1392
1403
|
withSeconds = false,
|
|
1404
|
+
displayTimezone,
|
|
1393
1405
|
disabled = false,
|
|
1394
1406
|
readOnly = false,
|
|
1395
1407
|
labels: labelsProp,
|
|
@@ -1406,17 +1418,20 @@ function TimePickerRoot({
|
|
|
1406
1418
|
);
|
|
1407
1419
|
const currentValue = isControlled ? controlledValue ?? null : uncontrolledValue;
|
|
1408
1420
|
const baseIso = currentValue ?? getDefaultIso();
|
|
1409
|
-
const currentTime = useMemo(
|
|
1421
|
+
const currentTime = useMemo(
|
|
1422
|
+
() => displayTimezone ? getTimeInTimezone(baseIso, displayTimezone) : getTime(baseIso),
|
|
1423
|
+
[baseIso, displayTimezone]
|
|
1424
|
+
);
|
|
1410
1425
|
const setTime$1 = useCallback(
|
|
1411
1426
|
(partial) => {
|
|
1412
1427
|
if (disabled || readOnly) return;
|
|
1413
|
-
const newIso = setTime(baseIso, partial);
|
|
1428
|
+
const newIso = displayTimezone ? setTimeInTimezone(baseIso, partial, displayTimezone) : setTime(baseIso, partial);
|
|
1414
1429
|
if (!isControlled) {
|
|
1415
1430
|
setUncontrolledValue(newIso);
|
|
1416
1431
|
}
|
|
1417
1432
|
onChange?.(newIso);
|
|
1418
1433
|
},
|
|
1419
|
-
[disabled, readOnly, baseIso, isControlled, onChange]
|
|
1434
|
+
[disabled, readOnly, baseIso, isControlled, onChange, displayTimezone]
|
|
1420
1435
|
);
|
|
1421
1436
|
const contextValue = useMemo(
|
|
1422
1437
|
() => ({
|
|
@@ -1425,13 +1440,14 @@ function TimePickerRoot({
|
|
|
1425
1440
|
format,
|
|
1426
1441
|
step,
|
|
1427
1442
|
withSeconds,
|
|
1443
|
+
displayTimezone,
|
|
1428
1444
|
isDisabled: disabled,
|
|
1429
1445
|
isReadOnly: readOnly,
|
|
1430
1446
|
currentTime,
|
|
1431
1447
|
pickerId,
|
|
1432
1448
|
labels: mergedLabels
|
|
1433
1449
|
}),
|
|
1434
|
-
[currentValue, setTime$1, format, step, withSeconds, disabled, readOnly, currentTime, pickerId, mergedLabels]
|
|
1450
|
+
[currentValue, setTime$1, format, step, withSeconds, displayTimezone, disabled, readOnly, currentTime, pickerId, mergedLabels]
|
|
1435
1451
|
);
|
|
1436
1452
|
return /* @__PURE__ */ jsx(TimePickerContext.Provider, { value: contextValue, children });
|
|
1437
1453
|
}
|
|
@@ -1692,6 +1708,7 @@ function DateTimePickerRoot({
|
|
|
1692
1708
|
weekStartsOn = 0,
|
|
1693
1709
|
displayFormat = "yyyy-MM-dd HH:mm",
|
|
1694
1710
|
locale = "en-US",
|
|
1711
|
+
displayTimezone,
|
|
1695
1712
|
adapter = DateFnsAdapter,
|
|
1696
1713
|
labels: labelsProp,
|
|
1697
1714
|
children
|
|
@@ -1713,10 +1730,10 @@ function DateTimePickerRoot({
|
|
|
1713
1730
|
const currentValue = isControlled ? controlledValue ?? null : uncontrolledValue;
|
|
1714
1731
|
const [isOpen, setIsOpen] = useState(false);
|
|
1715
1732
|
const [viewMonth, setViewMonth] = useState(
|
|
1716
|
-
currentValue ?? adapter.today()
|
|
1733
|
+
currentValue ?? adapter.today(displayTimezone)
|
|
1717
1734
|
);
|
|
1718
1735
|
const [focusedDate, setFocusedDate] = useState(
|
|
1719
|
-
currentValue ?? adapter.today()
|
|
1736
|
+
currentValue ?? adapter.today(displayTimezone)
|
|
1720
1737
|
);
|
|
1721
1738
|
const isDisabled = typeof disabled === "boolean" ? disabled : false;
|
|
1722
1739
|
const disabledRules = useMemo(
|
|
@@ -1724,7 +1741,10 @@ function DateTimePickerRoot({
|
|
|
1724
1741
|
[disabled]
|
|
1725
1742
|
);
|
|
1726
1743
|
const baseIso = currentValue ?? getDefaultIso2();
|
|
1727
|
-
const currentTime = useMemo(
|
|
1744
|
+
const currentTime = useMemo(
|
|
1745
|
+
() => displayTimezone ? getTimeInTimezone(baseIso, displayTimezone) : getTime(baseIso),
|
|
1746
|
+
[baseIso, displayTimezone]
|
|
1747
|
+
);
|
|
1728
1748
|
const updateValue = useCallback(
|
|
1729
1749
|
(next) => {
|
|
1730
1750
|
if (isDisabled || readOnly) return;
|
|
@@ -1741,27 +1761,28 @@ function DateTimePickerRoot({
|
|
|
1741
1761
|
updateValue(null);
|
|
1742
1762
|
return;
|
|
1743
1763
|
}
|
|
1744
|
-
const
|
|
1745
|
-
const
|
|
1764
|
+
const normalizedDate = displayTimezone ? civilMidnightFromUtcDay(newDateIso, displayTimezone) : newDateIso;
|
|
1765
|
+
const time = currentValue ? displayTimezone ? getTimeInTimezone(currentValue, displayTimezone) : getTime(currentValue) : currentTime;
|
|
1766
|
+
const merged = displayTimezone ? setTimeInTimezone(normalizedDate, time, displayTimezone) : setTime(normalizedDate, time);
|
|
1746
1767
|
updateValue(merged);
|
|
1747
1768
|
},
|
|
1748
|
-
[currentValue, currentTime, updateValue]
|
|
1769
|
+
[currentValue, currentTime, updateValue, displayTimezone]
|
|
1749
1770
|
);
|
|
1750
1771
|
const setTime$1 = useCallback(
|
|
1751
1772
|
(partial) => {
|
|
1752
1773
|
const base = currentValue ?? getDefaultIso2();
|
|
1753
|
-
const merged = setTime(base, partial);
|
|
1774
|
+
const merged = displayTimezone ? setTimeInTimezone(base, partial, displayTimezone) : setTime(base, partial);
|
|
1754
1775
|
updateValue(merged);
|
|
1755
1776
|
},
|
|
1756
|
-
[currentValue, updateValue]
|
|
1777
|
+
[currentValue, updateValue, displayTimezone]
|
|
1757
1778
|
);
|
|
1758
1779
|
const open = useCallback(() => {
|
|
1759
1780
|
if (isDisabled || readOnly) return;
|
|
1760
1781
|
setIsOpen(true);
|
|
1761
|
-
const target = currentValue ?? adapter.today();
|
|
1782
|
+
const target = currentValue ?? adapter.today(displayTimezone);
|
|
1762
1783
|
setViewMonth(target);
|
|
1763
1784
|
setFocusedDate(target);
|
|
1764
|
-
}, [isDisabled, readOnly, currentValue, adapter]);
|
|
1785
|
+
}, [isDisabled, readOnly, currentValue, adapter, displayTimezone]);
|
|
1765
1786
|
const close = useCallback(() => {
|
|
1766
1787
|
setIsOpen(false);
|
|
1767
1788
|
}, []);
|
|
@@ -1787,6 +1808,7 @@ function DateTimePickerRoot({
|
|
|
1787
1808
|
weekStartsOn,
|
|
1788
1809
|
displayFormat,
|
|
1789
1810
|
locale,
|
|
1811
|
+
displayTimezone,
|
|
1790
1812
|
isDisabled,
|
|
1791
1813
|
isReadOnly: readOnly,
|
|
1792
1814
|
pickerId,
|
|
@@ -1806,6 +1828,7 @@ function DateTimePickerRoot({
|
|
|
1806
1828
|
weekStartsOn,
|
|
1807
1829
|
displayFormat,
|
|
1808
1830
|
locale,
|
|
1831
|
+
displayTimezone,
|
|
1809
1832
|
isDisabled,
|
|
1810
1833
|
readOnly,
|
|
1811
1834
|
pickerId,
|
|
@@ -1819,13 +1842,14 @@ function DateTimePickerRoot({
|
|
|
1819
1842
|
format,
|
|
1820
1843
|
step,
|
|
1821
1844
|
withSeconds: false,
|
|
1845
|
+
displayTimezone,
|
|
1822
1846
|
isDisabled,
|
|
1823
1847
|
isReadOnly: readOnly,
|
|
1824
1848
|
currentTime,
|
|
1825
1849
|
pickerId,
|
|
1826
1850
|
labels: mergedTimeLabels
|
|
1827
1851
|
}),
|
|
1828
|
-
[currentValue, setTime$1, format, step, isDisabled, readOnly, currentTime, pickerId, mergedTimeLabels]
|
|
1852
|
+
[currentValue, setTime$1, format, step, displayTimezone, isDisabled, readOnly, currentTime, pickerId, mergedTimeLabels]
|
|
1829
1853
|
);
|
|
1830
1854
|
return /* @__PURE__ */ jsx(DatePickerContext.Provider, { value: dateContext, children: /* @__PURE__ */ jsx(TimePickerContext.Provider, { value: timeContext, children }) });
|
|
1831
1855
|
}
|
|
@@ -1835,7 +1859,9 @@ var DateTimePickerInput = forwardRef(
|
|
|
1835
1859
|
let displayValue = "";
|
|
1836
1860
|
if (ctx.value) {
|
|
1837
1861
|
try {
|
|
1838
|
-
|
|
1862
|
+
const datePart = ctx.adapter.format(ctx.value, "yyyy-MM-dd", ctx.displayTimezone);
|
|
1863
|
+
const time = ctx.displayTimezone ? getTimeInTimezone(ctx.value, ctx.displayTimezone) : getTime(ctx.value);
|
|
1864
|
+
displayValue = `${datePart} ${formatTimeString(time)}`;
|
|
1839
1865
|
} catch {
|
|
1840
1866
|
displayValue = ctx.value;
|
|
1841
1867
|
}
|
|
@@ -1905,7 +1931,8 @@ function useDatePicker(options = {}) {
|
|
|
1905
1931
|
onChange,
|
|
1906
1932
|
disabled = [],
|
|
1907
1933
|
weekStartsOn = 0,
|
|
1908
|
-
adapter = DateFnsAdapter
|
|
1934
|
+
adapter = DateFnsAdapter,
|
|
1935
|
+
displayTimezone
|
|
1909
1936
|
} = options;
|
|
1910
1937
|
const pickerId = useId();
|
|
1911
1938
|
const isControlled = useRef(controlledValue !== void 0).current;
|
|
@@ -1914,24 +1941,29 @@ function useDatePicker(options = {}) {
|
|
|
1914
1941
|
);
|
|
1915
1942
|
const currentValue = isControlled ? controlledValue ?? null : uncontrolledValue;
|
|
1916
1943
|
const [isOpen, setIsOpen] = useState(false);
|
|
1917
|
-
const [viewMonth, setViewMonth] = useState(
|
|
1918
|
-
|
|
1944
|
+
const [viewMonth, setViewMonth] = useState(
|
|
1945
|
+
currentValue ?? adapter.today(displayTimezone)
|
|
1946
|
+
);
|
|
1947
|
+
const [focusedDate, setFocusedDate] = useState(
|
|
1948
|
+
currentValue ?? adapter.today(displayTimezone)
|
|
1949
|
+
);
|
|
1919
1950
|
const selectDate = useCallback(
|
|
1920
1951
|
(iso) => {
|
|
1952
|
+
const normalized = iso && displayTimezone ? civilMidnightFromUtcDay(iso, displayTimezone) : iso;
|
|
1921
1953
|
if (!isControlled) {
|
|
1922
|
-
setUncontrolledValue(
|
|
1954
|
+
setUncontrolledValue(normalized);
|
|
1923
1955
|
}
|
|
1924
|
-
onChange?.(
|
|
1956
|
+
onChange?.(normalized);
|
|
1925
1957
|
setIsOpen(false);
|
|
1926
1958
|
},
|
|
1927
|
-
[isControlled, onChange]
|
|
1959
|
+
[isControlled, onChange, displayTimezone]
|
|
1928
1960
|
);
|
|
1929
1961
|
const open = useCallback(() => {
|
|
1930
1962
|
setIsOpen(true);
|
|
1931
|
-
const target = currentValue ?? adapter.today();
|
|
1963
|
+
const target = currentValue ?? adapter.today(displayTimezone);
|
|
1932
1964
|
setViewMonth(target);
|
|
1933
1965
|
setFocusedDate(target);
|
|
1934
|
-
}, [currentValue, adapter]);
|
|
1966
|
+
}, [currentValue, adapter, displayTimezone]);
|
|
1935
1967
|
const close = useCallback(() => {
|
|
1936
1968
|
setIsOpen(false);
|
|
1937
1969
|
}, []);
|
|
@@ -1953,7 +1985,8 @@ function useDatePicker(options = {}) {
|
|
|
1953
1985
|
weekStartsOn,
|
|
1954
1986
|
selected: currentValue,
|
|
1955
1987
|
focusedDate,
|
|
1956
|
-
disabled
|
|
1988
|
+
disabled,
|
|
1989
|
+
timezone: displayTimezone
|
|
1957
1990
|
});
|
|
1958
1991
|
return {
|
|
1959
1992
|
value: currentValue,
|
|
@@ -1981,7 +2014,8 @@ function useRangePicker(options = {}) {
|
|
|
1981
2014
|
onChange,
|
|
1982
2015
|
disabled = [],
|
|
1983
2016
|
weekStartsOn = 0,
|
|
1984
|
-
adapter = DateFnsAdapter
|
|
2017
|
+
adapter = DateFnsAdapter,
|
|
2018
|
+
displayTimezone
|
|
1985
2019
|
} = options;
|
|
1986
2020
|
const pickerId = useId();
|
|
1987
2021
|
const isControlled = useRef(controlledValue !== void 0).current;
|
|
@@ -1993,10 +2027,10 @@ function useRangePicker(options = {}) {
|
|
|
1993
2027
|
const [selectingTarget, setSelectingTarget] = useState("start");
|
|
1994
2028
|
const [hoverDate, setHoverDate] = useState(null);
|
|
1995
2029
|
const [viewMonth, setViewMonth] = useState(
|
|
1996
|
-
currentValue.start ?? adapter.today()
|
|
2030
|
+
currentValue.start ?? adapter.today(displayTimezone)
|
|
1997
2031
|
);
|
|
1998
2032
|
const [focusedDate, setFocusedDate] = useState(
|
|
1999
|
-
currentValue.start ?? adapter.today()
|
|
2033
|
+
currentValue.start ?? adapter.today(displayTimezone)
|
|
2000
2034
|
);
|
|
2001
2035
|
const setRange = useCallback(
|
|
2002
2036
|
(range) => {
|
|
@@ -2009,35 +2043,36 @@ function useRangePicker(options = {}) {
|
|
|
2009
2043
|
);
|
|
2010
2044
|
const selectDate = useCallback(
|
|
2011
2045
|
(iso) => {
|
|
2046
|
+
const normalized = displayTimezone ? civilMidnightFromUtcDay(iso, displayTimezone) : iso;
|
|
2012
2047
|
if (selectingTarget === "start") {
|
|
2013
|
-
setRange({ start:
|
|
2048
|
+
setRange({ start: normalized, end: null });
|
|
2014
2049
|
setSelectingTarget("end");
|
|
2015
2050
|
setHoverDate(null);
|
|
2016
2051
|
} else {
|
|
2017
2052
|
const start = currentValue.start;
|
|
2018
2053
|
if (!start) {
|
|
2019
|
-
setRange({ start:
|
|
2054
|
+
setRange({ start: normalized, end: null });
|
|
2020
2055
|
setSelectingTarget("end");
|
|
2021
2056
|
return;
|
|
2022
2057
|
}
|
|
2023
|
-
const newRange = adapter.isBefore(
|
|
2058
|
+
const newRange = adapter.isBefore(normalized, start) ? { start: normalized, end: start } : { start, end: normalized };
|
|
2024
2059
|
setRange(newRange);
|
|
2025
2060
|
setSelectingTarget("start");
|
|
2026
2061
|
setHoverDate(null);
|
|
2027
2062
|
setIsOpen(false);
|
|
2028
2063
|
}
|
|
2029
2064
|
},
|
|
2030
|
-
[selectingTarget, currentValue.start, adapter, setRange]
|
|
2065
|
+
[selectingTarget, currentValue.start, adapter, setRange, displayTimezone]
|
|
2031
2066
|
);
|
|
2032
2067
|
const open = useCallback(() => {
|
|
2033
2068
|
setIsOpen(true);
|
|
2034
|
-
const target = currentValue.start ?? adapter.today();
|
|
2069
|
+
const target = currentValue.start ?? adapter.today(displayTimezone);
|
|
2035
2070
|
setViewMonth(target);
|
|
2036
2071
|
setFocusedDate(target);
|
|
2037
2072
|
if (currentValue.start && currentValue.end) {
|
|
2038
2073
|
setSelectingTarget("start");
|
|
2039
2074
|
}
|
|
2040
|
-
}, [currentValue, adapter]);
|
|
2075
|
+
}, [currentValue, adapter, displayTimezone]);
|
|
2041
2076
|
const close = useCallback(() => {
|
|
2042
2077
|
setIsOpen(false);
|
|
2043
2078
|
setHoverDate(null);
|
|
@@ -2061,7 +2096,8 @@ function useRangePicker(options = {}) {
|
|
|
2061
2096
|
focusedDate,
|
|
2062
2097
|
disabled,
|
|
2063
2098
|
range: currentValue,
|
|
2064
|
-
rangeHover: hoverDate
|
|
2099
|
+
rangeHover: hoverDate,
|
|
2100
|
+
timezone: displayTimezone
|
|
2065
2101
|
});
|
|
2066
2102
|
return {
|
|
2067
2103
|
value: currentValue,
|
|
@@ -2094,7 +2130,8 @@ function useTimePicker(options = {}) {
|
|
|
2094
2130
|
defaultValue,
|
|
2095
2131
|
onChange,
|
|
2096
2132
|
format = "24h",
|
|
2097
|
-
step = 1
|
|
2133
|
+
step = 1,
|
|
2134
|
+
displayTimezone
|
|
2098
2135
|
} = options;
|
|
2099
2136
|
const pickerId = useId();
|
|
2100
2137
|
const isControlled = useRef(controlledValue !== void 0).current;
|
|
@@ -2103,16 +2140,19 @@ function useTimePicker(options = {}) {
|
|
|
2103
2140
|
);
|
|
2104
2141
|
const currentValue = isControlled ? controlledValue ?? null : uncontrolledValue;
|
|
2105
2142
|
const baseIso = currentValue ?? getDefaultIso3();
|
|
2106
|
-
const currentTime = useMemo(
|
|
2143
|
+
const currentTime = useMemo(
|
|
2144
|
+
() => displayTimezone ? getTimeInTimezone(baseIso, displayTimezone) : getTime(baseIso),
|
|
2145
|
+
[baseIso, displayTimezone]
|
|
2146
|
+
);
|
|
2107
2147
|
const setTime$1 = useCallback(
|
|
2108
2148
|
(partial) => {
|
|
2109
|
-
const newIso = setTime(baseIso, partial);
|
|
2149
|
+
const newIso = displayTimezone ? setTimeInTimezone(baseIso, partial, displayTimezone) : setTime(baseIso, partial);
|
|
2110
2150
|
if (!isControlled) {
|
|
2111
2151
|
setUncontrolledValue(newIso);
|
|
2112
2152
|
}
|
|
2113
2153
|
onChange?.(newIso);
|
|
2114
2154
|
},
|
|
2115
|
-
[baseIso, isControlled, onChange]
|
|
2155
|
+
[baseIso, isControlled, onChange, displayTimezone]
|
|
2116
2156
|
);
|
|
2117
2157
|
const period = format === "12h" ? to12Hour(currentTime.hours).period : null;
|
|
2118
2158
|
const displayHour = format === "12h" ? to12Hour(currentTime.hours).hours12 : currentTime.hours;
|