willba-component-library 0.3.19 → 0.3.20
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/README.md +1 -1
- package/lib/components/FilterBar/hooks/useFilterUi.d.ts +2 -1
- package/lib/components/FilterBar/hooks/usePanelPosition.d.ts +2 -2
- package/lib/components/FilterBar/hooks/useScrollInToView.d.ts +1 -1
- package/lib/components/FilterBar/providers/FilterBarProvider.d.ts +3 -2
- package/lib/core/hooks/useCloseFilterSection.d.ts +1 -1
- package/lib/index.esm.js +36 -34
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +36 -34
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +36 -34
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FilterBar/components/FilterControls/FilterControls.tsx +9 -5
- package/src/components/FilterBar/components/FilterPanels/FilterPanels.tsx +10 -11
- package/src/components/FilterBar/components/FilterTabs/FilterTabs.tsx +2 -2
- package/src/components/FilterBar/hooks/useFilterUi.tsx +4 -2
- package/src/components/FilterBar/hooks/usePanelPosition.tsx +3 -3
- package/src/components/FilterBar/hooks/useScrollInToView.tsx +4 -4
- package/src/components/FilterBar/providers/FilterBarProvider.tsx +4 -2
- package/src/components/FilterCalendar/FilterCalendar.tsx +2 -2
- package/src/core/hooks/useCloseFilterSection.tsx +5 -5
package/package.json
CHANGED
|
@@ -27,15 +27,13 @@ export const FilterControls = () => {
|
|
|
27
27
|
locations,
|
|
28
28
|
innerLoading,
|
|
29
29
|
outerLoading,
|
|
30
|
-
|
|
31
30
|
handleSubmit,
|
|
32
31
|
handleSelectedFilter,
|
|
33
32
|
|
|
34
|
-
// Refs
|
|
35
33
|
previouslyFocusedButtonRef,
|
|
36
34
|
buttonRefs,
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
tabsRef,
|
|
36
|
+
filtersRef,
|
|
39
37
|
} = useFilterBar()
|
|
40
38
|
|
|
41
39
|
// Store previously focused button and restore focus when closing
|
|
@@ -64,7 +62,13 @@ export const FilterControls = () => {
|
|
|
64
62
|
return (
|
|
65
63
|
<div
|
|
66
64
|
className={`will-filter-bar-controls ${mode || 'light'}`}
|
|
67
|
-
ref={
|
|
65
|
+
ref={(el) => {
|
|
66
|
+
filtersRef.current = el
|
|
67
|
+
|
|
68
|
+
if (tabs?.length === 1) {
|
|
69
|
+
tabsRef.current = el
|
|
70
|
+
}
|
|
71
|
+
}}
|
|
68
72
|
>
|
|
69
73
|
{!!locations?.data?.length && (
|
|
70
74
|
<>
|
|
@@ -29,7 +29,7 @@ export const FilterPanels = () => {
|
|
|
29
29
|
isMobile,
|
|
30
30
|
panelRef,
|
|
31
31
|
buttonRefs,
|
|
32
|
-
|
|
32
|
+
filtersRef,
|
|
33
33
|
setSelectedLocations,
|
|
34
34
|
setCalendarRange,
|
|
35
35
|
handleSelectedFilter,
|
|
@@ -38,12 +38,12 @@ export const FilterPanels = () => {
|
|
|
38
38
|
} = useFilterBar()
|
|
39
39
|
|
|
40
40
|
// Handle close filter section
|
|
41
|
-
const {
|
|
41
|
+
const { filterSectionRef } = useCloseFilterSection({ handleSelectedFilter })
|
|
42
42
|
|
|
43
43
|
const { localStyles } = usePanelPosition({
|
|
44
44
|
selectedFilter,
|
|
45
45
|
panelRef,
|
|
46
|
-
|
|
46
|
+
filtersRef,
|
|
47
47
|
buttonRefs,
|
|
48
48
|
isMobile,
|
|
49
49
|
})
|
|
@@ -54,7 +54,7 @@ export const FilterPanels = () => {
|
|
|
54
54
|
return (
|
|
55
55
|
<Dates
|
|
56
56
|
autoFocus
|
|
57
|
-
ref={
|
|
57
|
+
ref={filterSectionRef}
|
|
58
58
|
onClose={() => handleSelectedFilter(false)}
|
|
59
59
|
calendarRange={calendarRange}
|
|
60
60
|
setCalendarRange={setCalendarRange}
|
|
@@ -67,7 +67,7 @@ export const FilterPanels = () => {
|
|
|
67
67
|
return (
|
|
68
68
|
<Guests
|
|
69
69
|
autoFocus
|
|
70
|
-
ref={
|
|
70
|
+
ref={filterSectionRef}
|
|
71
71
|
ageCategories={ageCategories}
|
|
72
72
|
ageCategoryCounts={ageCategoryCounts}
|
|
73
73
|
updateGuestsCount={updateGuestsCount}
|
|
@@ -82,7 +82,7 @@ export const FilterPanels = () => {
|
|
|
82
82
|
return (
|
|
83
83
|
<Locations
|
|
84
84
|
autoFocus
|
|
85
|
-
ref={
|
|
85
|
+
ref={filterSectionRef}
|
|
86
86
|
locations={locations?.data}
|
|
87
87
|
language={language}
|
|
88
88
|
selectedLocations={selectedLocations}
|
|
@@ -102,11 +102,10 @@ export const FilterPanels = () => {
|
|
|
102
102
|
<div
|
|
103
103
|
ref={panelRef}
|
|
104
104
|
className={`will-filter-bar-panels ${mode || 'light'}`}
|
|
105
|
-
style={
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
105
|
+
style={{
|
|
106
|
+
...localStyles,
|
|
107
|
+
...((!tabs || tabs.length < 2) && !isMobile ? { top: 66 } : {}),
|
|
108
|
+
}}
|
|
110
109
|
>
|
|
111
110
|
{renderContent()}
|
|
112
111
|
</div>
|
|
@@ -19,13 +19,13 @@ export const FilterTabs = () => {
|
|
|
19
19
|
setSelectedPath,
|
|
20
20
|
handleResetFilters,
|
|
21
21
|
//
|
|
22
|
-
|
|
22
|
+
tabsRef,
|
|
23
23
|
} = useFilterBar()
|
|
24
24
|
|
|
25
25
|
return (
|
|
26
26
|
tabs &&
|
|
27
27
|
tabs.length > 1 && (
|
|
28
|
-
<div className="will-filter-bar-tabs" ref={
|
|
28
|
+
<div className="will-filter-bar-tabs" ref={tabsRef}>
|
|
29
29
|
{tabs
|
|
30
30
|
.sort((a, b) => a.order - b.order)
|
|
31
31
|
.map((tab, idx) => (
|
|
@@ -6,14 +6,16 @@ export const useFilterUi = (selectedFilter: string | boolean) => {
|
|
|
6
6
|
const buttonRefs = useRef<Record<string, HTMLButtonElement | null>>({})
|
|
7
7
|
const panelRef = useRef<HTMLDivElement | null>(null)
|
|
8
8
|
const previouslyFocusedButtonRef = useRef<HTMLButtonElement | null>(null)
|
|
9
|
+
const filtersRef = useRef<HTMLDivElement | null>(null)
|
|
9
10
|
|
|
10
|
-
const { isMobile,
|
|
11
|
+
const { isMobile, tabsRef } = useScrollInToView({ selectedFilter })
|
|
11
12
|
|
|
12
13
|
return {
|
|
13
14
|
previouslyFocusedButtonRef,
|
|
14
15
|
isMobile,
|
|
15
|
-
|
|
16
|
+
tabsRef,
|
|
16
17
|
panelRef,
|
|
17
18
|
buttonRefs,
|
|
19
|
+
filtersRef,
|
|
18
20
|
}
|
|
19
21
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
type Props = {
|
|
10
10
|
selectedFilter: string | boolean
|
|
11
11
|
panelRef: RefObject<HTMLDivElement | null>
|
|
12
|
-
|
|
12
|
+
filtersRef: RefObject<HTMLDivElement | null>
|
|
13
13
|
buttonRefs: MutableRefObject<Record<string, HTMLButtonElement | null>>
|
|
14
14
|
isMobile: boolean
|
|
15
15
|
}
|
|
@@ -17,7 +17,7 @@ type Props = {
|
|
|
17
17
|
export const usePanelPosition = ({
|
|
18
18
|
selectedFilter,
|
|
19
19
|
panelRef,
|
|
20
|
-
|
|
20
|
+
filtersRef,
|
|
21
21
|
buttonRefs,
|
|
22
22
|
isMobile,
|
|
23
23
|
}: Props) => {
|
|
@@ -30,7 +30,7 @@ export const usePanelPosition = ({
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
const panel = panelRef.current
|
|
33
|
-
const container =
|
|
33
|
+
const container = filtersRef.current
|
|
34
34
|
const button = buttonRefs.current[selectedFilter]
|
|
35
35
|
|
|
36
36
|
if (!panel || !container || !button) return
|
|
@@ -6,7 +6,7 @@ type Props = {
|
|
|
6
6
|
|
|
7
7
|
export const useScrollInToView = ({ selectedFilter }: Props) => {
|
|
8
8
|
const [isMobile, setIsMobile] = useState(true)
|
|
9
|
-
const
|
|
9
|
+
const tabsRef = useRef<HTMLDivElement | null>(null)
|
|
10
10
|
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
if (typeof window !== 'undefined' && window.innerWidth > 960) {
|
|
@@ -14,16 +14,16 @@ export const useScrollInToView = ({ selectedFilter }: Props) => {
|
|
|
14
14
|
return
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
if (
|
|
17
|
+
if (tabsRef.current && selectedFilter) {
|
|
18
18
|
window.scrollTo({
|
|
19
19
|
behavior: 'smooth',
|
|
20
20
|
top:
|
|
21
|
-
|
|
21
|
+
tabsRef.current.getBoundingClientRect().top -
|
|
22
22
|
document.body.getBoundingClientRect().top -
|
|
23
23
|
30,
|
|
24
24
|
})
|
|
25
25
|
}
|
|
26
26
|
}, [selectedFilter])
|
|
27
27
|
|
|
28
|
-
return { isMobile,
|
|
28
|
+
return { isMobile, tabsRef }
|
|
29
29
|
}
|
|
@@ -38,10 +38,11 @@ type FilterBarContextType = FilterBarTypes & {
|
|
|
38
38
|
previouslyFocusedButtonRef: MutableRefObject<HTMLButtonElement | null>
|
|
39
39
|
panelRef: MutableRefObject<HTMLDivElement | null>
|
|
40
40
|
buttonRefs: MutableRefObject<Record<string, HTMLButtonElement | null>>
|
|
41
|
+
filtersRef: MutableRefObject<HTMLDivElement | null>
|
|
41
42
|
|
|
42
43
|
// Mobile
|
|
43
44
|
isMobile: boolean
|
|
44
|
-
|
|
45
|
+
tabsRef: MutableRefObject<HTMLDivElement | null>
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
const FilterBarContext = createContext<FilterBarContextType | undefined>(
|
|
@@ -150,7 +151,8 @@ export const FilterBarProvider = ({
|
|
|
150
151
|
outerLoading,
|
|
151
152
|
locations,
|
|
152
153
|
filterUi.isMobile,
|
|
153
|
-
filterUi.
|
|
154
|
+
filterUi.tabsRef,
|
|
155
|
+
filterUi.filtersRef,
|
|
154
156
|
]
|
|
155
157
|
)
|
|
156
158
|
|
|
@@ -62,14 +62,14 @@ export default function FilterCalendar({
|
|
|
62
62
|
useAwaitRender()
|
|
63
63
|
|
|
64
64
|
// Handle close filter section
|
|
65
|
-
const {
|
|
65
|
+
const { filterSectionRef } = useCloseFilterSection({
|
|
66
66
|
handleSelectedFilter: setToggleCalendar,
|
|
67
67
|
})
|
|
68
68
|
|
|
69
69
|
return (
|
|
70
70
|
<div className={`will-root`} style={themePalette}>
|
|
71
71
|
{toggleCalendar && (
|
|
72
|
-
<div className={`will-calendar-wrapper`} ref={
|
|
72
|
+
<div className={`will-calendar-wrapper`} ref={filterSectionRef}>
|
|
73
73
|
<div className={`will-calendar-header`}>
|
|
74
74
|
<h2>{t('filterBar:calendar.title')}</h2>
|
|
75
75
|
<CloseButton handleClose={() => setToggleCalendar(false)} />
|
|
@@ -6,13 +6,13 @@ type Props = {
|
|
|
6
6
|
|
|
7
7
|
// TODO - Refactor and rename this hook
|
|
8
8
|
export const useCloseFilterSection = ({ handleSelectedFilter }: Props) => {
|
|
9
|
-
const
|
|
9
|
+
const filterSectionRef = useRef<HTMLDivElement | null>(null)
|
|
10
10
|
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
const handleClickOutside = (event: MouseEvent) => {
|
|
13
13
|
if (
|
|
14
|
-
|
|
15
|
-
!
|
|
14
|
+
filterSectionRef.current &&
|
|
15
|
+
!filterSectionRef.current.contains(event.target as Node)
|
|
16
16
|
) {
|
|
17
17
|
handleSelectedFilter(false)
|
|
18
18
|
}
|
|
@@ -23,7 +23,7 @@ export const useCloseFilterSection = ({ handleSelectedFilter }: Props) => {
|
|
|
23
23
|
return () => {
|
|
24
24
|
document.removeEventListener('mousedown', handleClickOutside)
|
|
25
25
|
}
|
|
26
|
-
}, [
|
|
26
|
+
}, [filterSectionRef])
|
|
27
27
|
|
|
28
|
-
return {
|
|
28
|
+
return { filterSectionRef }
|
|
29
29
|
}
|