willba-component-library 0.1.57 → 0.1.59
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/components/FilterBar/FilterBar.d.ts +3 -2
- package/lib/components/FilterBar/FilterBarTypes.d.ts +7 -0
- package/lib/components/FilterBar/components/calendar/Calendar.d.ts +3 -0
- package/lib/components/FilterBar/hooks/useFilterBar.d.ts +3 -3
- package/lib/components/FilterBar/utils/parseGuests.d.ts +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.esm.js +61 -28
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +61 -28
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +61 -28
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FilterBar/FilterBar.stories.tsx +4 -0
- package/src/components/FilterBar/FilterBar.tsx +21 -8
- package/src/components/FilterBar/FilterBarTypes.ts +9 -0
- package/src/components/FilterBar/components/calendar/Calendar.tsx +17 -3
- package/src/components/FilterBar/hooks/useFilterBar.tsx +15 -11
- package/src/components/FilterBar/utils/parseGuests.tsx +32 -10
- package/src/locales/en/filterBar.json +2 -1
- package/src/locales/fi/filterBar.json +2 -1
package/package.json
CHANGED
|
@@ -7,8 +7,10 @@ import '../../themes/Default.css'
|
|
|
7
7
|
import { parseDates, parseGuests } from './utils'
|
|
8
8
|
import {
|
|
9
9
|
AgeCategoryType,
|
|
10
|
+
CalendarOffset,
|
|
10
11
|
FilterSections,
|
|
11
12
|
Filters,
|
|
13
|
+
Pages,
|
|
12
14
|
ViewApply,
|
|
13
15
|
} from './FilterBarTypes'
|
|
14
16
|
import {
|
|
@@ -39,6 +41,7 @@ export type FilterBarProps = {
|
|
|
39
41
|
currentViewApply?: string
|
|
40
42
|
onSubmit?: ((val: Filters) => void) | null
|
|
41
43
|
fullWidth?: boolean
|
|
44
|
+
calendarOffset: CalendarOffset
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
export default function FilterBar({
|
|
@@ -49,6 +52,7 @@ export default function FilterBar({
|
|
|
49
52
|
currentViewApply,
|
|
50
53
|
onSubmit,
|
|
51
54
|
fullWidth,
|
|
55
|
+
calendarOffset,
|
|
52
56
|
}: FilterBarProps) {
|
|
53
57
|
const themePalette = useTheme({ palette })
|
|
54
58
|
|
|
@@ -69,6 +73,7 @@ export default function FilterBar({
|
|
|
69
73
|
handleSubmit,
|
|
70
74
|
updateGuestsCount,
|
|
71
75
|
setSelectedPath,
|
|
76
|
+
handleResetFilters,
|
|
72
77
|
} = useFilterBar({
|
|
73
78
|
redirectUrl,
|
|
74
79
|
currentViewApply,
|
|
@@ -79,7 +84,7 @@ export default function FilterBar({
|
|
|
79
84
|
// Default selected tab when tabs are hidden
|
|
80
85
|
useEffect(() => {
|
|
81
86
|
if (currentViewApply === ViewApply.ROOMS) {
|
|
82
|
-
setSelectedPath(
|
|
87
|
+
setSelectedPath(Pages.ROOMS)
|
|
83
88
|
}
|
|
84
89
|
}, [])
|
|
85
90
|
|
|
@@ -116,13 +121,17 @@ export default function FilterBar({
|
|
|
116
121
|
>
|
|
117
122
|
<TabButton
|
|
118
123
|
label={t('tabs.events')}
|
|
119
|
-
onClick={() =>
|
|
120
|
-
|
|
124
|
+
onClick={() => {
|
|
125
|
+
setSelectedPath(Pages.EVENTS), handleResetFilters()
|
|
126
|
+
}}
|
|
127
|
+
active={selectedPath === Pages.EVENTS}
|
|
121
128
|
/>
|
|
122
129
|
<TabButton
|
|
123
130
|
label={t('tabs.rooms')}
|
|
124
|
-
onClick={() =>
|
|
125
|
-
|
|
131
|
+
onClick={() => {
|
|
132
|
+
setSelectedPath(Pages.ROOMS), handleResetFilters()
|
|
133
|
+
}}
|
|
134
|
+
active={selectedPath === Pages.ROOMS}
|
|
126
135
|
/>
|
|
127
136
|
</div>
|
|
128
137
|
)}
|
|
@@ -136,7 +145,7 @@ export default function FilterBar({
|
|
|
136
145
|
description={
|
|
137
146
|
parsedDates
|
|
138
147
|
? parsedDates
|
|
139
|
-
: selectedPath ===
|
|
148
|
+
: selectedPath === Pages.ROOMS
|
|
140
149
|
? t('calendar.roomsLabelPlaceholder')
|
|
141
150
|
: t('calendar.eventsLabelPlaceholder')
|
|
142
151
|
}
|
|
@@ -144,14 +153,16 @@ export default function FilterBar({
|
|
|
144
153
|
active={selectedFilter === FilterSections.CALENDAR}
|
|
145
154
|
/>
|
|
146
155
|
|
|
147
|
-
{selectedPath ===
|
|
156
|
+
{selectedPath === Pages.ROOMS && (
|
|
148
157
|
<>
|
|
149
158
|
<Divider />
|
|
150
159
|
|
|
151
160
|
<SelectButton
|
|
152
161
|
label={t('guests.label')}
|
|
153
162
|
description={
|
|
154
|
-
parsedGuests
|
|
163
|
+
parsedGuests
|
|
164
|
+
? t('guests.guestsLabel') + parsedGuests
|
|
165
|
+
: t('guests.labelPlaceholder')
|
|
155
166
|
}
|
|
156
167
|
onClick={() => handleSelectedFilter(FilterSections.GUESTS)}
|
|
157
168
|
active={selectedFilter === FilterSections.GUESTS}
|
|
@@ -174,6 +185,8 @@ export default function FilterBar({
|
|
|
174
185
|
calendarRange={calendarRange}
|
|
175
186
|
setCalendarRange={setCalendarRange}
|
|
176
187
|
ref={filtersRef}
|
|
188
|
+
calendarOffset={calendarOffset}
|
|
189
|
+
selectedPath={selectedPath}
|
|
177
190
|
/>
|
|
178
191
|
)}
|
|
179
192
|
{selectedFilter === FilterSections.GUESTS && (
|
|
@@ -3,16 +3,23 @@ import { DateRange, DayPicker } from 'react-day-picker'
|
|
|
3
3
|
import { addDays, startOfDay, addMonths } from 'date-fns'
|
|
4
4
|
import { useMediaQuery } from 'react-responsive'
|
|
5
5
|
|
|
6
|
+
import { CalendarOffset } from '../../FilterBarTypes'
|
|
7
|
+
|
|
6
8
|
import 'react-day-picker/dist/style.css'
|
|
7
9
|
import './Calendar.css'
|
|
8
10
|
|
|
9
11
|
type Props = {
|
|
10
12
|
calendarRange: DateRange | undefined
|
|
11
13
|
setCalendarRange: (range: DateRange | undefined) => void
|
|
14
|
+
calendarOffset: CalendarOffset
|
|
15
|
+
selectedPath: string
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
export const Calendar = forwardRef<HTMLDivElement, Props>(
|
|
15
|
-
(
|
|
19
|
+
(
|
|
20
|
+
{ calendarRange, setCalendarRange, calendarOffset, selectedPath }: Props,
|
|
21
|
+
ref
|
|
22
|
+
) => {
|
|
16
23
|
const isTablet = useMediaQuery({ maxWidth: 960 })
|
|
17
24
|
|
|
18
25
|
useEffect(() => {
|
|
@@ -21,10 +28,17 @@ export const Calendar = forwardRef<HTMLDivElement, Props>(
|
|
|
21
28
|
|
|
22
29
|
const today = startOfDay(new Date())
|
|
23
30
|
|
|
31
|
+
const daysToOffsetCalendar = Object.entries(calendarOffset)?.find(
|
|
32
|
+
(page) => selectedPath.substring(1) === page[0]
|
|
33
|
+
)
|
|
34
|
+
|
|
24
35
|
const disabledDays = [
|
|
25
36
|
{
|
|
26
|
-
from: addDays(
|
|
27
|
-
|
|
37
|
+
from: addDays(
|
|
38
|
+
today,
|
|
39
|
+
!!daysToOffsetCalendar?.length ? daysToOffsetCalendar[1] : -2
|
|
40
|
+
),
|
|
41
|
+
to: addDays(today, -100),
|
|
28
42
|
},
|
|
29
43
|
]
|
|
30
44
|
const selectedStartDate = calendarRange?.from
|
|
@@ -2,7 +2,12 @@ import { useEffect, useState } from 'react'
|
|
|
2
2
|
import { DateRange } from 'react-day-picker'
|
|
3
3
|
import { format } from 'date-fns'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
AgeCategoryCount,
|
|
7
|
+
AgeCategoryType,
|
|
8
|
+
Filters,
|
|
9
|
+
Pages,
|
|
10
|
+
} from '../FilterBarTypes'
|
|
6
11
|
|
|
7
12
|
type Props = {
|
|
8
13
|
redirectUrl?: string
|
|
@@ -17,7 +22,7 @@ export const useFilterBar = ({
|
|
|
17
22
|
ageCategories,
|
|
18
23
|
onSubmit,
|
|
19
24
|
}: Props) => {
|
|
20
|
-
const [selectedPath, setSelectedPath] = useState(
|
|
25
|
+
const [selectedPath, setSelectedPath] = useState(Pages.EVENTS)
|
|
21
26
|
const [selectedFilter, setSelectedFilter] = useState<string | boolean>(false)
|
|
22
27
|
const [calendarRange, setCalendarRange] = useState<DateRange | undefined>()
|
|
23
28
|
|
|
@@ -65,11 +70,11 @@ export const useFilterBar = ({
|
|
|
65
70
|
// Handle default selected tab
|
|
66
71
|
if (typeof window === 'undefined') return
|
|
67
72
|
|
|
68
|
-
const currentPath = window.location.pathname.includes(
|
|
69
|
-
?
|
|
70
|
-
: window.location.pathname.includes(
|
|
71
|
-
?
|
|
72
|
-
:
|
|
73
|
+
const currentPath = window.location.pathname.includes(Pages.EVENTS)
|
|
74
|
+
? Pages.EVENTS
|
|
75
|
+
: window.location.pathname.includes(Pages.ROOMS)
|
|
76
|
+
? Pages.ROOMS
|
|
77
|
+
: Pages.EVENTS
|
|
73
78
|
|
|
74
79
|
setSelectedPath(currentPath)
|
|
75
80
|
}, [])
|
|
@@ -120,7 +125,7 @@ export const useFilterBar = ({
|
|
|
120
125
|
|
|
121
126
|
handleSelectedFilter(false)
|
|
122
127
|
|
|
123
|
-
if (onSubmit && selectedPath ===
|
|
128
|
+
if (onSubmit && selectedPath === Pages.ROOMS) {
|
|
124
129
|
const updatedParamsObject: { [key: string]: string } = {}
|
|
125
130
|
|
|
126
131
|
updatedParams.forEach((value, key) => {
|
|
@@ -141,7 +146,7 @@ export const useFilterBar = ({
|
|
|
141
146
|
}
|
|
142
147
|
|
|
143
148
|
handleSelectedFilter(false)
|
|
144
|
-
return onSubmit && selectedPath ===
|
|
149
|
+
return onSubmit && selectedPath === Pages.ROOMS
|
|
145
150
|
? onSubmit(newParams)
|
|
146
151
|
: (window.location.href = `${redirectUrl}/${selectedPath}${
|
|
147
152
|
querySearchParams ? `?${querySearchParams.toString()}` : ''
|
|
@@ -151,8 +156,7 @@ export const useFilterBar = ({
|
|
|
151
156
|
|
|
152
157
|
const handleResetFilters = () => {
|
|
153
158
|
setAgeCategoryCounts({})
|
|
154
|
-
|
|
155
|
-
setSelectedFilter(false)
|
|
159
|
+
setCalendarRange(undefined)
|
|
156
160
|
}
|
|
157
161
|
|
|
158
162
|
return {
|
|
@@ -5,15 +5,37 @@ type Props = {
|
|
|
5
5
|
ageCategories: AgeCategoryType[]
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
type AccType = {
|
|
9
|
+
total: number
|
|
10
|
+
html: string[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const parseGuests = ({ ageCategoryCounts, ageCategories }: Props) => {
|
|
14
|
+
const parsedData = Object.entries(ageCategoryCounts).reduce(
|
|
15
|
+
(acc: AccType, [key, value]) => {
|
|
16
|
+
const ageCategoryId = key[key.length - 1]
|
|
17
|
+
const ageCategory = ageCategories.find((c) => c.id === ageCategoryId)
|
|
18
|
+
|
|
19
|
+
if (ageCategory && value) {
|
|
20
|
+
return {
|
|
21
|
+
total: acc.total + value,
|
|
22
|
+
html: [
|
|
23
|
+
...acc.html,
|
|
24
|
+
`<span style="display: inline-block; width: 21px, text-align: center">${value}</span>`,
|
|
25
|
+
],
|
|
26
|
+
}
|
|
27
|
+
}
|
|
11
28
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
29
|
+
return acc
|
|
30
|
+
},
|
|
31
|
+
{ total: 0, html: [] }
|
|
32
|
+
)
|
|
17
33
|
|
|
18
|
-
|
|
19
|
-
|
|
34
|
+
const htmlString =
|
|
35
|
+
parsedData.html.length > 1 ? parsedData.html.join(' + ') : ''
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
(parsedData.total || htmlString) &&
|
|
39
|
+
`: ${parsedData.total} ${htmlString ? `- ( ${htmlString} )` : ''}`
|
|
40
|
+
)
|
|
41
|
+
}
|