willba-component-library 0.2.56 → 0.2.58
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/lib/components/FilterCalendar/FilterCalendar.stories.d.ts +1 -0
- package/lib/index.esm.js +78 -54
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +78 -54
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +78 -54
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FilterCalendar/FilterCalendar.stories.tsx +436 -29
- package/src/core/components/calendar/utils/calendarSelectionRules.tsx +92 -76
package/lib/index.esm.js
CHANGED
|
@@ -10968,27 +10968,28 @@ var calendarSelectionRules = function (_a) {
|
|
|
10968
10968
|
var _b;
|
|
10969
10969
|
var range = _a.range, newDisableCalendarDates = _a.newDisableCalendarDates, setCalendarRange = _a.setCalendarRange, setDisabledDates = _a.setDisabledDates, calendarRange = _a.calendarRange, overlappingDate = _a.overlappingDate, setCalendarHasError = _a.setCalendarHasError, rangeContext = _a.rangeContext;
|
|
10970
10970
|
// Get and parse needed data
|
|
10971
|
-
var
|
|
10972
|
-
var
|
|
10973
|
-
var
|
|
10974
|
-
|
|
10975
|
-
? format(calendarRange === null || calendarRange === void 0 ? void 0 : calendarRange.from, dateFormat)
|
|
10971
|
+
var rangeFrom = (range === null || range === void 0 ? void 0 : range.from) ? endOfDay(range.from) : null;
|
|
10972
|
+
var rangeTo = (range === null || range === void 0 ? void 0 : range.to) ? endOfDay(range.to) : null;
|
|
10973
|
+
var calendarRangeFrom = (calendarRange === null || calendarRange === void 0 ? void 0 : calendarRange.from)
|
|
10974
|
+
? endOfDay(calendarRange.from)
|
|
10976
10975
|
: null;
|
|
10977
|
-
(calendarRange === null || calendarRange === void 0 ? void 0 : calendarRange.to)
|
|
10978
|
-
|
|
10979
|
-
|
|
10980
|
-
(rangeContext === null || rangeContext === void 0 ? void 0 : rangeContext.from)
|
|
10981
|
-
? format(rangeContext.from, dateFormat)
|
|
10976
|
+
var calendarRangeTo = (calendarRange === null || calendarRange === void 0 ? void 0 : calendarRange.to) ? endOfDay(calendarRange.to) : null;
|
|
10977
|
+
var rangeContextFrom = (rangeContext === null || rangeContext === void 0 ? void 0 : rangeContext.from)
|
|
10978
|
+
? endOfDay(rangeContext.from)
|
|
10982
10979
|
: null;
|
|
10980
|
+
var rangeContextTo = (rangeContext === null || rangeContext === void 0 ? void 0 : rangeContext.to) ? endOfDay(rangeContext.to) : null;
|
|
10983
10981
|
var overlappingDateFrom = (overlappingDate === null || overlappingDate === void 0 ? void 0 : overlappingDate.length)
|
|
10984
10982
|
? overlappingDate.find(function (date) {
|
|
10985
|
-
return
|
|
10983
|
+
return !!(date.from && rangeFrom)
|
|
10984
|
+
? isEqual(endOfDay(date.from), rangeFrom)
|
|
10985
|
+
: false;
|
|
10986
10986
|
})
|
|
10987
10987
|
: null;
|
|
10988
10988
|
var checkOutRange = ((_b = newDisableCalendarDates === null || newDisableCalendarDates === void 0 ? void 0 : newDisableCalendarDates.availableDates) === null || _b === void 0 ? void 0 : _b.length)
|
|
10989
10989
|
? newDisableCalendarDates.availableDates.find(function (checkInDate) {
|
|
10990
|
-
return
|
|
10991
|
-
|
|
10990
|
+
return !!(checkInDate.checkIn && rangeFrom)
|
|
10991
|
+
? isEqual(endOfDay(checkInDate.checkIn), rangeFrom)
|
|
10992
|
+
: false;
|
|
10992
10993
|
})
|
|
10993
10994
|
: null;
|
|
10994
10995
|
// On check-in, disable future dates that are unavailable for checkout
|
|
@@ -10996,56 +10997,79 @@ var calendarSelectionRules = function (_a) {
|
|
|
10996
10997
|
rangeFrom: rangeFrom,
|
|
10997
10998
|
checkOutRange: checkOutRange,
|
|
10998
10999
|
setDisabledDates: setDisabledDates,
|
|
10999
|
-
dateFormat: dateFormat,
|
|
11000
11000
|
newDisableCalendarDates: newDisableCalendarDates,
|
|
11001
11001
|
});
|
|
11002
|
-
// Calendar selection rules
|
|
11003
|
-
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
|
|
11007
|
-
|
|
11008
|
-
|
|
11009
|
-
|
|
11010
|
-
|
|
11011
|
-
|
|
11012
|
-
|
|
11013
|
-
|
|
11014
|
-
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
|
|
11020
|
-
|
|
11021
|
-
|
|
11022
|
-
|
|
11023
|
-
|
|
11024
|
-
|
|
11025
|
-
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
|
|
11031
|
-
|
|
11032
|
-
|
|
11033
|
-
|
|
11034
|
-
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
|
|
11002
|
+
// Calendar selection rules: The cases are handled sequentially, starting from simple selections to more complex contextual selections.
|
|
11003
|
+
// The rules are processed in a specific order, so one case is handled before another.
|
|
11004
|
+
// Changing the order will cause the rules to break or not work properly.
|
|
11005
|
+
if (!!overlappingDateFrom) {
|
|
11006
|
+
// 1. If dates overlap, clear the selection.
|
|
11007
|
+
return setCalendarRange(undefined);
|
|
11008
|
+
}
|
|
11009
|
+
if (
|
|
11010
|
+
// 2. If selected "start" is after "range context end", clear selection and display error
|
|
11011
|
+
(rangeFrom && rangeContextTo && isAfter(rangeFrom, rangeContextTo)) ||
|
|
11012
|
+
(calendarRangeFrom &&
|
|
11013
|
+
calendarRangeTo &&
|
|
11014
|
+
rangeContextTo &&
|
|
11015
|
+
rangeTo &&
|
|
11016
|
+
isAfter(rangeTo, rangeContextTo))) {
|
|
11017
|
+
setCalendarHasError && setCalendarHasError(true);
|
|
11018
|
+
return setCalendarRange(undefined);
|
|
11019
|
+
}
|
|
11020
|
+
if (rangeFrom && rangeTo && isEqual(rangeFrom, rangeTo)) {
|
|
11021
|
+
// 3. If "start" is selected and the same date is clicked again, keep the current "start" selection.
|
|
11022
|
+
return setCalendarRange({ from: rangeFrom, to: undefined });
|
|
11023
|
+
}
|
|
11024
|
+
if (calendarRangeFrom && calendarRangeTo && !range) {
|
|
11025
|
+
// 4. If "calendarRange" has dates selected and the same "start" date is clicked, the "range" will become undefined.
|
|
11026
|
+
// Set the current selection (calendarRange) to the initial "start" of calendarRange.
|
|
11027
|
+
return setCalendarRange({ from: calendarRangeFrom, to: undefined });
|
|
11028
|
+
}
|
|
11029
|
+
// 5. Handle gap selection backwards and forwards
|
|
11030
|
+
if (
|
|
11031
|
+
// Enforce on every date selection before current "start", mark as "start" selection
|
|
11032
|
+
rangeFrom &&
|
|
11033
|
+
calendarRangeFrom &&
|
|
11034
|
+
isBefore(rangeFrom, calendarRangeFrom)) {
|
|
11035
|
+
return setCalendarRange({ from: rangeFrom, to: undefined });
|
|
11036
|
+
}
|
|
11037
|
+
if (
|
|
11038
|
+
// Every date selection that is after selected "start" last checkout, mark as "start"
|
|
11039
|
+
rangeTo &&
|
|
11040
|
+
(checkOutRange === null || checkOutRange === void 0 ? void 0 : checkOutRange.lastCheckOut) &&
|
|
11041
|
+
isAfter(rangeTo, endOfDay(checkOutRange.lastCheckOut))) {
|
|
11042
|
+
return setCalendarRange({ from: rangeTo, to: undefined });
|
|
11043
|
+
}
|
|
11044
|
+
if (calendarRangeFrom &&
|
|
11045
|
+
rangeFrom &&
|
|
11046
|
+
!isEqual(calendarRangeFrom, rangeFrom)) {
|
|
11047
|
+
// 6. If "calendarRange" has selected dates and the new selection "start" differs from the current "calendarRange start", reset and make a new "start" selection.
|
|
11048
|
+
return setCalendarRange({ from: rangeFrom, to: undefined });
|
|
11049
|
+
}
|
|
11050
|
+
else if (calendarRangeTo && rangeTo && !isEqual(calendarRangeTo, rangeTo)) {
|
|
11051
|
+
// 7. If "calendarRange" has selected dates and the new selection "end" differs from the current "calendarRange end", reset and make a new "start" selection.
|
|
11052
|
+
return setCalendarRange({ from: rangeTo, to: undefined });
|
|
11053
|
+
}
|
|
11054
|
+
if (
|
|
11055
|
+
// 8. If selected "end" is before "context start", mark as "start" and display error
|
|
11056
|
+
rangeFrom &&
|
|
11057
|
+
rangeTo &&
|
|
11058
|
+
rangeContextFrom &&
|
|
11059
|
+
isBefore(rangeTo, rangeContextFrom)) {
|
|
11060
|
+
setCalendarHasError && setCalendarHasError(true);
|
|
11061
|
+
return setCalendarRange({ from: rangeTo, to: undefined });
|
|
11062
|
+
}
|
|
11063
|
+
setCalendarRange(range);
|
|
11038
11064
|
};
|
|
11039
11065
|
/////////
|
|
11040
11066
|
var disableFutureDates = function (_a) {
|
|
11041
|
-
var rangeFrom = _a.rangeFrom, checkOutRange = _a.checkOutRange, setDisabledDates = _a.setDisabledDates,
|
|
11067
|
+
var rangeFrom = _a.rangeFrom, checkOutRange = _a.checkOutRange, setDisabledDates = _a.setDisabledDates, newDisableCalendarDates = _a.newDisableCalendarDates;
|
|
11042
11068
|
if (rangeFrom && checkOutRange && setDisabledDates) {
|
|
11043
11069
|
// Get and parse data
|
|
11044
11070
|
var checkIn = addDays(checkOutRange.checkIn, 1);
|
|
11045
11071
|
var firstCheckOut = addDays(checkOutRange.firstCheckOut, -1);
|
|
11046
|
-
var noDatesRange =
|
|
11047
|
-
format(checkOutRange.firstCheckOut, dateFormat);
|
|
11048
|
-
// -------------------
|
|
11072
|
+
var noDatesRange = isEqual(checkIn, checkOutRange.firstCheckOut);
|
|
11049
11073
|
setDisabledDates(__spreadArray$1(__spreadArray$1([], __read(((newDisableCalendarDates === null || newDisableCalendarDates === void 0 ? void 0 : newDisableCalendarDates.disabledDates) || [])), false), [
|
|
11050
11074
|
{
|
|
11051
11075
|
from: noDatesRange ? undefined : checkIn,
|