willba-component-library 0.1.28 → 0.1.29
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/hooks/useFilterBar.d.ts +4 -3
- package/lib/index.d.ts +3 -2
- package/lib/index.esm.js +207 -112
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +221 -126
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +10667 -10572
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FilterBar/FilterBar.css +2 -1
- package/src/components/FilterBar/FilterBar.stories.tsx +1 -0
- package/src/components/FilterBar/FilterBar.tsx +32 -16
- package/src/components/FilterBar/components/guests/Guests.css +2 -0
- package/src/components/FilterBar/hooks/useFilterBar.tsx +81 -40
- package/tsconfig.json +1 -0
package/package.json
CHANGED
|
@@ -23,8 +23,9 @@ export interface FilterBarProps {
|
|
|
23
23
|
vendor?: string
|
|
24
24
|
language?: string
|
|
25
25
|
ageCategories?: AgeCategoryType[]
|
|
26
|
-
redirectUrl
|
|
26
|
+
redirectUrl?: string
|
|
27
27
|
palette?: Palette
|
|
28
|
+
currentViewApply?: string
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
export default function FilterBar({
|
|
@@ -32,11 +33,14 @@ export default function FilterBar({
|
|
|
32
33
|
ageCategories = AGE_CATEGORIES_FALLBACK,
|
|
33
34
|
redirectUrl = REDIRECT_URL_FALLBACK,
|
|
34
35
|
palette,
|
|
36
|
+
currentViewApply,
|
|
35
37
|
}: FilterBarProps) {
|
|
36
38
|
const themePalette = useTheme({ palette })
|
|
37
39
|
|
|
38
40
|
// Translations
|
|
39
41
|
const [rerenderKey, setRerenderKey] = useState(0)
|
|
42
|
+
const [isMobile, setIsMobile] = useState(true)
|
|
43
|
+
|
|
40
44
|
useEffect(() => {
|
|
41
45
|
i18n.changeLanguage(language)
|
|
42
46
|
|
|
@@ -58,13 +62,20 @@ export default function FilterBar({
|
|
|
58
62
|
handleSubmit,
|
|
59
63
|
updateGuestsCount,
|
|
60
64
|
setSelectedPath,
|
|
61
|
-
} = useFilterBar({ redirectUrl })
|
|
65
|
+
} = useFilterBar({ redirectUrl, currentViewApply })
|
|
62
66
|
|
|
63
67
|
// Scroll in to view
|
|
64
68
|
|
|
65
69
|
const targetFilterBarRef = useRef<HTMLDivElement | null>(null)
|
|
66
70
|
useEffect(() => {
|
|
67
|
-
if (
|
|
71
|
+
if (currentViewApply === 'roomFilters') {
|
|
72
|
+
setSelectedPath('/rooms')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (window !== undefined && window.innerWidth > 960) {
|
|
76
|
+
setIsMobile(false)
|
|
77
|
+
return
|
|
78
|
+
}
|
|
68
79
|
if (targetFilterBarRef.current && selectedFilter) {
|
|
69
80
|
window.scrollTo({
|
|
70
81
|
behavior: 'smooth',
|
|
@@ -91,18 +102,20 @@ export default function FilterBar({
|
|
|
91
102
|
className={`will-root ${selectedFilter ? 'isMobileAbsolute' : ''}`}
|
|
92
103
|
style={themePalette}
|
|
93
104
|
>
|
|
94
|
-
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
{!currentViewApply && (
|
|
106
|
+
<div className="will-filter-bar-tabs" ref={targetFilterBarRef}>
|
|
107
|
+
<TabButton
|
|
108
|
+
label={t('tabs.events')}
|
|
109
|
+
onClick={() => setSelectedPath('/events')}
|
|
110
|
+
active={selectedPath === '/events'}
|
|
111
|
+
/>
|
|
112
|
+
<TabButton
|
|
113
|
+
label={t('tabs.rooms')}
|
|
114
|
+
onClick={() => setSelectedPath('/rooms')}
|
|
115
|
+
active={selectedPath === '/rooms'}
|
|
116
|
+
/>
|
|
117
|
+
</div>
|
|
118
|
+
)}
|
|
106
119
|
|
|
107
120
|
<div className="will-filter-bar-header">
|
|
108
121
|
<SelectButton
|
|
@@ -129,7 +142,10 @@ export default function FilterBar({
|
|
|
129
142
|
</div>
|
|
130
143
|
|
|
131
144
|
{selectedFilter && (
|
|
132
|
-
<div
|
|
145
|
+
<div
|
|
146
|
+
className="will-filter-bar-container"
|
|
147
|
+
style={currentViewApply && !isMobile ? { top: 66 } : {}}
|
|
148
|
+
>
|
|
133
149
|
<CloseButton handleClose={() => handleSelectedFilter(false)} />
|
|
134
150
|
|
|
135
151
|
{selectedFilter === 1 && (
|
|
@@ -5,10 +5,14 @@ import { format } from 'date-fns'
|
|
|
5
5
|
import { AgeCategoryCount } from '../FilterBarTypes'
|
|
6
6
|
|
|
7
7
|
interface UseFilterBarPropsType {
|
|
8
|
-
redirectUrl
|
|
8
|
+
redirectUrl?: string
|
|
9
|
+
currentViewApply?: string
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
export default function useFilterBar({
|
|
12
|
+
export default function useFilterBar({
|
|
13
|
+
redirectUrl,
|
|
14
|
+
currentViewApply,
|
|
15
|
+
}: UseFilterBarPropsType) {
|
|
12
16
|
const [selectedPath, setSelectedPath] = useState('/events')
|
|
13
17
|
|
|
14
18
|
const [selectedFilter, setSelectedFilter] = useState<number | boolean>(false)
|
|
@@ -19,13 +23,6 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
|
|
|
19
23
|
{}
|
|
20
24
|
)
|
|
21
25
|
|
|
22
|
-
const updateGuestsCount = (id: string, newCount: number) => {
|
|
23
|
-
setAgeCategoryCounts((prevCounts) => ({
|
|
24
|
-
...prevCounts,
|
|
25
|
-
[id]: newCount,
|
|
26
|
-
}))
|
|
27
|
-
}
|
|
28
|
-
|
|
29
26
|
useEffect(() => {
|
|
30
27
|
const urlSearchParams = new URLSearchParams(window.location.search)
|
|
31
28
|
|
|
@@ -49,14 +46,43 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
|
|
|
49
46
|
setCategories(parsedCategories)
|
|
50
47
|
}, [])
|
|
51
48
|
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (typeof window === 'undefined') return
|
|
51
|
+
|
|
52
|
+
document.body.style.overflow =
|
|
53
|
+
selectedFilter && window.innerWidth < 960 ? 'hidden' : 'visible'
|
|
54
|
+
|
|
55
|
+
return () => {
|
|
56
|
+
document.body.style.overflow = 'visible'
|
|
57
|
+
}
|
|
58
|
+
}, [selectedFilter])
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (typeof window !== 'undefined') {
|
|
62
|
+
// Handle default selected tab
|
|
63
|
+
const currentPath = window.location.pathname.includes('/events')
|
|
64
|
+
? '/events'
|
|
65
|
+
: window.location.pathname.includes('/rooms')
|
|
66
|
+
? '/rooms'
|
|
67
|
+
: '/events'
|
|
68
|
+
|
|
69
|
+
setSelectedPath(currentPath)
|
|
70
|
+
}
|
|
71
|
+
}, [])
|
|
72
|
+
|
|
73
|
+
const updateGuestsCount = (id: string, newCount: number) => {
|
|
74
|
+
setAgeCategoryCounts((prevCounts) => ({
|
|
75
|
+
...prevCounts,
|
|
76
|
+
[id]: newCount,
|
|
77
|
+
}))
|
|
78
|
+
}
|
|
79
|
+
|
|
52
80
|
const handleSelectedFilter = (id: number | boolean) => {
|
|
53
81
|
setSelectedFilter(id)
|
|
54
82
|
}
|
|
55
83
|
|
|
56
84
|
const handleSubmit = () => {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const params = {
|
|
85
|
+
const newParams = {
|
|
60
86
|
startDate: calendarRange?.from
|
|
61
87
|
? format(calendarRange.from, 'yyyy-MM-dd')
|
|
62
88
|
: '',
|
|
@@ -67,43 +93,58 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
|
|
|
67
93
|
: '',
|
|
68
94
|
}
|
|
69
95
|
|
|
70
|
-
|
|
96
|
+
// const getQueryParams = () => {
|
|
97
|
+
// const currentSearchParams = new URLSearchParams(window.location.search)
|
|
71
98
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
99
|
+
// const params: { [key: string]: string } = {}
|
|
100
|
+
// for (const [key, value] of currentSearchParams.entries()) {
|
|
101
|
+
// params[key] = value
|
|
102
|
+
// }
|
|
103
|
+
// return params
|
|
104
|
+
// }
|
|
105
|
+
|
|
106
|
+
if (currentViewApply) {
|
|
107
|
+
const currentSearchParams = new URLSearchParams(window.location.search)
|
|
108
|
+
const updatedParams = new URLSearchParams()
|
|
109
|
+
|
|
110
|
+
for (const [key, value] of currentSearchParams.entries()) {
|
|
111
|
+
updatedParams.append(key, value)
|
|
75
112
|
}
|
|
76
|
-
}
|
|
77
113
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
114
|
+
for (const [key, value] of Object.entries(newParams)) {
|
|
115
|
+
if (value) {
|
|
116
|
+
updatedParams.set(key, value.toString())
|
|
117
|
+
} else {
|
|
118
|
+
updatedParams.delete(key)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
83
121
|
|
|
84
|
-
|
|
85
|
-
if (typeof window === 'undefined') return
|
|
122
|
+
console.log(currentSearchParams.toString(), updatedParams.toString())
|
|
86
123
|
|
|
87
|
-
|
|
88
|
-
|
|
124
|
+
// Get the current URL without the query string
|
|
125
|
+
const baseUrl = window.location.origin + window.location.pathname
|
|
89
126
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
}, [selectedFilter])
|
|
127
|
+
// Construct the updated URL with the modified query parameters
|
|
128
|
+
const updatedUrl = `${baseUrl}?${updatedParams.toString()}`
|
|
94
129
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
? '/events'
|
|
100
|
-
: window.location.pathname.includes('/rooms')
|
|
101
|
-
? '/rooms'
|
|
102
|
-
: '/events'
|
|
130
|
+
// Replace the current URL with the updated URL in the browser's history
|
|
131
|
+
return (window.location.href = updatedUrl)
|
|
132
|
+
} else {
|
|
133
|
+
const querySearchParams = new URLSearchParams()
|
|
103
134
|
|
|
104
|
-
|
|
135
|
+
for (const [key, value] of Object.entries(newParams)) {
|
|
136
|
+
if (value) {
|
|
137
|
+
querySearchParams.append(key, value.toString())
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (window.location.href = `${redirectUrl}/${selectedPath}${
|
|
142
|
+
querySearchParams ? `?${querySearchParams.toString()}` : ''
|
|
143
|
+
}`)
|
|
105
144
|
}
|
|
106
|
-
|
|
145
|
+
|
|
146
|
+
handleSelectedFilter(false)
|
|
147
|
+
}
|
|
107
148
|
|
|
108
149
|
const handleResetFilters = () => {
|
|
109
150
|
setAgeCategoryCounts({})
|