willba-component-library 0.1.47 → 0.1.48

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.
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { Palette } from '../../themes/useTheme';
3
3
  import '../../themes/Default.css';
4
- import { AgeCategoryType } from './FilterBarTypes';
4
+ import { AgeCategoryType, Filters } from './FilterBarTypes';
5
5
  import './FilterBar.css';
6
6
  export type FilterBarProps = {
7
7
  vendor?: string;
@@ -10,5 +10,6 @@ export type FilterBarProps = {
10
10
  redirectUrl?: string;
11
11
  palette?: Palette;
12
12
  currentViewApply?: string;
13
+ onSubmit?: (val: Filters) => void;
13
14
  };
14
- export default function FilterBar({ language, ageCategories, redirectUrl, palette, currentViewApply, }: FilterBarProps): React.JSX.Element;
15
+ export default function FilterBar({ language, ageCategories, redirectUrl, palette, currentViewApply, onSubmit, }: FilterBarProps): React.JSX.Element;
@@ -20,3 +20,9 @@ export declare enum FilterSections {
20
20
  GUESTS = "guests",
21
21
  CATEGORIES = "categories"
22
22
  }
23
+ export type Filters = {
24
+ [key: string]: string | number;
25
+ };
26
+ export declare enum ViewApply {
27
+ ROOMS = "roomFilters"
28
+ }
@@ -1,12 +1,13 @@
1
1
  /// <reference types="react" />
2
2
  import { DateRange } from 'react-day-picker';
3
- import { AgeCategoryCount, AgeCategoryType } from '../FilterBarTypes';
3
+ import { AgeCategoryCount, AgeCategoryType, Filters } from '../FilterBarTypes';
4
4
  type Props = {
5
5
  redirectUrl?: string;
6
6
  currentViewApply?: string;
7
7
  ageCategories?: AgeCategoryType[];
8
+ onSubmit?: (val: Filters) => void;
8
9
  };
9
- export declare const useFilterBar: ({ redirectUrl, currentViewApply, ageCategories, }: Props) => {
10
+ export declare const useFilterBar: ({ redirectUrl, currentViewApply, ageCategories, onSubmit, }: Props) => {
10
11
  selectedFilter: string | boolean;
11
12
  ageCategoryCounts: AgeCategoryCount;
12
13
  categories: number;
@@ -17,7 +18,7 @@ export declare const useFilterBar: ({ redirectUrl, currentViewApply, ageCategori
17
18
  setAgeCategoryCounts: import("react").Dispatch<import("react").SetStateAction<AgeCategoryCount>>;
18
19
  setCategories: import("react").Dispatch<import("react").SetStateAction<number>>;
19
20
  handleSelectedFilter: (id: string | boolean) => void;
20
- handleSubmit: () => string;
21
+ handleSubmit: () => string | void;
21
22
  updateGuestsCount: (id: string, newCount: number) => void;
22
23
  handleResetFilters: () => void;
23
24
  setSelectedPath: import("react").Dispatch<import("react").SetStateAction<string>>;
@@ -1 +1,2 @@
1
- export { default } from "./FilterBar";
1
+ export { default } from './FilterBar';
2
+ export * from './FilterBarTypes';
package/lib/index.d.ts CHANGED
@@ -38,6 +38,9 @@ type AgeCategoryType = {
38
38
  minVal: number;
39
39
  sortOrder: number;
40
40
  };
41
+ type Filters = {
42
+ [key: string]: string | number;
43
+ };
41
44
 
42
45
  type FilterBarProps = {
43
46
  vendor?: string;
@@ -46,7 +49,8 @@ type FilterBarProps = {
46
49
  redirectUrl?: string;
47
50
  palette?: Palette;
48
51
  currentViewApply?: string;
52
+ onSubmit?: (val: Filters) => void;
49
53
  };
50
- declare function FilterBar({ language, ageCategories, redirectUrl, palette, currentViewApply, }: FilterBarProps): React.JSX.Element;
54
+ declare function FilterBar({ language, ageCategories, redirectUrl, palette, currentViewApply, onSubmit, }: FilterBarProps): React.JSX.Element;
51
55
 
52
56
  export { Button, FilterBar };
package/lib/index.esm.js CHANGED
@@ -3906,9 +3906,13 @@ var FilterSections;
3906
3906
  FilterSections["GUESTS"] = "guests";
3907
3907
  FilterSections["CATEGORIES"] = "categories";
3908
3908
  })(FilterSections || (FilterSections = {}));
3909
+ var ViewApply;
3910
+ (function (ViewApply) {
3911
+ ViewApply["ROOMS"] = "roomFilters";
3912
+ })(ViewApply || (ViewApply = {}));
3909
3913
 
3910
3914
  var useFilterBar = function (_a) {
3911
- var redirectUrl = _a.redirectUrl, currentViewApply = _a.currentViewApply, ageCategories = _a.ageCategories;
3915
+ var redirectUrl = _a.redirectUrl, currentViewApply = _a.currentViewApply, ageCategories = _a.ageCategories, onSubmit = _a.onSubmit;
3912
3916
  var _b = __read(useState('/events'), 2), selectedPath = _b[0], setSelectedPath = _b[1];
3913
3917
  var _c = __read(useState(false), 2), selectedFilter = _c[0], setSelectedFilter = _c[1];
3914
3918
  var _d = __read(useState(), 2), calendarRange = _d[0], setCalendarRange = _d[1];
@@ -4009,6 +4013,14 @@ var useFilterBar = function (_a) {
4009
4013
  var baseUrl = window.location.origin + window.location.pathname;
4010
4014
  var updatedUrl = "".concat(baseUrl, "?").concat(updatedParams.toString());
4011
4015
  handleSelectedFilter(false);
4016
+ if (onSubmit) {
4017
+ var updatedParamsObject_1 = {};
4018
+ updatedParams.forEach(function (value, key) {
4019
+ updatedParamsObject_1[key] = value;
4020
+ });
4021
+ console.log('sdasdasdsad', updatedParamsObject_1);
4022
+ return onSubmit(updatedParamsObject_1);
4023
+ }
4012
4024
  return (window.location.href = updatedUrl);
4013
4025
  }
4014
4026
  else {
@@ -4029,7 +4041,9 @@ var useFilterBar = function (_a) {
4029
4041
  finally { if (e_3) throw e_3.error; }
4030
4042
  }
4031
4043
  handleSelectedFilter(false);
4032
- return (window.location.href = "".concat(redirectUrl, "/").concat(selectedPath).concat(querySearchParams ? "?".concat(querySearchParams.toString()) : ''));
4044
+ return onSubmit
4045
+ ? onSubmit(newParams)
4046
+ : (window.location.href = "".concat(redirectUrl, "/").concat(selectedPath).concat(querySearchParams ? "?".concat(querySearchParams.toString()) : ''));
4033
4047
  }
4034
4048
  };
4035
4049
  var handleResetFilters = function () {
@@ -10673,16 +10687,21 @@ var css_248z = ".will-root {\n z-index: 999;\n width: 100%;\n max-height: 100
10673
10687
  styleInject(css_248z);
10674
10688
 
10675
10689
  function FilterBar(_a) {
10676
- 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;
10690
+ 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;
10677
10691
  var themePalette = useTheme({ palette: palette });
10678
10692
  // Translations
10679
10693
  useUpdateTranslations({ language: language });
10680
10694
  var t = useTranslation('filterBar').t;
10681
10695
  // Filters
10682
- var _d = useFilterBar({ redirectUrl: redirectUrl, currentViewApply: currentViewApply, ageCategories: ageCategories }), 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;
10696
+ var _d = useFilterBar({
10697
+ redirectUrl: redirectUrl,
10698
+ currentViewApply: currentViewApply,
10699
+ ageCategories: ageCategories,
10700
+ onSubmit: onSubmit,
10701
+ }), 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;
10683
10702
  // Default selected tab when tabs are hidden
10684
10703
  useEffect(function () {
10685
- if (currentViewApply === 'roomFilters') {
10704
+ if (currentViewApply === ViewApply.ROOMS) {
10686
10705
  setSelectedPath('/rooms');
10687
10706
  }
10688
10707
  }, []);