willba-component-library 0.1.41 → 0.1.43
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/FilterBar/hooks/useFilterBar.d.ts +3 -2
- package/lib/index.esm.js +43 -22
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +43 -22
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +43 -22
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FilterBar/FilterBar.stories.tsx +1 -1
- package/src/components/FilterBar/FilterBar.tsx +1 -1
- package/src/components/FilterBar/components/calendar/Calendar.tsx +1 -1
- package/src/components/FilterBar/components/guests/GuestCount/GuestCount.tsx +2 -6
- package/src/components/FilterBar/components/guests/Guests.tsx +1 -1
- package/src/components/FilterBar/hooks/useFilterBar.tsx +56 -15
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { DateRange } from 'react-day-picker';
|
|
3
|
-
import { AgeCategoryCount } from '../FilterBarTypes';
|
|
3
|
+
import { AgeCategoryCount, AgeCategoryType } from '../FilterBarTypes';
|
|
4
4
|
type Props = {
|
|
5
5
|
redirectUrl?: string;
|
|
6
6
|
currentViewApply?: string;
|
|
7
|
+
ageCategories?: AgeCategoryType[];
|
|
7
8
|
};
|
|
8
|
-
export declare const useFilterBar: ({ redirectUrl, currentViewApply }: Props) => {
|
|
9
|
+
export declare const useFilterBar: ({ redirectUrl, currentViewApply, ageCategories, }: Props) => {
|
|
9
10
|
selectedFilter: number | boolean;
|
|
10
11
|
ageCategoryCounts: AgeCategoryCount;
|
|
11
12
|
categories: number;
|
package/lib/index.esm.js
CHANGED
|
@@ -3901,7 +3901,7 @@ var parseGuests = function (_a) {
|
|
|
3901
3901
|
};
|
|
3902
3902
|
|
|
3903
3903
|
var useFilterBar = function (_a) {
|
|
3904
|
-
var redirectUrl = _a.redirectUrl, currentViewApply = _a.currentViewApply;
|
|
3904
|
+
var redirectUrl = _a.redirectUrl, currentViewApply = _a.currentViewApply, ageCategories = _a.ageCategories;
|
|
3905
3905
|
var _b = __read(useState('/events'), 2), selectedPath = _b[0], setSelectedPath = _b[1];
|
|
3906
3906
|
var _c = __read(useState(false), 2), selectedFilter = _c[0], setSelectedFilter = _c[1];
|
|
3907
3907
|
var _d = __read(useState(), 2), calendarRange = _d[0], setCalendarRange = _d[1];
|
|
@@ -3923,6 +3923,7 @@ var useFilterBar = function (_a) {
|
|
|
3923
3923
|
setCategories(parsedCategories);
|
|
3924
3924
|
}, []);
|
|
3925
3925
|
useEffect(function () {
|
|
3926
|
+
// Handle hide scroll bar on mobile
|
|
3926
3927
|
if (typeof window === 'undefined')
|
|
3927
3928
|
return;
|
|
3928
3929
|
document.body.style.overflow =
|
|
@@ -3932,15 +3933,15 @@ var useFilterBar = function (_a) {
|
|
|
3932
3933
|
};
|
|
3933
3934
|
}, [selectedFilter]);
|
|
3934
3935
|
useEffect(function () {
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3936
|
+
// Handle default selected tab
|
|
3937
|
+
if (typeof window === 'undefined')
|
|
3938
|
+
return;
|
|
3939
|
+
var currentPath = window.location.pathname.includes('/events')
|
|
3940
|
+
? '/events'
|
|
3941
|
+
: window.location.pathname.includes('/rooms')
|
|
3942
|
+
? '/rooms'
|
|
3943
|
+
: '/events';
|
|
3944
|
+
setSelectedPath(currentPath);
|
|
3944
3945
|
}, []);
|
|
3945
3946
|
var updateGuestsCount = function (id, newCount) {
|
|
3946
3947
|
setAgeCategoryCounts(function (prevCounts) {
|
|
@@ -3959,9 +3960,10 @@ var useFilterBar = function (_a) {
|
|
|
3959
3960
|
: '',
|
|
3960
3961
|
endDate: (calendarRange === null || calendarRange === void 0 ? void 0 : calendarRange.to) ? format(calendarRange.to, 'yyyy-MM-dd') : '',
|
|
3961
3962
|
categories: categories,
|
|
3962
|
-
ageCategoryCounts:
|
|
3963
|
-
|
|
3964
|
-
:
|
|
3963
|
+
ageCategoryCounts: handleAgeCategoryRules({
|
|
3964
|
+
ageCategoryCounts: ageCategoryCounts,
|
|
3965
|
+
ageCategories: ageCategories,
|
|
3966
|
+
}),
|
|
3965
3967
|
};
|
|
3966
3968
|
if (currentViewApply) {
|
|
3967
3969
|
var currentSearchParams = new URLSearchParams(window.location.search);
|
|
@@ -4045,6 +4047,27 @@ var useFilterBar = function (_a) {
|
|
|
4045
4047
|
setSelectedPath: setSelectedPath,
|
|
4046
4048
|
};
|
|
4047
4049
|
};
|
|
4050
|
+
////////////
|
|
4051
|
+
var handleAgeCategoryRules = function (_a) {
|
|
4052
|
+
var ageCategoryCounts = _a.ageCategoryCounts, ageCategories = _a.ageCategories;
|
|
4053
|
+
if (ageCategories === null || ageCategories === void 0 ? void 0 : ageCategories.length) {
|
|
4054
|
+
ageCategories === null || ageCategories === void 0 ? void 0 : ageCategories.map(function (a) {
|
|
4055
|
+
if (a.minVal) {
|
|
4056
|
+
// Age categories rules
|
|
4057
|
+
Object.entries(ageCategoryCounts).reduce(function (acc, c) {
|
|
4058
|
+
return acc + c[1];
|
|
4059
|
+
}, 0);
|
|
4060
|
+
var ageCategory = ageCategoryCounts["guests-".concat(a.id)];
|
|
4061
|
+
if (!ageCategory) {
|
|
4062
|
+
ageCategoryCounts["guests-".concat(a.id)] = a.minVal;
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
});
|
|
4066
|
+
}
|
|
4067
|
+
return Object.entries(ageCategoryCounts).length
|
|
4068
|
+
? JSON.stringify(ageCategoryCounts)
|
|
4069
|
+
: '';
|
|
4070
|
+
};
|
|
4048
4071
|
|
|
4049
4072
|
var useScrollInToView = function (_a) {
|
|
4050
4073
|
var selectedFilter = _a.selectedFilter;
|
|
@@ -6577,10 +6600,6 @@ styleInject(css_248z$6);
|
|
|
6577
6600
|
|
|
6578
6601
|
function GuestCount(_a) {
|
|
6579
6602
|
var label = _a.label, sortOrder = _a.sortOrder, id = _a.id, updateGuestsCount = _a.updateGuestsCount, count = _a.count, minVal = _a.minVal;
|
|
6580
|
-
useEffect(function () {
|
|
6581
|
-
if (minVal)
|
|
6582
|
-
updateGuestsCount("guests-".concat(id), minVal);
|
|
6583
|
-
}, []);
|
|
6584
6603
|
var handleDecrement = function () {
|
|
6585
6604
|
if (count > minVal) {
|
|
6586
6605
|
updateGuestsCount("guests-".concat(id), count - 1);
|
|
@@ -6592,8 +6611,8 @@ function GuestCount(_a) {
|
|
|
6592
6611
|
return (React__default__default.createElement("div", { className: "will-guests-filter-inner", style: { order: "".concat(sortOrder) } },
|
|
6593
6612
|
React__default__default.createElement("p", { className: "will-guests-filter-label" }, label),
|
|
6594
6613
|
React__default__default.createElement("div", { className: "will-guests-filter-counter" },
|
|
6595
|
-
React__default__default.createElement("button", { className: "will-guests-filter-counter-button", onClick: handleDecrement, disabled: minVal && count
|
|
6596
|
-
cursor: minVal && count
|
|
6614
|
+
React__default__default.createElement("button", { className: "will-guests-filter-counter-button", onClick: handleDecrement, disabled: minVal && count <= minVal ? true : false, style: {
|
|
6615
|
+
cursor: minVal && count <= minVal
|
|
6597
6616
|
? 'initial'
|
|
6598
6617
|
: !minVal && count < 1
|
|
6599
6618
|
? 'initial'
|
|
@@ -6612,7 +6631,7 @@ var Guests = forwardRef(function (_a, ref) {
|
|
|
6612
6631
|
var t = useTranslation('filterBar').t;
|
|
6613
6632
|
return (React__default__default.createElement("div", { className: "will-filter-bar-guests", ref: ref },
|
|
6614
6633
|
React__default__default.createElement("h3", { className: "will-guests-filter-title" }, t('guests.title')),
|
|
6615
|
-
React__default__default.createElement("div", { className: "will-guests-filter-container" }, ageCategories === null || ageCategories === void 0 ? void 0 : ageCategories.map(function (category) { return (React__default__default.createElement(GuestCount, { key: category.id, id: parseInt(category.id), label: category.name, minVal: category.minVal, sortOrder: category.sortOrder, updateGuestsCount: updateGuestsCount, count: ageCategoryCounts["guests-".concat(category.id)] ||
|
|
6634
|
+
React__default__default.createElement("div", { className: "will-guests-filter-container" }, ageCategories === null || ageCategories === void 0 ? void 0 : ageCategories.map(function (category) { return (React__default__default.createElement(GuestCount, { key: category.id, id: parseInt(category.id), label: category.name, minVal: category.minVal, sortOrder: category.sortOrder, updateGuestsCount: updateGuestsCount, count: ageCategoryCounts["guests-".concat(category.id)] || 0 })); }))));
|
|
6616
6635
|
});
|
|
6617
6636
|
|
|
6618
6637
|
/******************************************************************************
|
|
@@ -10605,7 +10624,9 @@ var Calendar = forwardRef(function (_a, ref) {
|
|
|
10605
10624
|
}, []);
|
|
10606
10625
|
return (React__default__default.createElement("div", { className: "will-filter-bar-calendar", ref: ref },
|
|
10607
10626
|
React__default__default.createElement("div", { className: "will-calendar-filter-container" },
|
|
10608
|
-
React__default__default.createElement(DayPicker, { id: "will-calendar", mode: "range",
|
|
10627
|
+
React__default__default.createElement(DayPicker, { id: "will-calendar", mode: "range",
|
|
10628
|
+
//showOutsideDays
|
|
10629
|
+
numberOfMonths: !isTablet ? 2 : 1, weekStartsOn: 1, selected: calendarRange, onSelect: setCalendarRange, modifiersClassNames: {
|
|
10609
10630
|
today: 'my-today',
|
|
10610
10631
|
}, modifiersStyles: {
|
|
10611
10632
|
disabled: { opacity: '0.2' },
|
|
@@ -10653,7 +10674,7 @@ function FilterBar(_a) {
|
|
|
10653
10674
|
useUpdateTranslations({ language: language });
|
|
10654
10675
|
var t = useTranslation('filterBar').t;
|
|
10655
10676
|
// Filters
|
|
10656
|
-
var _d = useFilterBar({ redirectUrl: redirectUrl, currentViewApply: currentViewApply }), selectedFilter = _d.selectedFilter, ageCategoryCounts = _d.ageCategoryCounts, categories = _d.categories, calendarRange = _d.calendarRange, selectedPath = _d.selectedPath, setCalendarRange = _d.setCalendarRange, setCategories = _d.setCategories, handleSelectedFilter = _d.handleSelectedFilter, handleSubmit = _d.handleSubmit, updateGuestsCount = _d.updateGuestsCount, setSelectedPath = _d.setSelectedPath;
|
|
10677
|
+
var _d = useFilterBar({ redirectUrl: redirectUrl, currentViewApply: currentViewApply, ageCategories: ageCategories }), selectedFilter = _d.selectedFilter, ageCategoryCounts = _d.ageCategoryCounts, categories = _d.categories, calendarRange = _d.calendarRange, selectedPath = _d.selectedPath, setCalendarRange = _d.setCalendarRange, setCategories = _d.setCategories, handleSelectedFilter = _d.handleSelectedFilter, handleSubmit = _d.handleSubmit, updateGuestsCount = _d.updateGuestsCount, setSelectedPath = _d.setSelectedPath;
|
|
10657
10678
|
// Default selected tab
|
|
10658
10679
|
useEffect(function () {
|
|
10659
10680
|
if (currentViewApply === 'roomFilters') {
|