willba-component-library 0.0.31 → 0.0.35
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 +2 -2
- package/lib/components/FilterBar/components/calendar/Calendar.d.ts +4 -0
- package/lib/components/FilterBar/components/categories/Categories.d.ts +3 -0
- package/lib/components/FilterBar/components/divider/Divider.d.ts +3 -0
- package/lib/components/FilterBar/components/guests/Guests.d.ts +3 -0
- package/lib/components/FilterBar/components/select-button/SelectButton.d.ts +3 -0
- package/lib/components/FilterBar/components/submit-button/SubmitButton.d.ts +3 -0
- package/lib/components/FilterBar/hooks/useFilterBar.d.ts +16 -0
- package/lib/index.esm.js +5693 -87
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +5724 -100
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +5724 -100
- package/lib/index.umd.js.map +1 -1
- package/package.json +4 -2
- package/prettier.config.js +6 -0
- package/src/components/FilterBar/FilterBar.css +3 -97
- package/src/components/FilterBar/FilterBar.tsx +35 -127
- package/src/components/FilterBar/components/calendar/Calendar.css +4 -0
- package/src/components/FilterBar/components/calendar/Calendar.tsx +33 -0
- package/src/components/FilterBar/components/categories/Categories.css +15 -0
- package/src/components/FilterBar/components/categories/Categories.tsx +37 -0
- package/src/components/FilterBar/components/divider/Divider.css +6 -0
- package/src/components/FilterBar/components/divider/Divider.tsx +7 -0
- package/src/components/FilterBar/components/guests/Guests.css +44 -0
- package/src/components/FilterBar/components/guests/Guests.tsx +42 -0
- package/src/components/FilterBar/components/select-button/SelectButton.css +9 -0
- package/src/components/FilterBar/components/select-button/SelectButton.tsx +11 -0
- package/src/components/FilterBar/components/submit-button/SubmitButton.css +11 -0
- package/src/components/FilterBar/components/submit-button/SubmitButton.tsx +11 -0
- package/src/components/FilterBar/hooks/useFilterBar.tsx +54 -0
- package/src/components/FilterBar/components/Callendar.tsx +0 -5
- package/src/components/FilterBar/components/Divider.tsx +0 -5
- package/src/components/FilterBar/components/SelectButton.tsx +0 -9
- package/src/components/FilterBar/components/SubmitButton.tsx +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "willba-component-library",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.35",
|
|
4
4
|
"description": "A stroybook 6 with TypeScript demo",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.esm.js",
|
|
@@ -14,7 +14,9 @@
|
|
|
14
14
|
"author": "Willba",
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"classnames": "^2.3.2"
|
|
17
|
+
"classnames": "^2.3.2",
|
|
18
|
+
"date-fns": "^2.30.0",
|
|
19
|
+
"react-day-picker": "^8.8.0"
|
|
18
20
|
},
|
|
19
21
|
"peerDependencies": {
|
|
20
22
|
"react": "^18.2.0",
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
.root {
|
|
4
|
-
width: 100%;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
.search-widget {
|
|
1
|
+
.filter-bar {
|
|
8
2
|
box-sizing: border-box;
|
|
9
3
|
max-width: 1100px;
|
|
10
4
|
position: relative;
|
|
11
5
|
}
|
|
12
6
|
|
|
13
|
-
.
|
|
7
|
+
.filter-bar-header {
|
|
14
8
|
display: flex;
|
|
15
9
|
justify-content: space-between;
|
|
16
10
|
align-items: center;
|
|
@@ -23,7 +17,7 @@
|
|
|
23
17
|
box-shadow: 0px 6px 11px 0px #a7a4a480;
|
|
24
18
|
}
|
|
25
19
|
|
|
26
|
-
.
|
|
20
|
+
.filter-bar-container {
|
|
27
21
|
background-color: #fff;
|
|
28
22
|
min-height: 100px;
|
|
29
23
|
|
|
@@ -36,96 +30,8 @@
|
|
|
36
30
|
box-shadow: 0px 6px 11px 0px #a7a4a480;
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
.search-widget-divider {
|
|
40
|
-
width: 1px;
|
|
41
|
-
margin: 0 10px;
|
|
42
|
-
height: 35px;
|
|
43
|
-
background-color: #384265;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.search-widget-submit-button {
|
|
47
|
-
width: auto;
|
|
48
|
-
height: auto;
|
|
49
|
-
background-color: #384265;
|
|
50
|
-
color: #fff;
|
|
51
|
-
padding: 10px 20px;
|
|
52
|
-
border-radius: 20px;
|
|
53
|
-
cursor: pointer;
|
|
54
|
-
border: none;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
.search-widget-select-button {
|
|
58
|
-
width: auto;
|
|
59
|
-
height: auto;
|
|
60
|
-
background-color: transparent;
|
|
61
|
-
border: none;
|
|
62
|
-
padding: 10px 20px;
|
|
63
|
-
border-radius: 20px;
|
|
64
|
-
cursor: pointer;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/* Filters - Guests ---------------------------- */
|
|
68
|
-
|
|
69
|
-
.search-widget-guests {
|
|
70
|
-
text-align: initial;
|
|
71
|
-
}
|
|
72
33
|
|
|
73
|
-
.guests-filter-container {
|
|
74
|
-
display: flex;
|
|
75
|
-
margin-top: 30px;
|
|
76
|
-
}
|
|
77
34
|
|
|
78
|
-
.guests-filter-inner {
|
|
79
|
-
display: flex;
|
|
80
|
-
align-items: center;
|
|
81
|
-
}
|
|
82
35
|
|
|
83
|
-
.guests-filter-inner:not(:last-child) {
|
|
84
|
-
margin-right: 50px;
|
|
85
|
-
}
|
|
86
36
|
|
|
87
|
-
.guests-filter-inner > span {
|
|
88
|
-
display: block;
|
|
89
|
-
margin-right: 20px;
|
|
90
|
-
font-weight: bold;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
.guests-filter-inner > div {
|
|
94
|
-
display: flex;
|
|
95
|
-
align-items: center;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
.guests-filter-inner > div > span {
|
|
99
|
-
margin: 0 10px;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
.guests-filter-inner > div button {
|
|
103
|
-
border-radius: 50%;
|
|
104
|
-
border: none;
|
|
105
|
-
background-color: #CDEEFF;
|
|
106
|
-
width: 25px;
|
|
107
|
-
height: 25px;
|
|
108
|
-
display: flex;
|
|
109
|
-
justify-content: center;
|
|
110
|
-
align-items: center;
|
|
111
|
-
font-size: 20px;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/* Filters - Categories ---------------------------- */
|
|
115
|
-
|
|
116
|
-
.search-widget-categories {
|
|
117
|
-
text-align: center;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
.categories-filter-inner {
|
|
121
|
-
display: flex;
|
|
122
|
-
align-items: center;
|
|
123
|
-
justify-content: center;
|
|
124
|
-
gap: 20px;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
.categories-filter-inner input {
|
|
128
|
-
cursor: pointer;
|
|
129
|
-
margin-right: 10px;
|
|
130
|
-
}
|
|
131
37
|
|
|
@@ -1,55 +1,41 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react'
|
|
2
2
|
|
|
3
|
-
import Divider from
|
|
4
|
-
import SelectButton from
|
|
5
|
-
import SubmitButton from
|
|
3
|
+
import Divider from './components/divider/Divider'
|
|
4
|
+
import SelectButton from './components/select-button/SelectButton'
|
|
5
|
+
import SubmitButton from './components/submit-button/SubmitButton'
|
|
6
|
+
import Calendar from './components/calendar/Calendar'
|
|
7
|
+
import Guests from './components/guests/Guests'
|
|
8
|
+
import Categories from './components/categories/Categories'
|
|
6
9
|
|
|
7
|
-
import
|
|
10
|
+
import useFilterBar from './hooks/useFilterBar'
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
const [selectedFilter, setSelectedFilter] = useState<number | boolean>(false);
|
|
11
|
-
// const [startDate, setStartDate] = useState(0);
|
|
12
|
-
// const [endDate, setEndDate] = useState(0);
|
|
13
|
-
const [guestsAdults, setGuestsAdults] = useState(1);
|
|
14
|
-
const [guestsKids, setGuestsKids] = useState(0);
|
|
15
|
-
const [categories, setCategories] = useState(0);
|
|
16
|
-
|
|
17
|
-
const handleSelectedFilter = (id: any) => {
|
|
18
|
-
setSelectedFilter(id);
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const handleSubmit = () => {
|
|
22
|
-
const queryParams = new URLSearchParams();
|
|
23
|
-
|
|
24
|
-
const params = {
|
|
25
|
-
// startDate,
|
|
26
|
-
// endDate,
|
|
27
|
-
guestsAdults,
|
|
28
|
-
guestsKids,
|
|
29
|
-
categories,
|
|
30
|
-
};
|
|
12
|
+
import './FilterBar.css'
|
|
31
13
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
14
|
+
export default function FilterBar() {
|
|
15
|
+
const {
|
|
16
|
+
selectedFilter,
|
|
17
|
+
guestsAdults,
|
|
18
|
+
guestsKids,
|
|
19
|
+
categories,
|
|
20
|
+
calendarRange,
|
|
21
|
+
setCalendarRange,
|
|
22
|
+
setGuestsAdults,
|
|
23
|
+
setGuestsKids,
|
|
24
|
+
setCategories,
|
|
25
|
+
handleSelectedFilter,
|
|
26
|
+
handleSubmit,
|
|
27
|
+
} = useFilterBar()
|
|
42
28
|
|
|
43
29
|
return (
|
|
44
|
-
<div className="
|
|
45
|
-
<div className="
|
|
30
|
+
<div className="filter-bar">
|
|
31
|
+
<div className="filter-bar-header">
|
|
46
32
|
<SelectButton
|
|
47
|
-
label=
|
|
33
|
+
label={'Start date'}
|
|
48
34
|
onClick={() => handleSelectedFilter(1)}
|
|
49
35
|
/>
|
|
50
36
|
<Divider />
|
|
51
37
|
<SelectButton
|
|
52
|
-
label=
|
|
38
|
+
label={'End date'}
|
|
53
39
|
onClick={() => handleSelectedFilter(2)}
|
|
54
40
|
/>
|
|
55
41
|
<Divider />
|
|
@@ -63,9 +49,13 @@ export default function FilterBar() {
|
|
|
63
49
|
</div>
|
|
64
50
|
|
|
65
51
|
{selectedFilter && (
|
|
66
|
-
<div className="
|
|
67
|
-
{selectedFilter === 1 &&
|
|
68
|
-
|
|
52
|
+
<div className="filter-bar-container">
|
|
53
|
+
{(selectedFilter === 1 || selectedFilter === 2) && (
|
|
54
|
+
<Calendar
|
|
55
|
+
calendarRange={calendarRange}
|
|
56
|
+
setCalendarRange={setCalendarRange}
|
|
57
|
+
/>
|
|
58
|
+
)}
|
|
69
59
|
{selectedFilter === 3 && (
|
|
70
60
|
<Guests
|
|
71
61
|
guestsAdults={guestsAdults}
|
|
@@ -82,87 +72,5 @@ export default function FilterBar() {
|
|
|
82
72
|
</div>
|
|
83
73
|
)}
|
|
84
74
|
</div>
|
|
85
|
-
)
|
|
75
|
+
)
|
|
86
76
|
}
|
|
87
|
-
|
|
88
|
-
const StartDate = () => {
|
|
89
|
-
return <div>Start date</div>;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const EndDate = () => {
|
|
93
|
-
return <div>End date</div>;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const Guests = ({
|
|
97
|
-
guestsAdults,
|
|
98
|
-
guestsKids,
|
|
99
|
-
decrementAdults,
|
|
100
|
-
incrementAdults,
|
|
101
|
-
decrementKids,
|
|
102
|
-
incrementKids,
|
|
103
|
-
}: any) => {
|
|
104
|
-
return (
|
|
105
|
-
<div className="search-widget-guests">
|
|
106
|
-
<h3>Guests</h3>
|
|
107
|
-
<p>Who's coming?</p>
|
|
108
|
-
|
|
109
|
-
<div className="guests-filter-container">
|
|
110
|
-
<div className="guests-filter-inner">
|
|
111
|
-
<span>Adults</span>
|
|
112
|
-
<div>
|
|
113
|
-
<button onClick={decrementAdults} disabled={guestsAdults < 1}>
|
|
114
|
-
-
|
|
115
|
-
</button>
|
|
116
|
-
<span>{guestsAdults}</span>
|
|
117
|
-
<button onClick={incrementAdults}>+</button>
|
|
118
|
-
</div>
|
|
119
|
-
</div>
|
|
120
|
-
<div className="guests-filter-inner">
|
|
121
|
-
<span>Kids</span>
|
|
122
|
-
<div>
|
|
123
|
-
<button onClick={decrementKids} disabled={guestsKids < 1}>
|
|
124
|
-
-
|
|
125
|
-
</button>
|
|
126
|
-
<span>{guestsKids}</span>
|
|
127
|
-
<button onClick={incrementKids}>+</button>
|
|
128
|
-
</div>
|
|
129
|
-
</div>
|
|
130
|
-
</div>
|
|
131
|
-
</div>
|
|
132
|
-
);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const Categories = ({ categories, setCategories }: any) => {
|
|
136
|
-
const categoriesPlaceholder = [
|
|
137
|
-
"Weekend",
|
|
138
|
-
"Week",
|
|
139
|
-
"Summer camp",
|
|
140
|
-
"Winter camp",
|
|
141
|
-
];
|
|
142
|
-
|
|
143
|
-
const [selectedCategory, setSelectedCategory] = useState("");
|
|
144
|
-
|
|
145
|
-
const handleCategoryChange = (selectedCategory: any) => {
|
|
146
|
-
setSelectedCategory(selectedCategory);
|
|
147
|
-
setCategories(selectedCategory); // Update the parent component's state with the selected category
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
return (
|
|
151
|
-
<div className="search-widget-categories">
|
|
152
|
-
<h3>CATEGORY</h3>
|
|
153
|
-
<div className="categories-filter-inner">
|
|
154
|
-
{categoriesPlaceholder.map((itm, idx) => (
|
|
155
|
-
<div key={idx}>
|
|
156
|
-
<input
|
|
157
|
-
type="radio"
|
|
158
|
-
value={itm}
|
|
159
|
-
checked={selectedCategory === itm}
|
|
160
|
-
onChange={() => handleCategoryChange(itm)}
|
|
161
|
-
/>
|
|
162
|
-
<span>{itm}</span>
|
|
163
|
-
</div>
|
|
164
|
-
))}
|
|
165
|
-
</div>
|
|
166
|
-
</div>
|
|
167
|
-
);
|
|
168
|
-
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import { addDays } from 'date-fns'
|
|
4
|
+
import { DateRange, DayPicker } from 'react-day-picker'
|
|
5
|
+
|
|
6
|
+
import 'react-day-picker/dist/style.css'
|
|
7
|
+
import './Calendar.css'
|
|
8
|
+
|
|
9
|
+
const currentMonth = new Date()
|
|
10
|
+
|
|
11
|
+
export default function Calendar({ calendarRange, setCalendarRange }: any) {
|
|
12
|
+
const defaultCalendarSelected: DateRange = {
|
|
13
|
+
from: currentMonth,
|
|
14
|
+
to: addDays(currentMonth, 0),
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!calendarRange) setCalendarRange(defaultCalendarSelected)
|
|
19
|
+
}, [])
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className="filter-bar-calendar">
|
|
23
|
+
<DayPicker
|
|
24
|
+
id="test"
|
|
25
|
+
mode="range"
|
|
26
|
+
numberOfMonths={2}
|
|
27
|
+
defaultMonth={currentMonth}
|
|
28
|
+
selected={calendarRange}
|
|
29
|
+
onSelect={setCalendarRange}
|
|
30
|
+
/>
|
|
31
|
+
</div>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.filter-bar-categories {
|
|
2
|
+
text-align: center;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.categories-filter-inner {
|
|
6
|
+
display: flex;
|
|
7
|
+
align-items: center;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
gap: 20px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.categories-filter-inner input {
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
margin-right: 10px;
|
|
15
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import './Categories.css'
|
|
3
|
+
|
|
4
|
+
export default function Categories({ categories, setCategories }: any) {
|
|
5
|
+
const categoriesPlaceholder = [
|
|
6
|
+
'Weekend',
|
|
7
|
+
'Week',
|
|
8
|
+
'Summer camp',
|
|
9
|
+
'Winter camp',
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
const [selectedCategory, setSelectedCategory] = useState('')
|
|
13
|
+
|
|
14
|
+
const handleCategoryChange = (selectedCategory: any) => {
|
|
15
|
+
setSelectedCategory(selectedCategory)
|
|
16
|
+
setCategories(selectedCategory)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div className="filter-bar-categories">
|
|
21
|
+
<h3>CATEGORY</h3>
|
|
22
|
+
<div className="categories-filter-inner">
|
|
23
|
+
{categoriesPlaceholder.map((itm, idx) => (
|
|
24
|
+
<div key={idx}>
|
|
25
|
+
<input
|
|
26
|
+
type="radio"
|
|
27
|
+
value={itm}
|
|
28
|
+
checked={selectedCategory === itm}
|
|
29
|
+
onChange={() => handleCategoryChange(itm)}
|
|
30
|
+
/>
|
|
31
|
+
<span>{itm}</span>
|
|
32
|
+
</div>
|
|
33
|
+
))}
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
.filter-bar-guests {
|
|
2
|
+
text-align: initial;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.guests-filter-container {
|
|
6
|
+
display: flex;
|
|
7
|
+
margin-top: 30px;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.guests-filter-inner {
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.guests-filter-inner:not(:last-child) {
|
|
16
|
+
margin-right: 50px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.guests-filter-inner > span {
|
|
20
|
+
display: block;
|
|
21
|
+
margin-right: 20px;
|
|
22
|
+
font-weight: bold;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.guests-filter-inner > div {
|
|
26
|
+
display: flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.guests-filter-inner > div > span {
|
|
31
|
+
margin: 0 10px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.guests-filter-inner > div button {
|
|
35
|
+
border-radius: 50%;
|
|
36
|
+
border: none;
|
|
37
|
+
background-color: #CDEEFF;
|
|
38
|
+
width: 25px;
|
|
39
|
+
height: 25px;
|
|
40
|
+
display: flex;
|
|
41
|
+
justify-content: center;
|
|
42
|
+
align-items: center;
|
|
43
|
+
font-size: 20px;
|
|
44
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
import './Guests.css'
|
|
4
|
+
|
|
5
|
+
export default function Guests({
|
|
6
|
+
guestsAdults,
|
|
7
|
+
guestsKids,
|
|
8
|
+
decrementAdults,
|
|
9
|
+
incrementAdults,
|
|
10
|
+
decrementKids,
|
|
11
|
+
incrementKids,
|
|
12
|
+
}: any) {
|
|
13
|
+
return (
|
|
14
|
+
<div className="filter-bar-guests">
|
|
15
|
+
<h3>Guests</h3>
|
|
16
|
+
<p>Who's coming?</p>
|
|
17
|
+
|
|
18
|
+
<div className="guests-filter-container">
|
|
19
|
+
<div className="guests-filter-inner">
|
|
20
|
+
<span>Adults</span>
|
|
21
|
+
<div>
|
|
22
|
+
<button onClick={decrementAdults} disabled={guestsAdults < 1}>
|
|
23
|
+
-
|
|
24
|
+
</button>
|
|
25
|
+
<span>{guestsAdults}</span>
|
|
26
|
+
<button onClick={incrementAdults}>+</button>
|
|
27
|
+
</div>
|
|
28
|
+
</div>
|
|
29
|
+
<div className="guests-filter-inner">
|
|
30
|
+
<span>Kids</span>
|
|
31
|
+
<div>
|
|
32
|
+
<button onClick={decrementKids} disabled={guestsKids < 1}>
|
|
33
|
+
-
|
|
34
|
+
</button>
|
|
35
|
+
<span>{guestsKids}</span>
|
|
36
|
+
<button onClick={incrementKids}>+</button>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import { DateRange } from 'react-day-picker'
|
|
3
|
+
import { addDays, format } from 'date-fns'
|
|
4
|
+
|
|
5
|
+
export default function useFilterBar() {
|
|
6
|
+
const [selectedFilter, setSelectedFilter] = useState<number | boolean>(false)
|
|
7
|
+
const [calendarRange, setCalendarRange] = useState<DateRange>()
|
|
8
|
+
const [guestsAdults, setGuestsAdults] = useState(1)
|
|
9
|
+
const [guestsKids, setGuestsKids] = useState(0)
|
|
10
|
+
const [categories, setCategories] = useState(0)
|
|
11
|
+
|
|
12
|
+
const handleSelectedFilter = (id: any) => {
|
|
13
|
+
setSelectedFilter(id)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const handleSubmit = () => {
|
|
17
|
+
const queryParams = new URLSearchParams()
|
|
18
|
+
|
|
19
|
+
const params = {
|
|
20
|
+
startDate: calendarRange?.from
|
|
21
|
+
? format(calendarRange.from, 'yyyy-MM-dd')
|
|
22
|
+
: '',
|
|
23
|
+
endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
|
|
24
|
+
guestsAdults,
|
|
25
|
+
guestsKids,
|
|
26
|
+
categories,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
for (const [key, value] of Object.entries(params)) {
|
|
30
|
+
if (value) {
|
|
31
|
+
queryParams.append(key, value.toString())
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const url = `http://localhost:4000/en/events/?${queryParams.toString()}`
|
|
36
|
+
window.location.href = url
|
|
37
|
+
handleSelectedFilter(false)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
selectedFilter,
|
|
42
|
+
guestsAdults,
|
|
43
|
+
guestsKids,
|
|
44
|
+
categories,
|
|
45
|
+
calendarRange,
|
|
46
|
+
setCalendarRange,
|
|
47
|
+
setSelectedFilter,
|
|
48
|
+
setGuestsAdults,
|
|
49
|
+
setGuestsKids,
|
|
50
|
+
setCategories,
|
|
51
|
+
handleSelectedFilter,
|
|
52
|
+
handleSubmit,
|
|
53
|
+
}
|
|
54
|
+
}
|