willba-component-library 0.3.19 → 0.3.20

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/README.md CHANGED
@@ -107,7 +107,7 @@ ReactDOM.render(<App />, document.querySelector('#app'))
107
107
 
108
108
  <script src="https://unpkg.com/react@18.3.1/umd/react.production.min.js"></script>
109
109
  <script src="https://unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js"></script>
110
- <script src="https://cdn.jsdelivr.net/npm/willba-component-library@0.3.19/lib/index.umd.js"></script>
110
+ <script src="https://cdn.jsdelivr.net/npm/willba-component-library@0.3.20/lib/index.umd.js"></script>
111
111
 
112
112
  <script>
113
113
  const renderFilterBar = async () => {
@@ -1,7 +1,8 @@
1
1
  export declare const useFilterUi: (selectedFilter: string | boolean) => {
2
2
  previouslyFocusedButtonRef: import("react").MutableRefObject<HTMLButtonElement | null>;
3
3
  isMobile: boolean;
4
- targetFilterBarRef: import("react").MutableRefObject<HTMLDivElement | null>;
4
+ tabsRef: import("react").MutableRefObject<HTMLDivElement | null>;
5
5
  panelRef: import("react").MutableRefObject<HTMLDivElement | null>;
6
6
  buttonRefs: import("react").MutableRefObject<Record<string, HTMLButtonElement | null>>;
7
+ filtersRef: import("react").MutableRefObject<HTMLDivElement | null>;
7
8
  };
@@ -2,11 +2,11 @@ import { CSSProperties, MutableRefObject, RefObject } from 'react';
2
2
  type Props = {
3
3
  selectedFilter: string | boolean;
4
4
  panelRef: RefObject<HTMLDivElement | null>;
5
- targetFilterBarRef: RefObject<HTMLDivElement | null>;
5
+ filtersRef: RefObject<HTMLDivElement | null>;
6
6
  buttonRefs: MutableRefObject<Record<string, HTMLButtonElement | null>>;
7
7
  isMobile: boolean;
8
8
  };
9
- export declare const usePanelPosition: ({ selectedFilter, panelRef, targetFilterBarRef, buttonRefs, isMobile, }: Props) => {
9
+ export declare const usePanelPosition: ({ selectedFilter, panelRef, filtersRef, buttonRefs, isMobile, }: Props) => {
10
10
  localStyles: CSSProperties;
11
11
  };
12
12
  export {};
@@ -3,6 +3,6 @@ type Props = {
3
3
  };
4
4
  export declare const useScrollInToView: ({ selectedFilter }: Props) => {
5
5
  isMobile: boolean;
6
- targetFilterBarRef: import("react").MutableRefObject<HTMLDivElement | null>;
6
+ tabsRef: import("react").MutableRefObject<HTMLDivElement | null>;
7
7
  };
8
8
  export {};
@@ -1,4 +1,4 @@
1
- import React, { PropsWithChildren, RefObject, MutableRefObject } from 'react';
1
+ import React, { PropsWithChildren, MutableRefObject } from 'react';
2
2
  import { DateRange } from 'react-day-picker';
3
3
  import { AgeCategoryCount, Location, FilterBarTypes } from '../FilterBarTypes';
4
4
  type FilterBarProviderProps = PropsWithChildren<FilterBarTypes>;
@@ -23,8 +23,9 @@ type FilterBarContextType = FilterBarTypes & {
23
23
  previouslyFocusedButtonRef: MutableRefObject<HTMLButtonElement | null>;
24
24
  panelRef: MutableRefObject<HTMLDivElement | null>;
25
25
  buttonRefs: MutableRefObject<Record<string, HTMLButtonElement | null>>;
26
+ filtersRef: MutableRefObject<HTMLDivElement | null>;
26
27
  isMobile: boolean;
27
- targetFilterBarRef: RefObject<HTMLDivElement>;
28
+ tabsRef: MutableRefObject<HTMLDivElement | null>;
28
29
  };
29
30
  export declare const FilterBarProvider: ({ children, language, ageCategories, redirectUrl, palette, onSubmit, fullWidth, disableCalendarDates, mode, tabs, outerLoading, locations, }: FilterBarProviderProps) => React.JSX.Element;
30
31
  export declare const useFilterBar: () => FilterBarContextType;
@@ -2,6 +2,6 @@ type Props = {
2
2
  handleSelectedFilter: (arg: boolean) => void;
3
3
  };
4
4
  export declare const useCloseFilterSection: ({ handleSelectedFilter }: Props) => {
5
- filtersRef: import("react").MutableRefObject<HTMLDivElement | null>;
5
+ filterSectionRef: import("react").MutableRefObject<HTMLDivElement | null>;
6
6
  };
7
7
  export {};
package/lib/index.esm.js CHANGED
@@ -2879,11 +2879,11 @@ var useUpdateTranslations = function (_a) {
2879
2879
  // TODO - Refactor and rename this hook
2880
2880
  var useCloseFilterSection = function (_a) {
2881
2881
  var handleSelectedFilter = _a.handleSelectedFilter;
2882
- var filtersRef = useRef(null);
2882
+ var filterSectionRef = useRef(null);
2883
2883
  useEffect(function () {
2884
2884
  var handleClickOutside = function (event) {
2885
- if (filtersRef.current &&
2886
- !filtersRef.current.contains(event.target)) {
2885
+ if (filterSectionRef.current &&
2886
+ !filterSectionRef.current.contains(event.target)) {
2887
2887
  handleSelectedFilter(false);
2888
2888
  }
2889
2889
  };
@@ -2891,8 +2891,8 @@ var useCloseFilterSection = function (_a) {
2891
2891
  return function () {
2892
2892
  document.removeEventListener('mousedown', handleClickOutside);
2893
2893
  };
2894
- }, [filtersRef]);
2895
- return { filtersRef: filtersRef };
2894
+ }, [filterSectionRef]);
2895
+ return { filterSectionRef: filterSectionRef };
2896
2896
  };
2897
2897
 
2898
2898
  var useAutoFocus = function (autoFocus) {
@@ -2962,22 +2962,22 @@ var Pages;
2962
2962
  var useScrollInToView = function (_a) {
2963
2963
  var selectedFilter = _a.selectedFilter;
2964
2964
  var _b = __read(useState(true), 2), isMobile = _b[0], setIsMobile = _b[1];
2965
- var targetFilterBarRef = useRef(null);
2965
+ var tabsRef = useRef(null);
2966
2966
  useEffect(function () {
2967
2967
  if (typeof window !== 'undefined' && window.innerWidth > 960) {
2968
2968
  setIsMobile(false);
2969
2969
  return;
2970
2970
  }
2971
- if (targetFilterBarRef.current && selectedFilter) {
2971
+ if (tabsRef.current && selectedFilter) {
2972
2972
  window.scrollTo({
2973
2973
  behavior: 'smooth',
2974
- top: targetFilterBarRef.current.getBoundingClientRect().top -
2974
+ top: tabsRef.current.getBoundingClientRect().top -
2975
2975
  document.body.getBoundingClientRect().top -
2976
2976
  30,
2977
2977
  });
2978
2978
  }
2979
2979
  }, [selectedFilter]);
2980
- return { isMobile: isMobile, targetFilterBarRef: targetFilterBarRef };
2980
+ return { isMobile: isMobile, tabsRef: tabsRef };
2981
2981
  };
2982
2982
 
2983
2983
  var useFilterState = function (_a) {
@@ -6815,18 +6815,20 @@ var useFilterUi = function (selectedFilter) {
6815
6815
  var buttonRefs = useRef({});
6816
6816
  var panelRef = useRef(null);
6817
6817
  var previouslyFocusedButtonRef = useRef(null);
6818
- var _a = useScrollInToView({ selectedFilter: selectedFilter }), isMobile = _a.isMobile, targetFilterBarRef = _a.targetFilterBarRef;
6818
+ var filtersRef = useRef(null);
6819
+ var _a = useScrollInToView({ selectedFilter: selectedFilter }), isMobile = _a.isMobile, tabsRef = _a.tabsRef;
6819
6820
  return {
6820
6821
  previouslyFocusedButtonRef: previouslyFocusedButtonRef,
6821
6822
  isMobile: isMobile,
6822
- targetFilterBarRef: targetFilterBarRef,
6823
+ tabsRef: tabsRef,
6823
6824
  panelRef: panelRef,
6824
6825
  buttonRefs: buttonRefs,
6826
+ filtersRef: filtersRef,
6825
6827
  };
6826
6828
  };
6827
6829
 
6828
6830
  var usePanelPosition = function (_a) {
6829
- var selectedFilter = _a.selectedFilter, panelRef = _a.panelRef, targetFilterBarRef = _a.targetFilterBarRef, buttonRefs = _a.buttonRefs, isMobile = _a.isMobile;
6831
+ var selectedFilter = _a.selectedFilter, panelRef = _a.panelRef, filtersRef = _a.filtersRef, buttonRefs = _a.buttonRefs, isMobile = _a.isMobile;
6830
6832
  var _b = __read(useState({}), 2), localStyles = _b[0], setLocalStyles = _b[1];
6831
6833
  useLayoutEffect(function () {
6832
6834
  if (!selectedFilter || typeof selectedFilter !== 'string' || isMobile) {
@@ -6834,7 +6836,7 @@ var usePanelPosition = function (_a) {
6834
6836
  return;
6835
6837
  }
6836
6838
  var panel = panelRef.current;
6837
- var container = targetFilterBarRef.current;
6839
+ var container = filtersRef.current;
6838
6840
  var button = buttonRefs.current[selectedFilter];
6839
6841
  if (!panel || !container || !button)
6840
6842
  return;
@@ -6888,7 +6890,8 @@ var FilterBarProvider = function (_a) {
6888
6890
  outerLoading,
6889
6891
  locations,
6890
6892
  filterUi.isMobile,
6891
- filterUi.targetFilterBarRef,
6893
+ filterUi.tabsRef,
6894
+ filterUi.filtersRef,
6892
6895
  ]);
6893
6896
  return (React__default.createElement(FilterBarContext.Provider, { value: contextValue }, children));
6894
6897
  };
@@ -12144,33 +12147,31 @@ var css_248z$5 = ".will-filter-bar-panels {\n background-color: var(--will-whit
12144
12147
  styleInject(css_248z$5);
12145
12148
 
12146
12149
  var FilterPanels = function () {
12147
- var _a = useFilterBar(), categories = _a.categories, calendarRange = _a.calendarRange, selectedFilter = _a.selectedFilter, selectedPath = _a.selectedPath, ageCategoryCounts = _a.ageCategoryCounts, selectedLocations = _a.selectedLocations, mode = _a.mode, tabs = _a.tabs, disableCalendarDates = _a.disableCalendarDates, ageCategories = _a.ageCategories, locations = _a.locations, language = _a.language, isMobile = _a.isMobile, panelRef = _a.panelRef, buttonRefs = _a.buttonRefs, targetFilterBarRef = _a.targetFilterBarRef, setSelectedLocations = _a.setSelectedLocations, setCalendarRange = _a.setCalendarRange, handleSelectedFilter = _a.handleSelectedFilter, updateGuestsCount = _a.updateGuestsCount, setCategories = _a.setCategories;
12150
+ var _a = useFilterBar(), categories = _a.categories, calendarRange = _a.calendarRange, selectedFilter = _a.selectedFilter, selectedPath = _a.selectedPath, ageCategoryCounts = _a.ageCategoryCounts, selectedLocations = _a.selectedLocations, mode = _a.mode, tabs = _a.tabs, disableCalendarDates = _a.disableCalendarDates, ageCategories = _a.ageCategories, locations = _a.locations, language = _a.language, isMobile = _a.isMobile, panelRef = _a.panelRef, buttonRefs = _a.buttonRefs, filtersRef = _a.filtersRef, setSelectedLocations = _a.setSelectedLocations, setCalendarRange = _a.setCalendarRange, handleSelectedFilter = _a.handleSelectedFilter, updateGuestsCount = _a.updateGuestsCount, setCategories = _a.setCategories;
12148
12151
  // Handle close filter section
12149
- var filtersRef = useCloseFilterSection({ handleSelectedFilter: handleSelectedFilter }).filtersRef;
12152
+ var filterSectionRef = useCloseFilterSection({ handleSelectedFilter: handleSelectedFilter }).filterSectionRef;
12150
12153
  var localStyles = usePanelPosition({
12151
12154
  selectedFilter: selectedFilter,
12152
12155
  panelRef: panelRef,
12153
- targetFilterBarRef: targetFilterBarRef,
12156
+ filtersRef: filtersRef,
12154
12157
  buttonRefs: buttonRefs,
12155
12158
  isMobile: isMobile,
12156
12159
  }).localStyles;
12157
12160
  var renderContent = function () {
12158
12161
  switch (selectedFilter) {
12159
12162
  case FilterSections.CALENDAR:
12160
- return (React__default.createElement(Dates, { autoFocus: true, ref: filtersRef, onClose: function () { return handleSelectedFilter(false); }, calendarRange: calendarRange, setCalendarRange: setCalendarRange, disableCalendarDates: disableCalendarDates, selectedPath: selectedPath, language: language }));
12163
+ return (React__default.createElement(Dates, { autoFocus: true, ref: filterSectionRef, onClose: function () { return handleSelectedFilter(false); }, calendarRange: calendarRange, setCalendarRange: setCalendarRange, disableCalendarDates: disableCalendarDates, selectedPath: selectedPath, language: language }));
12161
12164
  case FilterSections.GUESTS:
12162
- return (React__default.createElement(Guests, { autoFocus: true, ref: filtersRef, ageCategories: ageCategories, ageCategoryCounts: ageCategoryCounts, updateGuestsCount: updateGuestsCount, onClose: function () { return handleSelectedFilter(false); } }));
12165
+ return (React__default.createElement(Guests, { autoFocus: true, ref: filterSectionRef, ageCategories: ageCategories, ageCategoryCounts: ageCategoryCounts, updateGuestsCount: updateGuestsCount, onClose: function () { return handleSelectedFilter(false); } }));
12163
12166
  case FilterSections.CATEGORIES:
12164
12167
  return (React__default.createElement(Categories, { categories: categories, setCategories: setCategories }));
12165
12168
  case FilterSections.LOCATIONS:
12166
- return (React__default.createElement(Locations, { autoFocus: true, ref: filtersRef, locations: locations === null || locations === void 0 ? void 0 : locations.data, language: language, selectedLocations: selectedLocations, setSelectedLocations: setSelectedLocations, multiSelect: locations === null || locations === void 0 ? void 0 : locations.multiSelect, onClose: function () { return handleSelectedFilter(false); } }));
12169
+ return (React__default.createElement(Locations, { autoFocus: true, ref: filterSectionRef, locations: locations === null || locations === void 0 ? void 0 : locations.data, language: language, selectedLocations: selectedLocations, setSelectedLocations: setSelectedLocations, multiSelect: locations === null || locations === void 0 ? void 0 : locations.multiSelect, onClose: function () { return handleSelectedFilter(false); } }));
12167
12170
  default:
12168
12171
  return null;
12169
12172
  }
12170
12173
  };
12171
- return (selectedFilter && (React__default.createElement("div", { ref: panelRef, className: "will-filter-bar-panels ".concat(mode || 'light'), style: (!tabs || tabs.length < 2) && !isMobile
12172
- ? { top: 66 }
12173
- : __assign$2({}, localStyles) }, renderContent())));
12174
+ return (selectedFilter && (React__default.createElement("div", { ref: panelRef, className: "will-filter-bar-panels ".concat(mode || 'light'), style: __assign$2(__assign$2({}, localStyles), ((!tabs || tabs.length < 2) && !isMobile ? { top: 66 } : {})) }, renderContent())));
12174
12175
  };
12175
12176
 
12176
12177
  var css_248z$4 = ".will-filter-bar-controls {\n display: flex;\n justify-content: space-between;\n padding: 10px;\n position: relative;\n z-index: 222;\n border-radius: 40px;\n background-color: var(--will-white);\n}\n\n@media (max-width: 960px) {\n .will-filter-bar-controls {\n flex-direction: column;\n padding: 20px;\n border-radius: 25px;\n overflow: hidden;\n }\n}\n";
@@ -12179,11 +12180,7 @@ styleInject(css_248z$4);
12179
12180
  var FilterControls = function () {
12180
12181
  var _a;
12181
12182
  var t = useTranslation('filterBar').t;
12182
- var _b = useFilterBar(), calendarRange = _b.calendarRange, selectedFilter = _b.selectedFilter, selectedPath = _b.selectedPath, ageCategoryCounts = _b.ageCategoryCounts, selectedLocations = _b.selectedLocations, mode = _b.mode, tabs = _b.tabs, ageCategories = _b.ageCategories, locations = _b.locations, innerLoading = _b.innerLoading, outerLoading = _b.outerLoading, handleSubmit = _b.handleSubmit, handleSelectedFilter = _b.handleSelectedFilter,
12183
- // Refs
12184
- previouslyFocusedButtonRef = _b.previouslyFocusedButtonRef, buttonRefs = _b.buttonRefs,
12185
- //
12186
- targetFilterBarRef = _b.targetFilterBarRef;
12183
+ var _b = useFilterBar(), calendarRange = _b.calendarRange, selectedFilter = _b.selectedFilter, selectedPath = _b.selectedPath, ageCategoryCounts = _b.ageCategoryCounts, selectedLocations = _b.selectedLocations, mode = _b.mode, tabs = _b.tabs, ageCategories = _b.ageCategories, locations = _b.locations, innerLoading = _b.innerLoading, outerLoading = _b.outerLoading, handleSubmit = _b.handleSubmit, handleSelectedFilter = _b.handleSelectedFilter, previouslyFocusedButtonRef = _b.previouslyFocusedButtonRef, buttonRefs = _b.buttonRefs, tabsRef = _b.tabsRef, filtersRef = _b.filtersRef;
12187
12184
  // Store previously focused button and restore focus when closing
12188
12185
  useEffect(function () {
12189
12186
  if (!selectedFilter && previouslyFocusedButtonRef.current) {
@@ -12205,7 +12202,12 @@ var FilterControls = function () {
12205
12202
  locationsPlaceholder: t('locations.placeholder'),
12206
12203
  locationsSelectedLabel: t('locations.selected'),
12207
12204
  });
12208
- return (React__default.createElement("div", { className: "will-filter-bar-controls ".concat(mode || 'light'), ref: (tabs === null || tabs === void 0 ? void 0 : tabs.length) === 1 ? targetFilterBarRef : null },
12205
+ return (React__default.createElement("div", { className: "will-filter-bar-controls ".concat(mode || 'light'), ref: function (el) {
12206
+ filtersRef.current = el;
12207
+ if ((tabs === null || tabs === void 0 ? void 0 : tabs.length) === 1) {
12208
+ tabsRef.current = el;
12209
+ }
12210
+ } },
12209
12211
  !!((_a = locations === null || locations === void 0 ? void 0 : locations.data) === null || _a === void 0 ? void 0 : _a.length) && (React__default.createElement(React__default.Fragment, null,
12210
12212
  React__default.createElement(SelectButton, { ref: function (el) { return (buttonRefs.current[FilterSections.LOCATIONS] = el); }, label: t('locations.label'), description: parsedLocations, onClick: function (e) {
12211
12213
  previouslyFocusedButtonRef.current = e.currentTarget;
@@ -12236,9 +12238,9 @@ var FilterTabs = function () {
12236
12238
  var t = useTranslation('filterBar').t;
12237
12239
  var _a = useFilterBar(), selectedPath = _a.selectedPath, mode = _a.mode, tabs = _a.tabs, handleSelectedFilter = _a.handleSelectedFilter, setSelectedPath = _a.setSelectedPath, handleResetFilters = _a.handleResetFilters,
12238
12240
  //
12239
- targetFilterBarRef = _a.targetFilterBarRef;
12241
+ tabsRef = _a.tabsRef;
12240
12242
  return (tabs &&
12241
- tabs.length > 1 && (React__default.createElement("div", { className: "will-filter-bar-tabs", ref: targetFilterBarRef }, tabs
12243
+ tabs.length > 1 && (React__default.createElement("div", { className: "will-filter-bar-tabs", ref: tabsRef }, tabs
12242
12244
  .sort(function (a, b) { return a.order - b.order; })
12243
12245
  .map(function (tab, idx) { return (React__default.createElement(TabButton, { key: "tab-".concat(idx), label: tab.label || t("tabs.".concat(tab.path.substring(1))), onClick: function () {
12244
12246
  setSelectedPath(tab.path);
@@ -12443,10 +12445,10 @@ function FilterCalendar(_a) {
12443
12445
  // Display component after fully loaded
12444
12446
  useAwaitRender();
12445
12447
  // Handle close filter section
12446
- var filtersRef = useCloseFilterSection({
12448
+ var filterSectionRef = useCloseFilterSection({
12447
12449
  handleSelectedFilter: setToggleCalendar,
12448
- }).filtersRef;
12449
- return (React__default.createElement("div", { className: "will-root", style: themePalette }, toggleCalendar && (React__default.createElement("div", { className: "will-calendar-wrapper", ref: filtersRef },
12450
+ }).filterSectionRef;
12451
+ return (React__default.createElement("div", { className: "will-root", style: themePalette }, toggleCalendar && (React__default.createElement("div", { className: "will-calendar-wrapper", ref: filterSectionRef },
12450
12452
  React__default.createElement("div", { className: "will-calendar-header" },
12451
12453
  React__default.createElement("h2", null, t('filterBar:calendar.title')),
12452
12454
  React__default.createElement(CloseButton, { handleClose: function () { return setToggleCalendar(false); } })),