willba-component-library 0.1.46 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "willba-component-library",
3
- "version": "0.1.46",
3
+ "version": "0.1.48",
4
4
  "description": "A stroybook 6 with TypeScript demo",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.esm.js",
@@ -2,6 +2,7 @@ import React from 'react'
2
2
  import type { Meta, StoryObj } from '@storybook/react'
3
3
 
4
4
  import FilterBar from './FilterBar'
5
+ import { Filters } from './FilterBarTypes'
5
6
 
6
7
  const meta: Meta<typeof FilterBar> = {
7
8
  title: 'Components/FilterBar',
@@ -44,7 +45,7 @@ export const Primary: Story = {
44
45
  },
45
46
  render: (args) => (
46
47
  <div style={{ background: 'grey', padding: '30px', height: '100vh' }}>
47
- <FilterBar {...args} />
48
+ <FilterBar {...args} onSubmit={(val: Filters) => console.log(val)} />
48
49
  </div>
49
50
  ),
50
51
  }
@@ -1,12 +1,16 @@
1
1
  import React, { useEffect } from 'react'
2
2
  import { useTranslation } from 'react-i18next'
3
- import { format } from 'date-fns'
4
3
 
5
4
  import useTheme, { Palette } from '../../themes/useTheme'
6
5
  import '../../themes/Default.css'
7
6
 
8
7
  import { parseDates, parseGuests } from './utils'
9
- import { AgeCategoryType } from './FilterBarTypes'
8
+ import {
9
+ AgeCategoryType,
10
+ FilterSections,
11
+ Filters,
12
+ ViewApply,
13
+ } from './FilterBarTypes'
10
14
  import {
11
15
  useCloseFilterSection,
12
16
  useFilterBar,
@@ -33,6 +37,7 @@ export type FilterBarProps = {
33
37
  redirectUrl?: string
34
38
  palette?: Palette
35
39
  currentViewApply?: string
40
+ onSubmit?: (val: Filters) => void
36
41
  }
37
42
 
38
43
  export default function FilterBar({
@@ -41,6 +46,7 @@ export default function FilterBar({
41
46
  redirectUrl = REDIRECT_URL_FALLBACK,
42
47
  palette,
43
48
  currentViewApply,
49
+ onSubmit,
44
50
  }: FilterBarProps) {
45
51
  const themePalette = useTheme({ palette })
46
52
 
@@ -61,11 +67,16 @@ export default function FilterBar({
61
67
  handleSubmit,
62
68
  updateGuestsCount,
63
69
  setSelectedPath,
64
- } = useFilterBar({ redirectUrl, currentViewApply, ageCategories })
65
-
66
- // Default selected tab
70
+ } = useFilterBar({
71
+ redirectUrl,
72
+ currentViewApply,
73
+ ageCategories,
74
+ onSubmit,
75
+ })
76
+
77
+ // Default selected tab when tabs are hidden
67
78
  useEffect(() => {
68
- if (currentViewApply === 'roomFilters') {
79
+ if (currentViewApply === ViewApply.ROOMS) {
69
80
  setSelectedPath('/rooms')
70
81
  }
71
82
  }, [])
@@ -76,6 +87,7 @@ export default function FilterBar({
76
87
  // Handle close filter section
77
88
  const { filtersRef } = useCloseFilterSection({ handleSelectedFilter })
78
89
 
90
+ // Parsed data for filter section description
79
91
  const parsedDates = parseDates({ calendarRange })
80
92
  const parsedGuests = parseGuests({ ageCategoryCounts, ageCategories })
81
93
 
@@ -112,11 +124,8 @@ export default function FilterBar({
112
124
  ? t('calendar.roomsLabelPlaceholder')
113
125
  : t('calendar.eventsLabelPlaceholder')
114
126
  }
115
- onClick={() => handleSelectedFilter(1)}
116
- style={fontWeightBold(selectedFilter === 1)}
117
- date={
118
- calendarRange?.to ? format(calendarRange.to, 'dd.MM.yyyy') : null
119
- }
127
+ onClick={() => handleSelectedFilter(FilterSections.CALENDAR)}
128
+ active={selectedFilter === FilterSections.CALENDAR}
120
129
  />
121
130
 
122
131
  {selectedPath === '/rooms' && (
@@ -128,8 +137,8 @@ export default function FilterBar({
128
137
  description={
129
138
  parsedGuests ? parsedGuests : t('guests.labelPlaceholder')
130
139
  }
131
- onClick={() => handleSelectedFilter(2)}
132
- style={fontWeightBold(selectedFilter === 2)}
140
+ onClick={() => handleSelectedFilter(FilterSections.GUESTS)}
141
+ active={selectedFilter === FilterSections.GUESTS}
133
142
  />
134
143
  </>
135
144
  )}
@@ -144,14 +153,14 @@ export default function FilterBar({
144
153
  >
145
154
  <CloseButton handleClose={() => handleSelectedFilter(false)} />
146
155
 
147
- {selectedFilter === 1 && (
156
+ {selectedFilter === FilterSections.CALENDAR && (
148
157
  <Calendar
149
158
  calendarRange={calendarRange}
150
159
  setCalendarRange={setCalendarRange}
151
160
  ref={filtersRef}
152
161
  />
153
162
  )}
154
- {selectedFilter === 2 && (
163
+ {selectedFilter === FilterSections.GUESTS && (
155
164
  <Guests
156
165
  updateGuestsCount={updateGuestsCount}
157
166
  ageCategories={ageCategories}
@@ -159,7 +168,7 @@ export default function FilterBar({
159
168
  ref={filtersRef}
160
169
  />
161
170
  )}
162
- {selectedFilter === 3 && (
171
+ {selectedFilter === FilterSections.CATEGORIES && (
163
172
  <Categories categories={categories} setCategories={setCategories} />
164
173
  )}
165
174
  </div>
@@ -170,10 +179,6 @@ export default function FilterBar({
170
179
 
171
180
  ////////////
172
181
 
173
- const fontWeightBold = (input: boolean) => {
174
- return { fontWeight: input ? 'bold' : 'initial' }
175
- }
176
-
177
182
  const AGE_CATEGORIES_FALLBACK = [
178
183
  {
179
184
  id: '1',
@@ -1,15 +1,15 @@
1
- export interface AgeCategoryCount {
1
+ export type AgeCategoryCount = {
2
2
  [categoryId: string]: number
3
3
  }
4
4
 
5
- export interface AgeCategoryType {
5
+ export type AgeCategoryType = {
6
6
  id: string
7
7
  name: string
8
8
  minVal: number
9
9
  sortOrder: number
10
10
  }
11
11
 
12
- export interface GuestsCountPropsType {
12
+ export type GuestsCountPropsType = {
13
13
  label: string
14
14
  id: number
15
15
  updateGuestsCount: (arg1: string, arg2: number) => void
@@ -17,3 +17,15 @@ export interface GuestsCountPropsType {
17
17
  minVal: number
18
18
  sortOrder: number
19
19
  }
20
+
21
+ export enum FilterSections {
22
+ CALENDAR = 'calendar',
23
+ GUESTS = 'guests',
24
+ CATEGORIES = 'categories',
25
+ }
26
+
27
+ export type Filters = { [key: string]: string | number }
28
+
29
+ export enum ViewApply {
30
+ ROOMS = 'roomFilters',
31
+ }
@@ -10,8 +10,6 @@
10
10
  text-align: initial;
11
11
  }
12
12
 
13
-
14
-
15
13
  .will-filter-bar-select-button .select-button-wrapper {
16
14
  display: flex;
17
15
  align-items: center;
@@ -24,16 +22,24 @@
24
22
  display: grid
25
23
  }
26
24
 
25
+ .will-filter-bar-select-button .select-button-label {
26
+ font-weight: 500;
27
+ }
28
+
27
29
  .will-filter-bar-select-button .select-button-description {
28
30
  font-weight: 400;
29
- opacity: 0.4;
30
-
31
-
31
+ opacity: 0.8;
32
+
32
33
  white-space: nowrap;
33
34
  overflow: hidden;
34
35
  text-overflow: ellipsis;
35
36
  }
36
37
 
38
+ .will-filter-bar-select-button .select-button-label.active,
39
+ .will-filter-bar-select-button .select-button-description.active {
40
+ font-weight: 600;
41
+ }
42
+
37
43
  @media (max-width: 960px) {
38
44
  .will-filter-bar-select-button {
39
45
  padding: 15px 0;
@@ -5,21 +5,27 @@ import './SelectButton.css'
5
5
  type Props = {
6
6
  label: string
7
7
  onClick: () => void
8
- style: Object
9
8
  description: string
9
+ active?: boolean
10
10
  }
11
11
 
12
- export const SelectButton = ({ label, onClick, style, description }: any) => {
12
+ export const SelectButton = ({
13
+ active,
14
+ label,
15
+ onClick,
16
+
17
+ description,
18
+ }: Props) => {
13
19
  return (
14
- <button
15
- className="will-filter-bar-select-button"
16
- onClick={onClick}
17
- style={style}
18
- >
20
+ <button className="will-filter-bar-select-button" onClick={onClick}>
19
21
  <span className="select-button-wrapper">
20
22
  <div>
21
- <p className="select-button-label">{label}</p>
22
- <p className="select-button-description">{description}</p>
23
+ <p className={`select-button-label ${active ? 'active' : ''}`}>
24
+ {label}
25
+ </p>
26
+ <p className={`select-button-description ${active ? 'active' : ''}`}>
27
+ {description}
28
+ </p>
23
29
  </div>
24
30
  </span>
25
31
  </button>
@@ -2,22 +2,24 @@ import { useEffect, useState } from 'react'
2
2
  import { DateRange } from 'react-day-picker'
3
3
  import { format } from 'date-fns'
4
4
 
5
- import { AgeCategoryCount, AgeCategoryType } from '../FilterBarTypes'
5
+ import { AgeCategoryCount, AgeCategoryType, Filters } from '../FilterBarTypes'
6
6
 
7
7
  type Props = {
8
8
  redirectUrl?: string
9
9
  currentViewApply?: string
10
10
  ageCategories?: AgeCategoryType[]
11
+ onSubmit?: (val: Filters) => void
11
12
  }
12
13
 
13
14
  export const useFilterBar = ({
14
15
  redirectUrl,
15
16
  currentViewApply,
16
17
  ageCategories,
18
+ onSubmit,
17
19
  }: Props) => {
18
20
  const [selectedPath, setSelectedPath] = useState('/events')
19
21
 
20
- const [selectedFilter, setSelectedFilter] = useState<number | boolean>(false)
22
+ const [selectedFilter, setSelectedFilter] = useState<string | boolean>(false)
21
23
  const [calendarRange, setCalendarRange] = useState<DateRange | undefined>()
22
24
 
23
25
  const [categories, setCategories] = useState<number>(0)
@@ -80,7 +82,7 @@ export const useFilterBar = ({
80
82
  }))
81
83
  }
82
84
 
83
- const handleSelectedFilter = (id: number | boolean) => {
85
+ const handleSelectedFilter = (id: string | boolean) => {
84
86
  setSelectedFilter(id)
85
87
  }
86
88
 
@@ -118,6 +120,19 @@ export const useFilterBar = ({
118
120
  const updatedUrl = `${baseUrl}?${updatedParams.toString()}`
119
121
 
120
122
  handleSelectedFilter(false)
123
+
124
+ if (onSubmit) {
125
+ const updatedParamsObject: { [key: string]: string | number } = {}
126
+
127
+ updatedParams.forEach((value, key) => {
128
+ updatedParamsObject[key] = value
129
+ })
130
+
131
+ console.log('sdasdasdsad', updatedParamsObject)
132
+
133
+ return onSubmit(updatedParamsObject)
134
+ }
135
+
121
136
  return (window.location.href = updatedUrl)
122
137
  } else {
123
138
  const querySearchParams = new URLSearchParams()
@@ -129,9 +144,12 @@ export const useFilterBar = ({
129
144
  }
130
145
 
131
146
  handleSelectedFilter(false)
132
- return (window.location.href = `${redirectUrl}/${selectedPath}${
133
- querySearchParams ? `?${querySearchParams.toString()}` : ''
134
- }`)
147
+
148
+ return onSubmit
149
+ ? onSubmit(newParams)
150
+ : (window.location.href = `${redirectUrl}/${selectedPath}${
151
+ querySearchParams ? `?${querySearchParams.toString()}` : ''
152
+ }`)
135
153
  }
136
154
  }
137
155
 
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useRef, useState } from 'react'
2
2
 
3
3
  type Props = {
4
- selectedFilter: number | boolean
4
+ selectedFilter: string | boolean
5
5
  }
6
6
 
7
7
  export const useScrollInToView = ({ selectedFilter }: Props) => {
@@ -9,7 +9,7 @@ export const useScrollInToView = ({ selectedFilter }: Props) => {
9
9
  const targetFilterBarRef = useRef<HTMLDivElement | null>(null)
10
10
 
11
11
  useEffect(() => {
12
- if (window !== undefined && window.innerWidth > 960) {
12
+ if (typeof window !== 'undefined' && window.innerWidth > 960) {
13
13
  setIsMobile(false)
14
14
  return
15
15
  }
@@ -1 +1,3 @@
1
- export { default } from "./FilterBar";
1
+ export { default } from './FilterBar'
2
+
3
+ export * from './FilterBarTypes'