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