willba-component-library 0.3.18 → 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.18/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;
@@ -6859,6 +6861,7 @@ var FilterBarProvider = function (_a) {
6859
6861
  selectedLocations: selectedLocations,
6860
6862
  selectedPath: selectedPath,
6861
6863
  redirectUrl: redirectUrl,
6864
+ calendarRange: calendarRange,
6862
6865
  setSelectedPath: setSelectedPath,
6863
6866
  setAgeCategoryCounts: setAgeCategoryCounts,
6864
6867
  setSelectedFilter: setSelectedFilter,
@@ -6887,7 +6890,8 @@ var FilterBarProvider = function (_a) {
6887
6890
  outerLoading,
6888
6891
  locations,
6889
6892
  filterUi.isMobile,
6890
- filterUi.targetFilterBarRef,
6893
+ filterUi.tabsRef,
6894
+ filterUi.filtersRef,
6891
6895
  ]);
6892
6896
  return (React__default.createElement(FilterBarContext.Provider, { value: contextValue }, children));
6893
6897
  };
@@ -12143,33 +12147,31 @@ var css_248z$5 = ".will-filter-bar-panels {\n background-color: var(--will-whit
12143
12147
  styleInject(css_248z$5);
12144
12148
 
12145
12149
  var FilterPanels = function () {
12146
- 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;
12147
12151
  // Handle close filter section
12148
- var filtersRef = useCloseFilterSection({ handleSelectedFilter: handleSelectedFilter }).filtersRef;
12152
+ var filterSectionRef = useCloseFilterSection({ handleSelectedFilter: handleSelectedFilter }).filterSectionRef;
12149
12153
  var localStyles = usePanelPosition({
12150
12154
  selectedFilter: selectedFilter,
12151
12155
  panelRef: panelRef,
12152
- targetFilterBarRef: targetFilterBarRef,
12156
+ filtersRef: filtersRef,
12153
12157
  buttonRefs: buttonRefs,
12154
12158
  isMobile: isMobile,
12155
12159
  }).localStyles;
12156
12160
  var renderContent = function () {
12157
12161
  switch (selectedFilter) {
12158
12162
  case FilterSections.CALENDAR:
12159
- 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 }));
12160
12164
  case FilterSections.GUESTS:
12161
- 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); } }));
12162
12166
  case FilterSections.CATEGORIES:
12163
12167
  return (React__default.createElement(Categories, { categories: categories, setCategories: setCategories }));
12164
12168
  case FilterSections.LOCATIONS:
12165
- 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); } }));
12166
12170
  default:
12167
12171
  return null;
12168
12172
  }
12169
12173
  };
12170
- return (selectedFilter && (React__default.createElement("div", { ref: panelRef, className: "will-filter-bar-panels ".concat(mode || 'light'), style: (!tabs || tabs.length < 2) && !isMobile
12171
- ? { top: 66 }
12172
- : __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())));
12173
12175
  };
12174
12176
 
12175
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";
@@ -12178,11 +12180,7 @@ styleInject(css_248z$4);
12178
12180
  var FilterControls = function () {
12179
12181
  var _a;
12180
12182
  var t = useTranslation('filterBar').t;
12181
- 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,
12182
- // Refs
12183
- previouslyFocusedButtonRef = _b.previouslyFocusedButtonRef, buttonRefs = _b.buttonRefs,
12184
- //
12185
- 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;
12186
12184
  // Store previously focused button and restore focus when closing
12187
12185
  useEffect(function () {
12188
12186
  if (!selectedFilter && previouslyFocusedButtonRef.current) {
@@ -12204,7 +12202,12 @@ var FilterControls = function () {
12204
12202
  locationsPlaceholder: t('locations.placeholder'),
12205
12203
  locationsSelectedLabel: t('locations.selected'),
12206
12204
  });
12207
- 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
+ } },
12208
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,
12209
12212
  React__default.createElement(SelectButton, { ref: function (el) { return (buttonRefs.current[FilterSections.LOCATIONS] = el); }, label: t('locations.label'), description: parsedLocations, onClick: function (e) {
12210
12213
  previouslyFocusedButtonRef.current = e.currentTarget;
@@ -12235,9 +12238,9 @@ var FilterTabs = function () {
12235
12238
  var t = useTranslation('filterBar').t;
12236
12239
  var _a = useFilterBar(), selectedPath = _a.selectedPath, mode = _a.mode, tabs = _a.tabs, handleSelectedFilter = _a.handleSelectedFilter, setSelectedPath = _a.setSelectedPath, handleResetFilters = _a.handleResetFilters,
12237
12240
  //
12238
- targetFilterBarRef = _a.targetFilterBarRef;
12241
+ tabsRef = _a.tabsRef;
12239
12242
  return (tabs &&
12240
- 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
12241
12244
  .sort(function (a, b) { return a.order - b.order; })
12242
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 () {
12243
12246
  setSelectedPath(tab.path);
@@ -12442,10 +12445,10 @@ function FilterCalendar(_a) {
12442
12445
  // Display component after fully loaded
12443
12446
  useAwaitRender();
12444
12447
  // Handle close filter section
12445
- var filtersRef = useCloseFilterSection({
12448
+ var filterSectionRef = useCloseFilterSection({
12446
12449
  handleSelectedFilter: setToggleCalendar,
12447
- }).filtersRef;
12448
- 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 },
12449
12452
  React__default.createElement("div", { className: "will-calendar-header" },
12450
12453
  React__default.createElement("h2", null, t('filterBar:calendar.title')),
12451
12454
  React__default.createElement(CloseButton, { handleClose: function () { return setToggleCalendar(false); } })),