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