willba-component-library 0.4.3 → 0.4.5

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/index.js CHANGED
@@ -3157,25 +3157,21 @@ var Pages;
3157
3157
  Pages["SALES"] = "/sales";
3158
3158
  })(Pages || (Pages = {}));
3159
3159
 
3160
- var useScrollInToView = function (_a) {
3161
- var selectedFilter = _a.selectedFilter;
3162
- var _b = __read(React.useState(true), 2), isMobile = _b[0], setIsMobile = _b[1];
3163
- var tabsRef = React.useRef(null);
3160
+ var MOBILE_BREAKPOINT = 960;
3161
+ var useIsMobile = function () {
3162
+ var _a = __read(React.useState(function () {
3163
+ return typeof window !== 'undefined' && window.innerWidth <= MOBILE_BREAKPOINT;
3164
+ }), 2), isMobile = _a[0], setIsMobile = _a[1];
3164
3165
  React.useEffect(function () {
3165
- if (typeof window !== 'undefined' && window.innerWidth > 960) {
3166
- setIsMobile(false);
3166
+ if (typeof window === 'undefined')
3167
3167
  return;
3168
- }
3169
- if (tabsRef.current && selectedFilter) {
3170
- window.scrollTo({
3171
- behavior: 'smooth',
3172
- top: tabsRef.current.getBoundingClientRect().top -
3173
- document.body.getBoundingClientRect().top -
3174
- 30,
3175
- });
3176
- }
3177
- }, [selectedFilter]);
3178
- return { isMobile: isMobile, tabsRef: tabsRef };
3168
+ var handleResize = function () {
3169
+ setIsMobile(window.innerWidth <= MOBILE_BREAKPOINT);
3170
+ };
3171
+ window.addEventListener('resize', handleResize);
3172
+ return function () { return window.removeEventListener('resize', handleResize); };
3173
+ }, []);
3174
+ return isMobile;
3179
3175
  };
3180
3176
 
3181
3177
  var useFilterState = function (_a) {
@@ -7009,43 +7005,53 @@ var useFilterActions = function (_a) {
7009
7005
  };
7010
7006
  };
7011
7007
 
7012
- var useFilterRefs = function (selectedFilter) {
7008
+ var useFilterRefs = function () {
7013
7009
  var buttonRefs = React.useRef({});
7014
7010
  var panelRef = React.useRef(null);
7015
7011
  var previouslyFocusedButtonRef = React.useRef(null);
7016
7012
  var filtersRef = React.useRef(null);
7017
- var _a = useScrollInToView({ selectedFilter: selectedFilter }), isMobile = _a.isMobile, tabsRef = _a.tabsRef;
7013
+ var isMobile = useIsMobile();
7018
7014
  return {
7019
7015
  previouslyFocusedButtonRef: previouslyFocusedButtonRef,
7020
7016
  isMobile: isMobile,
7021
- tabsRef: tabsRef,
7022
7017
  panelRef: panelRef,
7023
7018
  buttonRefs: buttonRefs,
7024
7019
  filtersRef: filtersRef,
7025
7020
  };
7026
7021
  };
7027
7022
 
7023
+ var DESKTOP_PANEL_GAP = 10;
7028
7024
  var usePanelPosition = function (_a) {
7029
- var selectedFilter = _a.selectedFilter, panelRef = _a.panelRef, filtersRef = _a.filtersRef, buttonRefs = _a.buttonRefs, isMobile = _a.isMobile, tabs = _a.tabs;
7025
+ var selectedFilter = _a.selectedFilter, panelRef = _a.panelRef, filtersRef = _a.filtersRef, buttonRefs = _a.buttonRefs, isMobile = _a.isMobile;
7030
7026
  var _b = __read(React.useState(), 2), left = _b[0], setLeft = _b[1];
7031
- var hasMultipleTabs = tabs && tabs.length > 1;
7032
- var top = isMobile ? (hasMultipleTabs ? 60 : 0) : hasMultipleTabs ? 125 : 66;
7027
+ var _c = __read(React.useState(), 2), top = _c[0], setTop = _c[1];
7033
7028
  React.useLayoutEffect(function () {
7034
- if (!selectedFilter || typeof selectedFilter !== 'string' || isMobile) {
7029
+ if (!selectedFilter || typeof selectedFilter !== 'string') {
7035
7030
  setLeft(undefined);
7031
+ setTop(undefined);
7036
7032
  return;
7037
7033
  }
7034
+ var filters = filtersRef.current;
7035
+ if (!filters)
7036
+ return;
7037
+ if (isMobile) {
7038
+ // Panel overlays the filter controls (which fade to opacity 0.1
7039
+ // via the .disabled rule), so it starts at the top of the controls.
7040
+ setTop(filters.offsetTop);
7041
+ setLeft(undefined);
7042
+ return;
7043
+ }
7044
+ // Desktop: panel sits below the controls with a small breathing room.
7045
+ setTop(filters.offsetTop + filters.offsetHeight + DESKTOP_PANEL_GAP);
7038
7046
  var panel = panelRef.current;
7039
- var container = filtersRef.current;
7040
7047
  var button = buttonRefs.current[selectedFilter];
7041
- if (!panel || !container || !button)
7048
+ if (!panel || !button)
7042
7049
  return;
7043
7050
  var panelRect = panel.getBoundingClientRect();
7044
- var containerRect = container.getBoundingClientRect();
7051
+ var containerRect = filters.getBoundingClientRect();
7045
7052
  var buttonRect = button.getBoundingClientRect();
7046
7053
  var buttonLeft = buttonRect.left - containerRect.left - 10;
7047
- var newLeft = Math.max(0, Math.min(buttonLeft, containerRect.width - panelRect.width));
7048
- setLeft(newLeft);
7054
+ setLeft(Math.max(0, Math.min(buttonLeft, containerRect.width - panelRect.width)));
7049
7055
  }, [selectedFilter, isMobile]);
7050
7056
  return { top: top, left: left };
7051
7057
  };
@@ -7069,7 +7075,7 @@ var FilterBarProvider = function (_a) {
7069
7075
  onSubmit: onSubmit,
7070
7076
  setInnerLoading: setInnerLoading,
7071
7077
  });
7072
- var filterRefs = useFilterRefs(selectedFilter);
7078
+ var filterRefs = useFilterRefs();
7073
7079
  var contextValue = React.useMemo(function () { return (__assign$2(__assign$2(__assign$2({ selectedFilter: selectedFilter, ageCategoryCounts: ageCategoryCounts, categories: categories, calendarRange: calendarRange, selectedPath: selectedPath, innerLoading: innerLoading, selectedLocations: selectedLocations, setSelectedLocations: setSelectedLocations, setCalendarRange: setCalendarRange, setSelectedFilter: setSelectedFilter, setAgeCategoryCounts: setAgeCategoryCounts, setCategories: setCategories, setSelectedPath: setSelectedPath }, filterActions), { language: language, ageCategories: ageCategories, redirectUrl: redirectUrl, palette: palette, onSubmit: onSubmit, fullWidth: fullWidth, disableCalendarDates: disableCalendarDates, mode: mode, tabs: tabs, outerLoading: outerLoading, locations: locations }), filterRefs)); }, [
7074
7080
  selectedFilter,
7075
7081
  ageCategoryCounts,
@@ -7090,7 +7096,6 @@ var FilterBarProvider = function (_a) {
7090
7096
  outerLoading,
7091
7097
  locations,
7092
7098
  filterRefs.isMobile,
7093
- filterRefs.tabsRef,
7094
7099
  filterRefs.filtersRef,
7095
7100
  ]);
7096
7101
  return (React.createElement(FilterBarContext.Provider, { value: contextValue }, children));
@@ -12363,7 +12368,7 @@ var css_248z$5 = ".will-filter-bar-panels {\n background-color: var(--will-whit
12363
12368
  styleInject(css_248z$5);
12364
12369
 
12365
12370
  var FilterPanels = function () {
12366
- 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;
12371
+ var _a = useFilterBar(), categories = _a.categories, calendarRange = _a.calendarRange, selectedFilter = _a.selectedFilter, selectedPath = _a.selectedPath, ageCategoryCounts = _a.ageCategoryCounts, selectedLocations = _a.selectedLocations, mode = _a.mode; _a.tabs; var 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;
12367
12372
  // Handle close filter section
12368
12373
  var filterSectionRef = useCloseFilterSection({ handleSelectedFilter: handleSelectedFilter }).filterSectionRef;
12369
12374
  var _b = usePanelPosition({
@@ -12372,7 +12377,6 @@ var FilterPanels = function () {
12372
12377
  filtersRef: filtersRef,
12373
12378
  buttonRefs: buttonRefs,
12374
12379
  isMobile: isMobile,
12375
- tabs: tabs,
12376
12380
  }), left = _b.left, top = _b.top;
12377
12381
  var renderContent = function () {
12378
12382
  switch (selectedFilter) {
@@ -12397,7 +12401,7 @@ styleInject(css_248z$4);
12397
12401
  var FilterControls = function () {
12398
12402
  var _a;
12399
12403
  var t = useTranslation('filterBar').t;
12400
- 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;
12404
+ var _b = useFilterBar(), calendarRange = _b.calendarRange, selectedFilter = _b.selectedFilter, selectedPath = _b.selectedPath, ageCategoryCounts = _b.ageCategoryCounts, selectedLocations = _b.selectedLocations, mode = _b.mode, ageCategories = _b.ageCategories, locations = _b.locations, innerLoading = _b.innerLoading, outerLoading = _b.outerLoading, handleSubmit = _b.handleSubmit, handleSelectedFilter = _b.handleSelectedFilter, previouslyFocusedButtonRef = _b.previouslyFocusedButtonRef, buttonRefs = _b.buttonRefs, filtersRef = _b.filtersRef;
12401
12405
  // Store previously focused button and restore focus when closing
12402
12406
  React.useEffect(function () {
12403
12407
  if (!selectedFilter && previouslyFocusedButtonRef.current) {
@@ -12421,9 +12425,6 @@ var FilterControls = function () {
12421
12425
  });
12422
12426
  return (React.createElement("div", { className: "will-filter-bar-controls ".concat(mode || 'light', " ").concat(selectedFilter ? 'disabled' : ''), ref: function (el) {
12423
12427
  filtersRef.current = el;
12424
- if ((tabs === null || tabs === void 0 ? void 0 : tabs.length) === 1) {
12425
- tabsRef.current = el;
12426
- }
12427
12428
  } },
12428
12429
  !!((_a = locations === null || locations === void 0 ? void 0 : locations.data) === null || _a === void 0 ? void 0 : _a.length) && locations.data.length > 1 && (React.createElement(React.Fragment, null,
12429
12430
  React.createElement(SelectButton, { ref: function (el) { return (buttonRefs.current[FilterSections.LOCATIONS] = el); }, label: t('locations.label'), description: parsedLocations, onClick: function (e) {
@@ -12453,7 +12454,7 @@ styleInject(css_248z$3);
12453
12454
 
12454
12455
  var FilterTabs = function () {
12455
12456
  var t = useTranslation('filterBar').t;
12456
- var _a = useFilterBar(), selectedPath = _a.selectedPath, mode = _a.mode, tabs = _a.tabs, tabsRef = _a.tabsRef, handleSelectedFilter = _a.handleSelectedFilter, setSelectedPath = _a.setSelectedPath, handleResetFilters = _a.handleResetFilters;
12457
+ var _a = useFilterBar(), selectedPath = _a.selectedPath, mode = _a.mode, tabs = _a.tabs, handleSelectedFilter = _a.handleSelectedFilter, setSelectedPath = _a.setSelectedPath, handleResetFilters = _a.handleResetFilters;
12457
12458
  var sortedTabs = React.useMemo(function () { return __spreadArray$1([], __read((tabs !== null && tabs !== void 0 ? tabs : [])), false).sort(function (a, b) { return a.order - b.order; }); }, [tabs]);
12458
12459
  var handleTabClick = function (path) {
12459
12460
  setSelectedPath(path);
@@ -12462,7 +12463,7 @@ var FilterTabs = function () {
12462
12463
  };
12463
12464
  if (sortedTabs.length <= 1)
12464
12465
  return null;
12465
- return (React.createElement("div", { className: "will-filter-bar-tabs", ref: tabsRef }, sortedTabs.map(function (tab) { return (React.createElement(TabButton, { key: tab.path, label: tab.label || t("tabs.".concat(tab.path.slice(1))), onClick: function () { return handleTabClick(tab.path); }, active: selectedPath === tab.path, mode: mode })); })));
12466
+ return (React.createElement("div", { className: "will-filter-bar-tabs" }, sortedTabs.map(function (tab) { return (React.createElement(TabButton, { key: tab.path, label: tab.label || t("tabs.".concat(tab.path.slice(1))), onClick: function () { return handleTabClick(tab.path); }, active: selectedPath === tab.path, mode: mode })); })));
12466
12467
  };
12467
12468
 
12468
12469
  var css_248z$2 = "@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap');\n\n.will-root * {\n font-family: 'Montserrat', sans-serif;\n}\n\n.will-root {\n \n box-sizing: border-box;\n font-size: 14px;\n \n color: #1E1E1E;\n \n /* Palette */\n --will-primary: #374269;\n --will-secondary: #374269;\n --will-grey: #ABA7AF;\n --will-light-grey: #C8C8C8;\n --will-white: #fff;\n --will-white-transparent: #ffffffcf;\n --will-black: #000;\n --will-onahau: #CDEEFF;\n --will-text: #5A5959;\n --will-charcoal-blue: #384265;\n --will-error: #d32f2f;\n\n /* Transparent */\n --will-transparent-black: rgba(0, 0, 0, 0.5);\n --will-transparent-white: rgba(255, 255, 255, 0.30);\n --will-transparent-lavender: rgba(171, 167, 175, 0.30);\n\n /* Color mix */\n --will-primary-lighter: color-mix(in srgb, var(--will-primary), white 50%);\n --will-primary-lightest: color-mix(in srgb, var(--will-primary), white 80%);\n\n\n /* Shadows */\n --will-box-shadow-dark: 0px 2px 12px 2px #a1a1a180;\n --will-box-shadow-light: 0px 2px 12px 2px #bcb9b980;\n\n /* Breakpoints */\n --will-lg: 1140px;\n --will-md: 960px;\n --will-sm: 600px;\n --will-xl: 1280px;\n --will-xs: 0px;\n}\n\n/* Typography */\n\n.will-root h1, h2, h3, h4, h5, h6 {\n font-weight: 700;\n} \n\n.will-root p, h1, h2, h3, h4, h5, h6, span {\n margin: 0;\n padding: 0;\n}\n\n\n/* Integration fixes */\n\n.will-root p {\n margin: 0 !important;\n}\n\n.will-root button {\n line-height: normal !important;\n}\n";