willba-component-library 0.1.57 → 0.1.59
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/FilterBar.d.ts +3 -2
- package/lib/components/FilterBar/FilterBarTypes.d.ts +7 -0
- package/lib/components/FilterBar/components/calendar/Calendar.d.ts +3 -0
- package/lib/components/FilterBar/hooks/useFilterBar.d.ts +3 -3
- package/lib/components/FilterBar/utils/parseGuests.d.ts +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.esm.js +61 -28
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +61 -28
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +61 -28
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FilterBar/FilterBar.stories.tsx +4 -0
- package/src/components/FilterBar/FilterBar.tsx +21 -8
- package/src/components/FilterBar/FilterBarTypes.ts +9 -0
- package/src/components/FilterBar/components/calendar/Calendar.tsx +17 -3
- package/src/components/FilterBar/hooks/useFilterBar.tsx +15 -11
- package/src/components/FilterBar/utils/parseGuests.tsx +32 -10
- package/src/locales/en/filterBar.json +2 -1
- package/src/locales/fi/filterBar.json +2 -1
package/lib/index.umd.js
CHANGED
|
@@ -80,6 +80,16 @@
|
|
|
80
80
|
return ar;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
function __spreadArray$1(to, from, pack) {
|
|
84
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
85
|
+
if (ar || !(i in from)) {
|
|
86
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
87
|
+
ar[i] = from[i];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
91
|
+
}
|
|
92
|
+
|
|
83
93
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
84
94
|
var e = new Error(message);
|
|
85
95
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
@@ -3912,14 +3922,23 @@
|
|
|
3912
3922
|
|
|
3913
3923
|
var parseGuests = function (_a) {
|
|
3914
3924
|
var ageCategoryCounts = _a.ageCategoryCounts, ageCategories = _a.ageCategories;
|
|
3915
|
-
|
|
3925
|
+
var parsedData = Object.entries(ageCategoryCounts).reduce(function (acc, _a) {
|
|
3916
3926
|
var _b = __read(_a, 2), key = _b[0], value = _b[1];
|
|
3917
|
-
var
|
|
3927
|
+
var ageCategoryId = key[key.length - 1];
|
|
3928
|
+
var ageCategory = ageCategories.find(function (c) { return c.id === ageCategoryId; });
|
|
3918
3929
|
if (ageCategory && value) {
|
|
3919
|
-
|
|
3930
|
+
return {
|
|
3931
|
+
total: acc.total + value,
|
|
3932
|
+
html: __spreadArray$1(__spreadArray$1([], __read(acc.html), false), [
|
|
3933
|
+
"<span style=\"display: inline-block; width: 21px, text-align: center\">".concat(value, "</span>"),
|
|
3934
|
+
], false),
|
|
3935
|
+
};
|
|
3920
3936
|
}
|
|
3921
3937
|
return acc;
|
|
3922
|
-
},
|
|
3938
|
+
}, { total: 0, html: [] });
|
|
3939
|
+
var htmlString = parsedData.html.length > 1 ? parsedData.html.join(' + ') : '';
|
|
3940
|
+
return ((parsedData.total || htmlString) &&
|
|
3941
|
+
": ".concat(parsedData.total, " ").concat(htmlString ? "- ( ".concat(htmlString, " )") : ''));
|
|
3923
3942
|
};
|
|
3924
3943
|
|
|
3925
3944
|
var FilterSections;
|
|
@@ -3932,10 +3951,15 @@
|
|
|
3932
3951
|
(function (ViewApply) {
|
|
3933
3952
|
ViewApply["ROOMS"] = "roomFilters";
|
|
3934
3953
|
})(ViewApply || (ViewApply = {}));
|
|
3954
|
+
var Pages;
|
|
3955
|
+
(function (Pages) {
|
|
3956
|
+
Pages["ROOMS"] = "/rooms";
|
|
3957
|
+
Pages["EVENTS"] = "/events";
|
|
3958
|
+
})(Pages || (Pages = {}));
|
|
3935
3959
|
|
|
3936
3960
|
var useFilterBar = function (_a) {
|
|
3937
3961
|
var redirectUrl = _a.redirectUrl, currentViewApply = _a.currentViewApply, ageCategories = _a.ageCategories, onSubmit = _a.onSubmit;
|
|
3938
|
-
var _b = __read(React__default.useState(
|
|
3962
|
+
var _b = __read(React__default.useState(Pages.EVENTS), 2), selectedPath = _b[0], setSelectedPath = _b[1];
|
|
3939
3963
|
var _c = __read(React__default.useState(false), 2), selectedFilter = _c[0], setSelectedFilter = _c[1];
|
|
3940
3964
|
var _d = __read(React__default.useState(), 2), calendarRange = _d[0], setCalendarRange = _d[1];
|
|
3941
3965
|
var _e = __read(React__default.useState(0), 2), categories = _e[0], setCategories = _e[1];
|
|
@@ -3969,11 +3993,11 @@
|
|
|
3969
3993
|
// Handle default selected tab
|
|
3970
3994
|
if (typeof window === 'undefined')
|
|
3971
3995
|
return;
|
|
3972
|
-
var currentPath = window.location.pathname.includes(
|
|
3973
|
-
?
|
|
3974
|
-
: window.location.pathname.includes(
|
|
3975
|
-
?
|
|
3976
|
-
:
|
|
3996
|
+
var currentPath = window.location.pathname.includes(Pages.EVENTS)
|
|
3997
|
+
? Pages.EVENTS
|
|
3998
|
+
: window.location.pathname.includes(Pages.ROOMS)
|
|
3999
|
+
? Pages.ROOMS
|
|
4000
|
+
: Pages.EVENTS;
|
|
3977
4001
|
setSelectedPath(currentPath);
|
|
3978
4002
|
}, []);
|
|
3979
4003
|
var updateGuestsCount = function (id, newCount) {
|
|
@@ -4035,7 +4059,7 @@
|
|
|
4035
4059
|
var baseUrl = window.location.origin + window.location.pathname;
|
|
4036
4060
|
var updatedUrl = "".concat(baseUrl, "?").concat(updatedParams.toString());
|
|
4037
4061
|
handleSelectedFilter(false);
|
|
4038
|
-
if (onSubmit && selectedPath ===
|
|
4062
|
+
if (onSubmit && selectedPath === Pages.ROOMS) {
|
|
4039
4063
|
var updatedParamsObject_1 = {};
|
|
4040
4064
|
updatedParams.forEach(function (value, key) {
|
|
4041
4065
|
if (value)
|
|
@@ -4063,15 +4087,14 @@
|
|
|
4063
4087
|
finally { if (e_3) throw e_3.error; }
|
|
4064
4088
|
}
|
|
4065
4089
|
handleSelectedFilter(false);
|
|
4066
|
-
return onSubmit && selectedPath ===
|
|
4090
|
+
return onSubmit && selectedPath === Pages.ROOMS
|
|
4067
4091
|
? onSubmit(newParams)
|
|
4068
4092
|
: (window.location.href = "".concat(redirectUrl, "/").concat(selectedPath).concat(querySearchParams ? "?".concat(querySearchParams.toString()) : ''));
|
|
4069
4093
|
}
|
|
4070
4094
|
};
|
|
4071
4095
|
var handleResetFilters = function () {
|
|
4072
4096
|
setAgeCategoryCounts({});
|
|
4073
|
-
|
|
4074
|
-
setSelectedFilter(false);
|
|
4097
|
+
setCalendarRange(undefined);
|
|
4075
4098
|
};
|
|
4076
4099
|
return {
|
|
4077
4100
|
selectedFilter: selectedFilter,
|
|
@@ -6415,7 +6438,8 @@
|
|
|
6415
6438
|
labelPlaceholder: "Add guests",
|
|
6416
6439
|
title: "Who's coming?",
|
|
6417
6440
|
adultsLabel: "Adults",
|
|
6418
|
-
kidsLabel: "kids"
|
|
6441
|
+
kidsLabel: "kids",
|
|
6442
|
+
guestsLabel: "Guests"
|
|
6419
6443
|
};
|
|
6420
6444
|
var categories$1 = {
|
|
6421
6445
|
label: "Categories",
|
|
@@ -6449,7 +6473,8 @@
|
|
|
6449
6473
|
labelPlaceholder: "Lisää vieraat",
|
|
6450
6474
|
title: "Ketkä ovat tulossa?",
|
|
6451
6475
|
adultsLabel: "Aikuiset",
|
|
6452
|
-
kidsLabel: "lapset"
|
|
6476
|
+
kidsLabel: "lapset",
|
|
6477
|
+
guestsLabel: "Gieraita"
|
|
6453
6478
|
};
|
|
6454
6479
|
var categories = {
|
|
6455
6480
|
label: "Kategoriat",
|
|
@@ -10651,17 +10676,19 @@
|
|
|
10651
10676
|
styleInject(css_248z$3);
|
|
10652
10677
|
|
|
10653
10678
|
var Calendar = React__default.forwardRef(function (_a, ref) {
|
|
10654
|
-
var
|
|
10679
|
+
var _b;
|
|
10680
|
+
var calendarRange = _a.calendarRange, setCalendarRange = _a.setCalendarRange, calendarOffset = _a.calendarOffset, selectedPath = _a.selectedPath;
|
|
10655
10681
|
var isTablet = reactResponsiveExports.useMediaQuery({ maxWidth: 960 });
|
|
10656
10682
|
React__default.useEffect(function () {
|
|
10657
10683
|
if (!calendarRange)
|
|
10658
10684
|
setCalendarRange(undefined);
|
|
10659
10685
|
}, []);
|
|
10660
10686
|
var today = startOfDay(new Date());
|
|
10687
|
+
var daysToOffsetCalendar = (_b = Object.entries(calendarOffset)) === null || _b === void 0 ? void 0 : _b.find(function (page) { return selectedPath.substring(1) === page[0]; });
|
|
10661
10688
|
var disabledDays = [
|
|
10662
10689
|
{
|
|
10663
|
-
from: addDays(today, -2),
|
|
10664
|
-
to: addDays(today, -
|
|
10690
|
+
from: addDays(today, !!(daysToOffsetCalendar === null || daysToOffsetCalendar === void 0 ? void 0 : daysToOffsetCalendar.length) ? daysToOffsetCalendar[1] : -2),
|
|
10691
|
+
to: addDays(today, -100),
|
|
10665
10692
|
},
|
|
10666
10693
|
];
|
|
10667
10694
|
var selectedStartDate = calendarRange === null || calendarRange === void 0 ? void 0 : calendarRange.from;
|
|
@@ -10709,7 +10736,7 @@
|
|
|
10709
10736
|
styleInject(css_248z);
|
|
10710
10737
|
|
|
10711
10738
|
function FilterBar(_a) {
|
|
10712
|
-
var language = _a.language, _b = _a.ageCategories, ageCategories = _b === void 0 ? AGE_CATEGORIES_FALLBACK : _b, _c = _a.redirectUrl, redirectUrl = _c === void 0 ? REDIRECT_URL_FALLBACK : _c, palette = _a.palette, currentViewApply = _a.currentViewApply, onSubmit = _a.onSubmit, fullWidth = _a.fullWidth;
|
|
10739
|
+
var language = _a.language, _b = _a.ageCategories, ageCategories = _b === void 0 ? AGE_CATEGORIES_FALLBACK : _b, _c = _a.redirectUrl, redirectUrl = _c === void 0 ? REDIRECT_URL_FALLBACK : _c, palette = _a.palette, currentViewApply = _a.currentViewApply, onSubmit = _a.onSubmit, fullWidth = _a.fullWidth, calendarOffset = _a.calendarOffset;
|
|
10713
10740
|
var themePalette = useTheme({ palette: palette });
|
|
10714
10741
|
// Translations
|
|
10715
10742
|
useUpdateTranslations({ language: language });
|
|
@@ -10720,11 +10747,11 @@
|
|
|
10720
10747
|
currentViewApply: currentViewApply,
|
|
10721
10748
|
ageCategories: ageCategories,
|
|
10722
10749
|
onSubmit: onSubmit,
|
|
10723
|
-
}), 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;
|
|
10750
|
+
}), 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, handleResetFilters = _d.handleResetFilters;
|
|
10724
10751
|
// Default selected tab when tabs are hidden
|
|
10725
10752
|
React__default.useEffect(function () {
|
|
10726
10753
|
if (currentViewApply === ViewApply.ROOMS) {
|
|
10727
|
-
setSelectedPath(
|
|
10754
|
+
setSelectedPath(Pages.ROOMS);
|
|
10728
10755
|
}
|
|
10729
10756
|
}, []);
|
|
10730
10757
|
// Scroll in to view
|
|
@@ -10744,21 +10771,27 @@
|
|
|
10744
10771
|
var parsedGuests = parseGuests({ ageCategoryCounts: ageCategoryCounts, ageCategories: ageCategories });
|
|
10745
10772
|
return (React__default.createElement("div", { className: "will-root ".concat(fullWidth ? 'is-full-width' : ''), style: themePalette },
|
|
10746
10773
|
!currentViewApply && (React__default.createElement("div", { className: "will-filter-bar-tabs", ref: !currentViewApply ? targetFilterBarRef : null },
|
|
10747
|
-
React__default.createElement(TabButton, { label: t('tabs.events'), onClick: function () {
|
|
10748
|
-
|
|
10774
|
+
React__default.createElement(TabButton, { label: t('tabs.events'), onClick: function () {
|
|
10775
|
+
setSelectedPath(Pages.EVENTS), handleResetFilters();
|
|
10776
|
+
}, active: selectedPath === Pages.EVENTS }),
|
|
10777
|
+
React__default.createElement(TabButton, { label: t('tabs.rooms'), onClick: function () {
|
|
10778
|
+
setSelectedPath(Pages.ROOMS), handleResetFilters();
|
|
10779
|
+
}, active: selectedPath === Pages.ROOMS }))),
|
|
10749
10780
|
React__default.createElement("div", { className: "will-filter-bar-header", ref: currentViewApply ? targetFilterBarRef : null },
|
|
10750
10781
|
React__default.createElement(SelectButton, { label: t('calendar.label'), description: parsedDates
|
|
10751
10782
|
? parsedDates
|
|
10752
|
-
: selectedPath ===
|
|
10783
|
+
: selectedPath === Pages.ROOMS
|
|
10753
10784
|
? t('calendar.roomsLabelPlaceholder')
|
|
10754
10785
|
: t('calendar.eventsLabelPlaceholder'), onClick: function () { return handleSelectedFilter(FilterSections.CALENDAR); }, active: selectedFilter === FilterSections.CALENDAR }),
|
|
10755
|
-
selectedPath ===
|
|
10786
|
+
selectedPath === Pages.ROOMS && (React__default.createElement(React__default.Fragment, null,
|
|
10756
10787
|
React__default.createElement(Divider, null),
|
|
10757
|
-
React__default.createElement(SelectButton, { label: t('guests.label'), description: parsedGuests
|
|
10788
|
+
React__default.createElement(SelectButton, { label: t('guests.label'), description: parsedGuests
|
|
10789
|
+
? t('guests.guestsLabel') + parsedGuests
|
|
10790
|
+
: t('guests.labelPlaceholder'), onClick: function () { return handleSelectedFilter(FilterSections.GUESTS); }, active: selectedFilter === FilterSections.GUESTS }))),
|
|
10758
10791
|
React__default.createElement(SubmitButton, { onClick: handleSubmit })),
|
|
10759
10792
|
selectedFilter && (React__default.createElement("div", { className: "will-filter-bar-container", style: currentViewApply && !isMobile ? { top: 66 } : {} },
|
|
10760
10793
|
React__default.createElement(CloseButton, { handleClose: function () { return handleSelectedFilter(false); } }),
|
|
10761
|
-
selectedFilter === FilterSections.CALENDAR && (React__default.createElement(Calendar, { calendarRange: calendarRange, setCalendarRange: setCalendarRange, ref: filtersRef })),
|
|
10794
|
+
selectedFilter === FilterSections.CALENDAR && (React__default.createElement(Calendar, { calendarRange: calendarRange, setCalendarRange: setCalendarRange, ref: filtersRef, calendarOffset: calendarOffset, selectedPath: selectedPath })),
|
|
10762
10795
|
selectedFilter === FilterSections.GUESTS && (React__default.createElement(Guests, { updateGuestsCount: updateGuestsCount, ageCategories: ageCategories, ageCategoryCounts: ageCategoryCounts, ref: filtersRef })),
|
|
10763
10796
|
selectedFilter === FilterSections.CATEGORIES && (React__default.createElement(Categories, { categories: categories, setCategories: setCategories }))))));
|
|
10764
10797
|
}
|