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.js
CHANGED
|
@@ -10988,27 +10988,28 @@ var calendarSelectionRules = function (_a) {
|
|
|
10988
10988
|
var _b;
|
|
10989
10989
|
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;
|
|
10990
10990
|
// Get and parse needed data
|
|
10991
|
-
var
|
|
10992
|
-
var
|
|
10993
|
-
var
|
|
10994
|
-
|
|
10995
|
-
? format(calendarRange === null || calendarRange === void 0 ? void 0 : calendarRange.from, dateFormat)
|
|
10991
|
+
var rangeFrom = (range === null || range === void 0 ? void 0 : range.from) ? endOfDay(range.from) : null;
|
|
10992
|
+
var rangeTo = (range === null || range === void 0 ? void 0 : range.to) ? endOfDay(range.to) : null;
|
|
10993
|
+
var calendarRangeFrom = (calendarRange === null || calendarRange === void 0 ? void 0 : calendarRange.from)
|
|
10994
|
+
? endOfDay(calendarRange.from)
|
|
10996
10995
|
: null;
|
|
10997
|
-
(calendarRange === null || calendarRange === void 0 ? void 0 : calendarRange.to)
|
|
10998
|
-
|
|
10999
|
-
|
|
11000
|
-
(rangeContext === null || rangeContext === void 0 ? void 0 : rangeContext.from)
|
|
11001
|
-
? format(rangeContext.from, dateFormat)
|
|
10996
|
+
var calendarRangeTo = (calendarRange === null || calendarRange === void 0 ? void 0 : calendarRange.to) ? endOfDay(calendarRange.to) : null;
|
|
10997
|
+
var rangeContextFrom = (rangeContext === null || rangeContext === void 0 ? void 0 : rangeContext.from)
|
|
10998
|
+
? endOfDay(rangeContext.from)
|
|
11002
10999
|
: null;
|
|
11000
|
+
var rangeContextTo = (rangeContext === null || rangeContext === void 0 ? void 0 : rangeContext.to) ? endOfDay(rangeContext.to) : null;
|
|
11003
11001
|
var overlappingDateFrom = (overlappingDate === null || overlappingDate === void 0 ? void 0 : overlappingDate.length)
|
|
11004
11002
|
? overlappingDate.find(function (date) {
|
|
11005
|
-
return
|
|
11003
|
+
return !!(date.from && rangeFrom)
|
|
11004
|
+
? isEqual(endOfDay(date.from), rangeFrom)
|
|
11005
|
+
: false;
|
|
11006
11006
|
})
|
|
11007
11007
|
: null;
|
|
11008
11008
|
var checkOutRange = ((_b = newDisableCalendarDates === null || newDisableCalendarDates === void 0 ? void 0 : newDisableCalendarDates.availableDates) === null || _b === void 0 ? void 0 : _b.length)
|
|
11009
11009
|
? newDisableCalendarDates.availableDates.find(function (checkInDate) {
|
|
11010
|
-
return
|
|
11011
|
-
|
|
11010
|
+
return !!(checkInDate.checkIn && rangeFrom)
|
|
11011
|
+
? isEqual(endOfDay(checkInDate.checkIn), rangeFrom)
|
|
11012
|
+
: false;
|
|
11012
11013
|
})
|
|
11013
11014
|
: null;
|
|
11014
11015
|
// On check-in, disable future dates that are unavailable for checkout
|
|
@@ -11016,56 +11017,79 @@ var calendarSelectionRules = function (_a) {
|
|
|
11016
11017
|
rangeFrom: rangeFrom,
|
|
11017
11018
|
checkOutRange: checkOutRange,
|
|
11018
11019
|
setDisabledDates: setDisabledDates,
|
|
11019
|
-
dateFormat: dateFormat,
|
|
11020
11020
|
newDisableCalendarDates: newDisableCalendarDates,
|
|
11021
11021
|
});
|
|
11022
|
-
// Calendar selection rules
|
|
11023
|
-
|
|
11024
|
-
|
|
11025
|
-
|
|
11026
|
-
|
|
11027
|
-
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
|
|
11031
|
-
|
|
11032
|
-
|
|
11033
|
-
|
|
11034
|
-
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
-
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11056
|
-
|
|
11057
|
-
|
|
11022
|
+
// Calendar selection rules: The cases are handled sequentially, starting from simple selections to more complex contextual selections.
|
|
11023
|
+
// The rules are processed in a specific order, so one case is handled before another.
|
|
11024
|
+
// Changing the order will cause the rules to break or not work properly.
|
|
11025
|
+
if (!!overlappingDateFrom) {
|
|
11026
|
+
// 1. If dates overlap, clear the selection.
|
|
11027
|
+
return setCalendarRange(undefined);
|
|
11028
|
+
}
|
|
11029
|
+
if (
|
|
11030
|
+
// 2. If selected "start" is after "range context end", clear selection and display error
|
|
11031
|
+
(rangeFrom && rangeContextTo && isAfter(rangeFrom, rangeContextTo)) ||
|
|
11032
|
+
(calendarRangeFrom &&
|
|
11033
|
+
calendarRangeTo &&
|
|
11034
|
+
rangeContextTo &&
|
|
11035
|
+
rangeTo &&
|
|
11036
|
+
isAfter(rangeTo, rangeContextTo))) {
|
|
11037
|
+
setCalendarHasError && setCalendarHasError(true);
|
|
11038
|
+
return setCalendarRange(undefined);
|
|
11039
|
+
}
|
|
11040
|
+
if (rangeFrom && rangeTo && isEqual(rangeFrom, rangeTo)) {
|
|
11041
|
+
// 3. If "start" is selected and the same date is clicked again, keep the current "start" selection.
|
|
11042
|
+
return setCalendarRange({ from: rangeFrom, to: undefined });
|
|
11043
|
+
}
|
|
11044
|
+
if (calendarRangeFrom && calendarRangeTo && !range) {
|
|
11045
|
+
// 4. If "calendarRange" has dates selected and the same "start" date is clicked, the "range" will become undefined.
|
|
11046
|
+
// Set the current selection (calendarRange) to the initial "start" of calendarRange.
|
|
11047
|
+
return setCalendarRange({ from: calendarRangeFrom, to: undefined });
|
|
11048
|
+
}
|
|
11049
|
+
// 5. Handle gap selection backwards and forwards
|
|
11050
|
+
if (
|
|
11051
|
+
// Enforce on every date selection before current "start", mark as "start" selection
|
|
11052
|
+
rangeFrom &&
|
|
11053
|
+
calendarRangeFrom &&
|
|
11054
|
+
isBefore(rangeFrom, calendarRangeFrom)) {
|
|
11055
|
+
return setCalendarRange({ from: rangeFrom, to: undefined });
|
|
11056
|
+
}
|
|
11057
|
+
if (
|
|
11058
|
+
// Every date selection that is after selected "start" last checkout, mark as "start"
|
|
11059
|
+
rangeTo &&
|
|
11060
|
+
(checkOutRange === null || checkOutRange === void 0 ? void 0 : checkOutRange.lastCheckOut) &&
|
|
11061
|
+
isAfter(rangeTo, endOfDay(checkOutRange.lastCheckOut))) {
|
|
11062
|
+
return setCalendarRange({ from: rangeTo, to: undefined });
|
|
11063
|
+
}
|
|
11064
|
+
if (calendarRangeFrom &&
|
|
11065
|
+
rangeFrom &&
|
|
11066
|
+
!isEqual(calendarRangeFrom, rangeFrom)) {
|
|
11067
|
+
// 6. If "calendarRange" has selected dates and the new selection "start" differs from the current "calendarRange start", reset and make a new "start" selection.
|
|
11068
|
+
return setCalendarRange({ from: rangeFrom, to: undefined });
|
|
11069
|
+
}
|
|
11070
|
+
else if (calendarRangeTo && rangeTo && !isEqual(calendarRangeTo, rangeTo)) {
|
|
11071
|
+
// 7. If "calendarRange" has selected dates and the new selection "end" differs from the current "calendarRange end", reset and make a new "start" selection.
|
|
11072
|
+
return setCalendarRange({ from: rangeTo, to: undefined });
|
|
11073
|
+
}
|
|
11074
|
+
if (
|
|
11075
|
+
// 8. If selected "end" is before "context start", mark as "start" and display error
|
|
11076
|
+
rangeFrom &&
|
|
11077
|
+
rangeTo &&
|
|
11078
|
+
rangeContextFrom &&
|
|
11079
|
+
isBefore(rangeTo, rangeContextFrom)) {
|
|
11080
|
+
setCalendarHasError && setCalendarHasError(true);
|
|
11081
|
+
return setCalendarRange({ from: rangeTo, to: undefined });
|
|
11082
|
+
}
|
|
11083
|
+
setCalendarRange(range);
|
|
11058
11084
|
};
|
|
11059
11085
|
/////////
|
|
11060
11086
|
var disableFutureDates = function (_a) {
|
|
11061
|
-
var rangeFrom = _a.rangeFrom, checkOutRange = _a.checkOutRange, setDisabledDates = _a.setDisabledDates,
|
|
11087
|
+
var rangeFrom = _a.rangeFrom, checkOutRange = _a.checkOutRange, setDisabledDates = _a.setDisabledDates, newDisableCalendarDates = _a.newDisableCalendarDates;
|
|
11062
11088
|
if (rangeFrom && checkOutRange && setDisabledDates) {
|
|
11063
11089
|
// Get and parse data
|
|
11064
11090
|
var checkIn = addDays(checkOutRange.checkIn, 1);
|
|
11065
11091
|
var firstCheckOut = addDays(checkOutRange.firstCheckOut, -1);
|
|
11066
|
-
var noDatesRange =
|
|
11067
|
-
format(checkOutRange.firstCheckOut, dateFormat);
|
|
11068
|
-
// -------------------
|
|
11092
|
+
var noDatesRange = isEqual(checkIn, checkOutRange.firstCheckOut);
|
|
11069
11093
|
setDisabledDates(__spreadArray$1(__spreadArray$1([], __read(((newDisableCalendarDates === null || newDisableCalendarDates === void 0 ? void 0 : newDisableCalendarDates.disabledDates) || [])), false), [
|
|
11070
11094
|
{
|
|
11071
11095
|
from: noDatesRange ? undefined : checkIn,
|