@zendeskgarden/react-datepickers 8.74.0 → 8.74.2
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/dist/index.cjs.js +83 -101
- package/dist/index.esm.js +29 -29
- package/package.json +5 -5
package/dist/index.cjs.js
CHANGED
|
@@ -55,24 +55,6 @@ function _interopNamespace(e) {
|
|
|
55
55
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
56
56
|
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
|
|
57
57
|
var styled__default = /*#__PURE__*/_interopDefault(styled);
|
|
58
|
-
var startOfMonth__default = /*#__PURE__*/_interopDefault(startOfMonth);
|
|
59
|
-
var endOfMonth__default = /*#__PURE__*/_interopDefault(endOfMonth);
|
|
60
|
-
var startOfWeek__default = /*#__PURE__*/_interopDefault(startOfWeek);
|
|
61
|
-
var endOfWeek__default = /*#__PURE__*/_interopDefault(endOfWeek);
|
|
62
|
-
var eachDayOfInterval__default = /*#__PURE__*/_interopDefault(eachDayOfInterval);
|
|
63
|
-
var addDays__default = /*#__PURE__*/_interopDefault(addDays);
|
|
64
|
-
var isToday__default = /*#__PURE__*/_interopDefault(isToday);
|
|
65
|
-
var isSameDay__default = /*#__PURE__*/_interopDefault(isSameDay);
|
|
66
|
-
var isSameMonth__default = /*#__PURE__*/_interopDefault(isSameMonth);
|
|
67
|
-
var isBefore__default = /*#__PURE__*/_interopDefault(isBefore);
|
|
68
|
-
var isAfter__default = /*#__PURE__*/_interopDefault(isAfter);
|
|
69
|
-
var getDate__default = /*#__PURE__*/_interopDefault(getDate);
|
|
70
|
-
var addMonths__default = /*#__PURE__*/_interopDefault(addMonths);
|
|
71
|
-
var subMonths__default = /*#__PURE__*/_interopDefault(subMonths);
|
|
72
|
-
var isValid__default = /*#__PURE__*/_interopDefault(isValid);
|
|
73
|
-
var parse__default = /*#__PURE__*/_interopDefault(parse);
|
|
74
|
-
var compareAsc__default = /*#__PURE__*/_interopDefault(compareAsc);
|
|
75
|
-
var subDays__default = /*#__PURE__*/_interopDefault(subDays);
|
|
76
58
|
|
|
77
59
|
const WEEK_STARTS_ON = [0, 1, 2, 3, 4, 5, 6];
|
|
78
60
|
const SHARED_PLACEMENT = ['auto', 'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end'];
|
|
@@ -130,7 +112,7 @@ function getMenuPosition(popperPlacement) {
|
|
|
130
112
|
const COMPONENT_ID$b = 'datepickers.menu';
|
|
131
113
|
const StyledMenu = styled__default.default.div.attrs({
|
|
132
114
|
'data-garden-id': COMPONENT_ID$b,
|
|
133
|
-
'data-garden-version': '8.74.
|
|
115
|
+
'data-garden-version': '8.74.2'
|
|
134
116
|
}).withConfig({
|
|
135
117
|
displayName: "StyledMenu",
|
|
136
118
|
componentId: "sc-1npbkk0-0"
|
|
@@ -538,12 +520,12 @@ const Calendar$1 = React.forwardRef((_ref, ref) => {
|
|
|
538
520
|
dispatch
|
|
539
521
|
} = useDatepickerContext$1();
|
|
540
522
|
const preferredWeekStartsOn = weekStartsOn || getStartOfWeek(locale);
|
|
541
|
-
const monthStartDate =
|
|
542
|
-
const monthEndDate =
|
|
543
|
-
const startDate =
|
|
523
|
+
const monthStartDate = startOfMonth.startOfMonth(state.previewDate);
|
|
524
|
+
const monthEndDate = endOfMonth.endOfMonth(monthStartDate);
|
|
525
|
+
const startDate = startOfWeek.startOfWeek(monthStartDate, {
|
|
544
526
|
weekStartsOn: preferredWeekStartsOn
|
|
545
527
|
});
|
|
546
|
-
const endDate =
|
|
528
|
+
const endDate = endOfWeek.endOfWeek(monthEndDate, {
|
|
547
529
|
weekStartsOn: preferredWeekStartsOn
|
|
548
530
|
});
|
|
549
531
|
const dayLabelFormatter = React.useCallback(date => {
|
|
@@ -552,9 +534,9 @@ const Calendar$1 = React.forwardRef((_ref, ref) => {
|
|
|
552
534
|
});
|
|
553
535
|
return formatter.format(date);
|
|
554
536
|
}, [locale]);
|
|
555
|
-
const dayLabels =
|
|
537
|
+
const dayLabels = eachDayOfInterval.eachDayOfInterval({
|
|
556
538
|
start: startDate,
|
|
557
|
-
end:
|
|
539
|
+
end: addDays.addDays(startDate, 6)
|
|
558
540
|
}).map(date => {
|
|
559
541
|
const formattedDayLabel = dayLabelFormatter(date);
|
|
560
542
|
return React__namespace.default.createElement(StyledCalendarItem, {
|
|
@@ -564,20 +546,20 @@ const Calendar$1 = React.forwardRef((_ref, ref) => {
|
|
|
564
546
|
isCompact: isCompact
|
|
565
547
|
}, formattedDayLabel));
|
|
566
548
|
});
|
|
567
|
-
const items =
|
|
549
|
+
const items = eachDayOfInterval.eachDayOfInterval({
|
|
568
550
|
start: startDate,
|
|
569
551
|
end: endDate
|
|
570
552
|
}).map((date, itemsIndex) => {
|
|
571
|
-
const formattedDayLabel =
|
|
572
|
-
const isCurrentDate =
|
|
573
|
-
const isPreviousMonth = !
|
|
574
|
-
const isSelected = value &&
|
|
553
|
+
const formattedDayLabel = getDate.getDate(date);
|
|
554
|
+
const isCurrentDate = isToday.isToday(date);
|
|
555
|
+
const isPreviousMonth = !isSameMonth.isSameMonth(date, state.previewDate);
|
|
556
|
+
const isSelected = value && isSameDay.isSameDay(date, value);
|
|
575
557
|
let isDisabled = false;
|
|
576
558
|
if (minValue !== undefined) {
|
|
577
|
-
isDisabled =
|
|
559
|
+
isDisabled = isBefore.isBefore(date, minValue) && !isSameDay.isSameDay(date, minValue);
|
|
578
560
|
}
|
|
579
561
|
if (maxValue !== undefined) {
|
|
580
|
-
isDisabled = isDisabled ||
|
|
562
|
+
isDisabled = isDisabled || isAfter.isAfter(date, maxValue) && !isSameDay.isSameDay(date, maxValue);
|
|
581
563
|
}
|
|
582
564
|
return React__namespace.default.createElement(StyledCalendarItem, {
|
|
583
565
|
key: `day-${itemsIndex}`,
|
|
@@ -622,16 +604,16 @@ function parseInputValue$1(_ref) {
|
|
|
622
604
|
return customParseDate(inputValue);
|
|
623
605
|
}
|
|
624
606
|
const MINIMUM_DATE = new Date(1001, 0, 0);
|
|
625
|
-
let tryParseDate =
|
|
626
|
-
if (
|
|
607
|
+
let tryParseDate = parse.parse(inputValue, 'P', new Date());
|
|
608
|
+
if (isValid.isValid(tryParseDate) && !isBefore.isBefore(tryParseDate, MINIMUM_DATE)) {
|
|
627
609
|
return tryParseDate;
|
|
628
610
|
}
|
|
629
|
-
tryParseDate =
|
|
630
|
-
if (
|
|
611
|
+
tryParseDate = parse.parse(inputValue, 'PP', new Date());
|
|
612
|
+
if (isValid.isValid(tryParseDate) && !isBefore.isBefore(tryParseDate, MINIMUM_DATE)) {
|
|
631
613
|
return tryParseDate;
|
|
632
614
|
}
|
|
633
|
-
tryParseDate =
|
|
634
|
-
if (
|
|
615
|
+
tryParseDate = parse.parse(inputValue, 'PPP', new Date());
|
|
616
|
+
if (isValid.isValid(tryParseDate) && !isBefore.isBefore(tryParseDate, MINIMUM_DATE)) {
|
|
635
617
|
return tryParseDate;
|
|
636
618
|
}
|
|
637
619
|
return new Date(NaN);
|
|
@@ -685,7 +667,7 @@ const datepickerReducer = _ref3 => {
|
|
|
685
667
|
}
|
|
686
668
|
case 'PREVIEW_NEXT_MONTH':
|
|
687
669
|
{
|
|
688
|
-
const previewDate =
|
|
670
|
+
const previewDate = addMonths.addMonths(state.previewDate, 1);
|
|
689
671
|
return {
|
|
690
672
|
...state,
|
|
691
673
|
previewDate
|
|
@@ -693,7 +675,7 @@ const datepickerReducer = _ref3 => {
|
|
|
693
675
|
}
|
|
694
676
|
case 'PREVIEW_PREVIOUS_MONTH':
|
|
695
677
|
{
|
|
696
|
-
const previewDate =
|
|
678
|
+
const previewDate = subMonths.subMonths(state.previewDate, 1);
|
|
697
679
|
return {
|
|
698
680
|
...state,
|
|
699
681
|
previewDate
|
|
@@ -706,7 +688,7 @@ const datepickerReducer = _ref3 => {
|
|
|
706
688
|
inputValue,
|
|
707
689
|
customParseDate
|
|
708
690
|
});
|
|
709
|
-
if (onChange && currentDate &&
|
|
691
|
+
if (onChange && currentDate && isValid.isValid(currentDate) && !isSameDay.isSameDay(value, currentDate)) {
|
|
710
692
|
onChange(currentDate);
|
|
711
693
|
}
|
|
712
694
|
return {
|
|
@@ -748,7 +730,7 @@ const datepickerReducer = _ref3 => {
|
|
|
748
730
|
locale,
|
|
749
731
|
formatDate
|
|
750
732
|
});
|
|
751
|
-
if (onChange && action.value &&
|
|
733
|
+
if (onChange && action.value && isValid.isValid(action.value) && !isSameDay.isSameDay(value, action.value)) {
|
|
752
734
|
onChange(action.value);
|
|
753
735
|
}
|
|
754
736
|
return {
|
|
@@ -764,7 +746,7 @@ const datepickerReducer = _ref3 => {
|
|
|
764
746
|
};
|
|
765
747
|
function retrieveInitialState$1(initialProps) {
|
|
766
748
|
let previewDate = initialProps.value;
|
|
767
|
-
if (previewDate === undefined || !
|
|
749
|
+
if (previewDate === undefined || !isValid.isValid(previewDate)) {
|
|
768
750
|
previewDate = new Date();
|
|
769
751
|
}
|
|
770
752
|
let inputValue = '';
|
|
@@ -890,16 +872,16 @@ const Datepicker = React.forwardRef((props, calendarRef) => {
|
|
|
890
872
|
});
|
|
891
873
|
}),
|
|
892
874
|
onKeyDown: containerUtilities.composeEventHandlers(childElement.props.onKeyDown, e => {
|
|
893
|
-
switch (e.
|
|
894
|
-
case containerUtilities.
|
|
895
|
-
case containerUtilities.
|
|
875
|
+
switch (e.key) {
|
|
876
|
+
case containerUtilities.KEYS.ESCAPE:
|
|
877
|
+
case containerUtilities.KEYS.ENTER:
|
|
896
878
|
dispatch({
|
|
897
879
|
type: 'CLOSE'
|
|
898
880
|
});
|
|
899
881
|
break;
|
|
900
|
-
case containerUtilities.
|
|
901
|
-
case containerUtilities.
|
|
902
|
-
case containerUtilities.
|
|
882
|
+
case containerUtilities.KEYS.UP:
|
|
883
|
+
case containerUtilities.KEYS.DOWN:
|
|
884
|
+
case containerUtilities.KEYS.SPACE:
|
|
903
885
|
dispatch({
|
|
904
886
|
type: 'OPEN'
|
|
905
887
|
});
|
|
@@ -974,7 +956,7 @@ function formatValue(_ref) {
|
|
|
974
956
|
formatDate
|
|
975
957
|
} = _ref;
|
|
976
958
|
let stringValue = '';
|
|
977
|
-
if (value !== undefined &&
|
|
959
|
+
if (value !== undefined && isValid.isValid(value)) {
|
|
978
960
|
if (formatDate) {
|
|
979
961
|
stringValue = formatDate(value);
|
|
980
962
|
} else {
|
|
@@ -992,16 +974,16 @@ function parseInputValue(_ref2) {
|
|
|
992
974
|
inputValue
|
|
993
975
|
} = _ref2;
|
|
994
976
|
const MINIMUM_DATE = new Date(1001, 0, 0);
|
|
995
|
-
let tryParseDate =
|
|
996
|
-
if (
|
|
977
|
+
let tryParseDate = parse.parse(inputValue || '', 'P', new Date());
|
|
978
|
+
if (isValid.isValid(tryParseDate) && !isBefore.isBefore(tryParseDate, MINIMUM_DATE)) {
|
|
997
979
|
return tryParseDate;
|
|
998
980
|
}
|
|
999
|
-
tryParseDate =
|
|
1000
|
-
if (
|
|
981
|
+
tryParseDate = parse.parse(inputValue || '', 'PP', new Date());
|
|
982
|
+
if (isValid.isValid(tryParseDate) && !isBefore.isBefore(tryParseDate, MINIMUM_DATE)) {
|
|
1001
983
|
return tryParseDate;
|
|
1002
984
|
}
|
|
1003
|
-
tryParseDate =
|
|
1004
|
-
if (
|
|
985
|
+
tryParseDate = parse.parse(inputValue || '', 'PPP', new Date());
|
|
986
|
+
if (isValid.isValid(tryParseDate) && !isBefore.isBefore(tryParseDate, MINIMUM_DATE)) {
|
|
1005
987
|
return tryParseDate;
|
|
1006
988
|
}
|
|
1007
989
|
return new Date(NaN);
|
|
@@ -1020,10 +1002,10 @@ const datepickerRangeReducer = _ref3 => {
|
|
|
1020
1002
|
{
|
|
1021
1003
|
let previewDate = state.previewDate;
|
|
1022
1004
|
if (startValue) {
|
|
1023
|
-
if (
|
|
1005
|
+
if (compareAsc.compareAsc(startValue, startOfMonth.startOfMonth(state.previewDate)) === 1 && compareAsc.compareAsc(startValue, addMonths.addMonths(endOfMonth.endOfMonth(state.previewDate), 1)) === -1) {
|
|
1024
1006
|
previewDate = state.previewDate;
|
|
1025
1007
|
} else {
|
|
1026
|
-
previewDate =
|
|
1008
|
+
previewDate = startOfMonth.startOfMonth(startValue);
|
|
1027
1009
|
}
|
|
1028
1010
|
}
|
|
1029
1011
|
return {
|
|
@@ -1037,10 +1019,10 @@ const datepickerRangeReducer = _ref3 => {
|
|
|
1037
1019
|
{
|
|
1038
1020
|
let previewDate = state.previewDate;
|
|
1039
1021
|
if (endValue) {
|
|
1040
|
-
if (
|
|
1022
|
+
if (compareAsc.compareAsc(endValue, startOfMonth.startOfMonth(state.previewDate)) === 1 && compareAsc.compareAsc(endValue, addMonths.addMonths(endOfMonth.endOfMonth(state.previewDate), 1)) === -1) {
|
|
1041
1023
|
previewDate = state.previewDate;
|
|
1042
1024
|
} else {
|
|
1043
|
-
previewDate =
|
|
1025
|
+
previewDate = startOfMonth.startOfMonth(endValue);
|
|
1044
1026
|
}
|
|
1045
1027
|
}
|
|
1046
1028
|
return {
|
|
@@ -1109,10 +1091,10 @@ const datepickerRangeReducer = _ref3 => {
|
|
|
1109
1091
|
});
|
|
1110
1092
|
let previewDate = state.previewDate;
|
|
1111
1093
|
if (action.value) {
|
|
1112
|
-
if (
|
|
1094
|
+
if (compareAsc.compareAsc(action.value, startOfMonth.startOfMonth(state.previewDate)) === 1 && compareAsc.compareAsc(action.value, addMonths.addMonths(endOfMonth.endOfMonth(state.previewDate), 1)) === -1) {
|
|
1113
1095
|
previewDate = state.previewDate;
|
|
1114
1096
|
} else {
|
|
1115
|
-
previewDate =
|
|
1097
|
+
previewDate = startOfMonth.startOfMonth(action.value);
|
|
1116
1098
|
}
|
|
1117
1099
|
}
|
|
1118
1100
|
return {
|
|
@@ -1131,10 +1113,10 @@ const datepickerRangeReducer = _ref3 => {
|
|
|
1131
1113
|
});
|
|
1132
1114
|
let previewDate = state.previewDate;
|
|
1133
1115
|
if (action.value) {
|
|
1134
|
-
if (
|
|
1116
|
+
if (compareAsc.compareAsc(action.value, startOfMonth.startOfMonth(state.previewDate)) === 1 && compareAsc.compareAsc(action.value, addMonths.addMonths(endOfMonth.endOfMonth(state.previewDate), 1)) === -1) {
|
|
1135
1117
|
previewDate = state.previewDate;
|
|
1136
1118
|
} else {
|
|
1137
|
-
previewDate =
|
|
1119
|
+
previewDate = startOfMonth.startOfMonth(action.value);
|
|
1138
1120
|
}
|
|
1139
1121
|
}
|
|
1140
1122
|
return {
|
|
@@ -1146,7 +1128,7 @@ const datepickerRangeReducer = _ref3 => {
|
|
|
1146
1128
|
}
|
|
1147
1129
|
case 'CLICK_DATE':
|
|
1148
1130
|
if (state.isStartFocused) {
|
|
1149
|
-
if (endValue !== undefined && (
|
|
1131
|
+
if (endValue !== undefined && (isBefore.isBefore(action.value, endValue) || isSameDay.isSameDay(action.value, endValue))) {
|
|
1150
1132
|
return {
|
|
1151
1133
|
...state,
|
|
1152
1134
|
startInputValue: formatValue({
|
|
@@ -1162,7 +1144,7 @@ const datepickerRangeReducer = _ref3 => {
|
|
|
1162
1144
|
endInputValue: undefined
|
|
1163
1145
|
};
|
|
1164
1146
|
} else if (state.isEndFocused) {
|
|
1165
|
-
if (startValue !== undefined && (
|
|
1147
|
+
if (startValue !== undefined && (isAfter.isAfter(action.value, startValue) || isSameDay.isSameDay(action.value, startValue))) {
|
|
1166
1148
|
return {
|
|
1167
1149
|
...state,
|
|
1168
1150
|
endInputValue: formatValue({
|
|
@@ -1185,7 +1167,7 @@ const datepickerRangeReducer = _ref3 => {
|
|
|
1185
1167
|
endInputValue: undefined
|
|
1186
1168
|
};
|
|
1187
1169
|
} else if (endValue === undefined) {
|
|
1188
|
-
if (
|
|
1170
|
+
if (isBefore.isBefore(action.value, startValue)) {
|
|
1189
1171
|
return {
|
|
1190
1172
|
...state,
|
|
1191
1173
|
startInputValue: formatValue({
|
|
@@ -1223,7 +1205,7 @@ const datepickerRangeReducer = _ref3 => {
|
|
|
1223
1205
|
};
|
|
1224
1206
|
case 'PREVIEW_NEXT_MONTH':
|
|
1225
1207
|
{
|
|
1226
|
-
const previewDate =
|
|
1208
|
+
const previewDate = addMonths.addMonths(state.previewDate, 1);
|
|
1227
1209
|
return {
|
|
1228
1210
|
...state,
|
|
1229
1211
|
previewDate,
|
|
@@ -1232,7 +1214,7 @@ const datepickerRangeReducer = _ref3 => {
|
|
|
1232
1214
|
}
|
|
1233
1215
|
case 'PREVIEW_PREVIOUS_MONTH':
|
|
1234
1216
|
{
|
|
1235
|
-
const previewDate =
|
|
1217
|
+
const previewDate = subMonths.subMonths(state.previewDate, 1);
|
|
1236
1218
|
return {
|
|
1237
1219
|
...state,
|
|
1238
1220
|
previewDate,
|
|
@@ -1246,7 +1228,7 @@ const datepickerRangeReducer = _ref3 => {
|
|
|
1246
1228
|
};
|
|
1247
1229
|
function retrieveInitialState(initialProps) {
|
|
1248
1230
|
let previewDate = initialProps.startValue;
|
|
1249
|
-
if (previewDate === undefined || !
|
|
1231
|
+
if (previewDate === undefined || !isValid.isValid(previewDate)) {
|
|
1250
1232
|
previewDate = new Date();
|
|
1251
1233
|
}
|
|
1252
1234
|
const startInputValue = formatValue({
|
|
@@ -1308,7 +1290,7 @@ const Start = props => {
|
|
|
1308
1290
|
dispatch({
|
|
1309
1291
|
type: 'START_BLUR'
|
|
1310
1292
|
});
|
|
1311
|
-
if (parsedDate &&
|
|
1293
|
+
if (parsedDate && isValid.isValid(parsedDate) && !isSameDay.isSameDay(parsedDate, startValue)) {
|
|
1312
1294
|
onChange && onChange({
|
|
1313
1295
|
startValue: parsedDate,
|
|
1314
1296
|
endValue
|
|
@@ -1316,7 +1298,7 @@ const Start = props => {
|
|
|
1316
1298
|
}
|
|
1317
1299
|
}, [dispatch, onChange, startValue, endValue, customParseDate, state.startInputValue]);
|
|
1318
1300
|
const onKeyDownCallback = React.useCallback(e => {
|
|
1319
|
-
if (e.
|
|
1301
|
+
if (e.key === containerUtilities.KEYS.ENTER) {
|
|
1320
1302
|
e.preventDefault();
|
|
1321
1303
|
handleBlur();
|
|
1322
1304
|
}
|
|
@@ -1373,7 +1355,7 @@ const End = props => {
|
|
|
1373
1355
|
inputValue: state.endInputValue
|
|
1374
1356
|
});
|
|
1375
1357
|
}
|
|
1376
|
-
if (onChange && parsedDate &&
|
|
1358
|
+
if (onChange && parsedDate && isValid.isValid(parsedDate) && !isSameDay.isSameDay(parsedDate, endValue)) {
|
|
1377
1359
|
onChange && onChange({
|
|
1378
1360
|
startValue,
|
|
1379
1361
|
endValue: parsedDate
|
|
@@ -1381,7 +1363,7 @@ const End = props => {
|
|
|
1381
1363
|
}
|
|
1382
1364
|
}, [dispatch, onChange, startValue, endValue, customParseDate, state.endInputValue]);
|
|
1383
1365
|
const onKeydownCallback = React.useCallback(e => {
|
|
1384
|
-
if (e.
|
|
1366
|
+
if (e.key === containerUtilities.KEYS.ENTER) {
|
|
1385
1367
|
handleBlur();
|
|
1386
1368
|
e.preventDefault();
|
|
1387
1369
|
}
|
|
@@ -1456,17 +1438,17 @@ const Month = React.forwardRef((_ref, ref) => {
|
|
|
1456
1438
|
return formatter.format(date);
|
|
1457
1439
|
}, [locale]);
|
|
1458
1440
|
const preferredWeekStartsOn = weekStartsOn || getStartOfWeek(locale);
|
|
1459
|
-
const monthStartDate =
|
|
1460
|
-
const monthEndDate =
|
|
1461
|
-
const startDate =
|
|
1441
|
+
const monthStartDate = startOfMonth.startOfMonth(displayDate);
|
|
1442
|
+
const monthEndDate = endOfMonth.endOfMonth(monthStartDate);
|
|
1443
|
+
const startDate = startOfWeek.startOfWeek(monthStartDate, {
|
|
1462
1444
|
weekStartsOn: preferredWeekStartsOn
|
|
1463
1445
|
});
|
|
1464
|
-
const endDate =
|
|
1446
|
+
const endDate = endOfWeek.endOfWeek(monthEndDate, {
|
|
1465
1447
|
weekStartsOn: preferredWeekStartsOn
|
|
1466
1448
|
});
|
|
1467
|
-
const dayLabels =
|
|
1449
|
+
const dayLabels = eachDayOfInterval.eachDayOfInterval({
|
|
1468
1450
|
start: startDate,
|
|
1469
|
-
end:
|
|
1451
|
+
end: addDays.addDays(startDate, 6)
|
|
1470
1452
|
}).map(date => {
|
|
1471
1453
|
const formattedDayLabel = dayLabelFormatter(date);
|
|
1472
1454
|
return React__namespace.default.createElement(StyledCalendarItem, {
|
|
@@ -1476,13 +1458,13 @@ const Month = React.forwardRef((_ref, ref) => {
|
|
|
1476
1458
|
isCompact: isCompact
|
|
1477
1459
|
}, formattedDayLabel));
|
|
1478
1460
|
});
|
|
1479
|
-
const items =
|
|
1461
|
+
const items = eachDayOfInterval.eachDayOfInterval({
|
|
1480
1462
|
start: startDate,
|
|
1481
1463
|
end: endDate
|
|
1482
1464
|
}).map((date, itemsIndex) => {
|
|
1483
1465
|
const formattedDayLabel = dayFormatter(date);
|
|
1484
|
-
const isCurrentDate =
|
|
1485
|
-
const isPreviousMonth = !
|
|
1466
|
+
const isCurrentDate = isToday.isToday(date);
|
|
1467
|
+
const isPreviousMonth = !isSameMonth.isSameMonth(date, displayDate);
|
|
1486
1468
|
if (isPreviousMonth) {
|
|
1487
1469
|
return React__namespace.default.createElement(StyledCalendarItem, {
|
|
1488
1470
|
key: `day-${itemsIndex}`,
|
|
@@ -1495,41 +1477,41 @@ const Month = React.forwardRef((_ref, ref) => {
|
|
|
1495
1477
|
}
|
|
1496
1478
|
let isSelected = false;
|
|
1497
1479
|
if (startValue !== undefined) {
|
|
1498
|
-
isSelected =
|
|
1480
|
+
isSelected = isSameDay.isSameDay(date, startValue);
|
|
1499
1481
|
}
|
|
1500
1482
|
if (endValue !== undefined) {
|
|
1501
|
-
isSelected = isSelected ||
|
|
1483
|
+
isSelected = isSelected || isSameDay.isSameDay(date, endValue);
|
|
1502
1484
|
}
|
|
1503
1485
|
let isDisabled = false;
|
|
1504
1486
|
if (minValue !== undefined) {
|
|
1505
|
-
isDisabled =
|
|
1487
|
+
isDisabled = isBefore.isBefore(date, minValue) && !isSameDay.isSameDay(date, minValue);
|
|
1506
1488
|
}
|
|
1507
1489
|
if (maxValue !== undefined) {
|
|
1508
|
-
isDisabled = isDisabled ||
|
|
1490
|
+
isDisabled = isDisabled || isAfter.isAfter(date, maxValue) && !isSameDay.isSameDay(date, maxValue);
|
|
1509
1491
|
}
|
|
1510
1492
|
let isHighlighted = false;
|
|
1511
1493
|
if (startValue !== undefined && endValue !== undefined) {
|
|
1512
|
-
isHighlighted = (
|
|
1494
|
+
isHighlighted = (isAfter.isAfter(date, startValue) || isSameDay.isSameDay(date, startValue)) && (isBefore.isBefore(date, endValue) || isSameDay.isSameDay(date, endValue)) && !isSameDay.isSameDay(startValue, endValue);
|
|
1513
1495
|
} else if (startValue !== undefined && state.hoverDate !== undefined) {
|
|
1514
|
-
isHighlighted = (
|
|
1496
|
+
isHighlighted = (isAfter.isAfter(date, startValue) || isSameDay.isSameDay(date, startValue)) && (isBefore.isBefore(date, state.hoverDate) || isSameDay.isSameDay(date, state.hoverDate));
|
|
1515
1497
|
}
|
|
1516
|
-
const isHighlightStart = isHighlighted && startValue &&
|
|
1517
|
-
const isHighlightEnd = isHighlighted && endValue &&
|
|
1518
|
-
let isInvalidDateRange = endValue && startValue &&
|
|
1498
|
+
const isHighlightStart = isHighlighted && startValue && isSameDay.isSameDay(date, startValue) || false;
|
|
1499
|
+
const isHighlightEnd = isHighlighted && endValue && isSameDay.isSameDay(date, endValue) || state.hoverDate && isSameDay.isSameDay(date, state.hoverDate) && !isBefore.isBefore(date, endValue) || false;
|
|
1500
|
+
let isInvalidDateRange = endValue && startValue && compareAsc.compareAsc(endValue, startValue) === -1 || false;
|
|
1519
1501
|
if (minValue) {
|
|
1520
1502
|
if (startValue) {
|
|
1521
|
-
isInvalidDateRange = isInvalidDateRange ||
|
|
1503
|
+
isInvalidDateRange = isInvalidDateRange || compareAsc.compareAsc(startValue, subDays.subDays(minValue, 1)) === -1;
|
|
1522
1504
|
}
|
|
1523
1505
|
if (endValue) {
|
|
1524
|
-
isInvalidDateRange = isInvalidDateRange ||
|
|
1506
|
+
isInvalidDateRange = isInvalidDateRange || compareAsc.compareAsc(endValue, subDays.subDays(minValue, 1)) === -1;
|
|
1525
1507
|
}
|
|
1526
1508
|
}
|
|
1527
1509
|
if (maxValue) {
|
|
1528
1510
|
if (startValue) {
|
|
1529
|
-
isInvalidDateRange = isInvalidDateRange ||
|
|
1511
|
+
isInvalidDateRange = isInvalidDateRange || compareAsc.compareAsc(startValue, maxValue) === 1;
|
|
1530
1512
|
}
|
|
1531
1513
|
if (endValue) {
|
|
1532
|
-
isInvalidDateRange = isInvalidDateRange ||
|
|
1514
|
+
isInvalidDateRange = isInvalidDateRange || compareAsc.compareAsc(endValue, maxValue) === 1;
|
|
1533
1515
|
}
|
|
1534
1516
|
}
|
|
1535
1517
|
return React__namespace.default.createElement(StyledCalendarItem, {
|
|
@@ -1553,7 +1535,7 @@ const Month = React.forwardRef((_ref, ref) => {
|
|
|
1553
1535
|
});
|
|
1554
1536
|
if (onChange) {
|
|
1555
1537
|
if (state.isStartFocused) {
|
|
1556
|
-
if (endValue !== undefined && (
|
|
1538
|
+
if (endValue !== undefined && (isBefore.isBefore(date, endValue) || isSameDay.isSameDay(date, endValue))) {
|
|
1557
1539
|
onChange({
|
|
1558
1540
|
startValue: date,
|
|
1559
1541
|
endValue
|
|
@@ -1565,7 +1547,7 @@ const Month = React.forwardRef((_ref, ref) => {
|
|
|
1565
1547
|
});
|
|
1566
1548
|
}
|
|
1567
1549
|
} else if (state.isEndFocused) {
|
|
1568
|
-
if (startValue !== undefined && (
|
|
1550
|
+
if (startValue !== undefined && (isAfter.isAfter(date, startValue) || isSameDay.isSameDay(date, startValue))) {
|
|
1569
1551
|
onChange({
|
|
1570
1552
|
startValue,
|
|
1571
1553
|
endValue: date
|
|
@@ -1582,7 +1564,7 @@ const Month = React.forwardRef((_ref, ref) => {
|
|
|
1582
1564
|
endValue: undefined
|
|
1583
1565
|
});
|
|
1584
1566
|
} else if (endValue === undefined) {
|
|
1585
|
-
if (
|
|
1567
|
+
if (isBefore.isBefore(date, startValue)) {
|
|
1586
1568
|
onChange({
|
|
1587
1569
|
startValue: date,
|
|
1588
1570
|
endValue: undefined
|
|
@@ -1657,12 +1639,12 @@ const Calendar = React.forwardRef((props, ref) => {
|
|
|
1657
1639
|
return React__namespace.default.createElement(StyledRangeCalendar, _extends({
|
|
1658
1640
|
ref: ref,
|
|
1659
1641
|
"data-garden-id": "datepickers.range",
|
|
1660
|
-
"data-garden-version": '8.74.
|
|
1642
|
+
"data-garden-version": '8.74.2'
|
|
1661
1643
|
}, props), React__namespace.default.createElement(Month, {
|
|
1662
1644
|
displayDate: state.previewDate,
|
|
1663
1645
|
isNextHidden: true
|
|
1664
1646
|
}), React__namespace.default.createElement(Month, {
|
|
1665
|
-
displayDate:
|
|
1647
|
+
displayDate: addMonths.addMonths(state.previewDate, 1),
|
|
1666
1648
|
isPreviousHidden: true
|
|
1667
1649
|
}));
|
|
1668
1650
|
});
|
package/dist/index.esm.js
CHANGED
|
@@ -10,26 +10,26 @@ import React__default, { createContext, useContext, useCallback, forwardRef, use
|
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
11
|
import styled, { css, ThemeContext } from 'styled-components';
|
|
12
12
|
import { Manager, Reference, Popper } from 'react-popper';
|
|
13
|
-
import { composeEventHandlers,
|
|
14
|
-
import startOfMonth from 'date-fns/startOfMonth';
|
|
15
|
-
import endOfMonth from 'date-fns/endOfMonth';
|
|
16
|
-
import startOfWeek from 'date-fns/startOfWeek';
|
|
17
|
-
import endOfWeek from 'date-fns/endOfWeek';
|
|
18
|
-
import eachDayOfInterval from 'date-fns/eachDayOfInterval';
|
|
19
|
-
import addDays from 'date-fns/addDays';
|
|
20
|
-
import isToday from 'date-fns/isToday';
|
|
21
|
-
import isSameDay from 'date-fns/isSameDay';
|
|
22
|
-
import isSameMonth from 'date-fns/isSameMonth';
|
|
23
|
-
import isBefore from 'date-fns/isBefore';
|
|
24
|
-
import isAfter from 'date-fns/isAfter';
|
|
25
|
-
import getDate from 'date-fns/getDate';
|
|
13
|
+
import { composeEventHandlers, KEYS } from '@zendeskgarden/container-utilities';
|
|
14
|
+
import { startOfMonth } from 'date-fns/startOfMonth';
|
|
15
|
+
import { endOfMonth } from 'date-fns/endOfMonth';
|
|
16
|
+
import { startOfWeek } from 'date-fns/startOfWeek';
|
|
17
|
+
import { endOfWeek } from 'date-fns/endOfWeek';
|
|
18
|
+
import { eachDayOfInterval } from 'date-fns/eachDayOfInterval';
|
|
19
|
+
import { addDays } from 'date-fns/addDays';
|
|
20
|
+
import { isToday } from 'date-fns/isToday';
|
|
21
|
+
import { isSameDay } from 'date-fns/isSameDay';
|
|
22
|
+
import { isSameMonth } from 'date-fns/isSameMonth';
|
|
23
|
+
import { isBefore } from 'date-fns/isBefore';
|
|
24
|
+
import { isAfter } from 'date-fns/isAfter';
|
|
25
|
+
import { getDate } from 'date-fns/getDate';
|
|
26
26
|
import { retrieveComponentStyles, DEFAULT_THEME, menuStyles, getColor } from '@zendeskgarden/react-theming';
|
|
27
|
-
import addMonths from 'date-fns/addMonths';
|
|
28
|
-
import subMonths from 'date-fns/subMonths';
|
|
29
|
-
import isValid from 'date-fns/isValid';
|
|
30
|
-
import parse from 'date-fns/parse';
|
|
31
|
-
import compareAsc from 'date-fns/compareAsc';
|
|
32
|
-
import subDays from 'date-fns/subDays';
|
|
27
|
+
import { addMonths } from 'date-fns/addMonths';
|
|
28
|
+
import { subMonths } from 'date-fns/subMonths';
|
|
29
|
+
import { isValid } from 'date-fns/isValid';
|
|
30
|
+
import { parse } from 'date-fns/parse';
|
|
31
|
+
import { compareAsc } from 'date-fns/compareAsc';
|
|
32
|
+
import { subDays } from 'date-fns/subDays';
|
|
33
33
|
|
|
34
34
|
const WEEK_STARTS_ON = [0, 1, 2, 3, 4, 5, 6];
|
|
35
35
|
const SHARED_PLACEMENT = ['auto', 'top', 'top-start', 'top-end', 'bottom', 'bottom-start', 'bottom-end'];
|
|
@@ -87,7 +87,7 @@ function getMenuPosition(popperPlacement) {
|
|
|
87
87
|
const COMPONENT_ID$b = 'datepickers.menu';
|
|
88
88
|
const StyledMenu = styled.div.attrs({
|
|
89
89
|
'data-garden-id': COMPONENT_ID$b,
|
|
90
|
-
'data-garden-version': '8.74.
|
|
90
|
+
'data-garden-version': '8.74.2'
|
|
91
91
|
}).withConfig({
|
|
92
92
|
displayName: "StyledMenu",
|
|
93
93
|
componentId: "sc-1npbkk0-0"
|
|
@@ -847,16 +847,16 @@ const Datepicker = forwardRef((props, calendarRef) => {
|
|
|
847
847
|
});
|
|
848
848
|
}),
|
|
849
849
|
onKeyDown: composeEventHandlers(childElement.props.onKeyDown, e => {
|
|
850
|
-
switch (e.
|
|
851
|
-
case
|
|
852
|
-
case
|
|
850
|
+
switch (e.key) {
|
|
851
|
+
case KEYS.ESCAPE:
|
|
852
|
+
case KEYS.ENTER:
|
|
853
853
|
dispatch({
|
|
854
854
|
type: 'CLOSE'
|
|
855
855
|
});
|
|
856
856
|
break;
|
|
857
|
-
case
|
|
858
|
-
case
|
|
859
|
-
case
|
|
857
|
+
case KEYS.UP:
|
|
858
|
+
case KEYS.DOWN:
|
|
859
|
+
case KEYS.SPACE:
|
|
860
860
|
dispatch({
|
|
861
861
|
type: 'OPEN'
|
|
862
862
|
});
|
|
@@ -1273,7 +1273,7 @@ const Start = props => {
|
|
|
1273
1273
|
}
|
|
1274
1274
|
}, [dispatch, onChange, startValue, endValue, customParseDate, state.startInputValue]);
|
|
1275
1275
|
const onKeyDownCallback = useCallback(e => {
|
|
1276
|
-
if (e.
|
|
1276
|
+
if (e.key === KEYS.ENTER) {
|
|
1277
1277
|
e.preventDefault();
|
|
1278
1278
|
handleBlur();
|
|
1279
1279
|
}
|
|
@@ -1338,7 +1338,7 @@ const End = props => {
|
|
|
1338
1338
|
}
|
|
1339
1339
|
}, [dispatch, onChange, startValue, endValue, customParseDate, state.endInputValue]);
|
|
1340
1340
|
const onKeydownCallback = useCallback(e => {
|
|
1341
|
-
if (e.
|
|
1341
|
+
if (e.key === KEYS.ENTER) {
|
|
1342
1342
|
handleBlur();
|
|
1343
1343
|
e.preventDefault();
|
|
1344
1344
|
}
|
|
@@ -1614,7 +1614,7 @@ const Calendar = forwardRef((props, ref) => {
|
|
|
1614
1614
|
return React__default.createElement(StyledRangeCalendar, _extends({
|
|
1615
1615
|
ref: ref,
|
|
1616
1616
|
"data-garden-id": "datepickers.range",
|
|
1617
|
-
"data-garden-version": '8.74.
|
|
1617
|
+
"data-garden-version": '8.74.2'
|
|
1618
1618
|
}, props), React__default.createElement(Month, {
|
|
1619
1619
|
displayDate: state.previewDate,
|
|
1620
1620
|
isNextHidden: true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zendeskgarden/react-datepickers",
|
|
3
|
-
"version": "8.74.
|
|
3
|
+
"version": "8.74.2",
|
|
4
4
|
"description": "Components relating to datepickers in the Garden Design System",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Zendesk Garden <garden@zendesk.com>",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"sideEffects": false,
|
|
22
22
|
"types": "dist/typings/index.d.ts",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@zendeskgarden/container-utilities": "^
|
|
25
|
-
"date-fns": "^
|
|
24
|
+
"@zendeskgarden/container-utilities": "^2.0.0",
|
|
25
|
+
"date-fns": "^3.0.0",
|
|
26
26
|
"prop-types": "^15.5.7",
|
|
27
27
|
"react-popper": "^1.3.4"
|
|
28
28
|
},
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"styled-components": "^4.2.0 || ^5.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@zendeskgarden/react-theming": "^8.74.
|
|
36
|
+
"@zendeskgarden/react-theming": "^8.74.2",
|
|
37
37
|
"@zendeskgarden/svg-icons": "7.0.0"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"access": "public"
|
|
47
47
|
},
|
|
48
48
|
"zendeskgarden:src": "src/index.ts",
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "be0e20f0b016a227ed1ab6b5b13cb04971969d3b"
|
|
50
50
|
}
|