willba-component-library 0.0.78 → 0.0.80
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 +5 -3
- package/lib/components/FilterBar/FilterBarTypes.d.ts +15 -0
- package/lib/components/FilterBar/components/calendar/Calendar.d.ts +7 -1
- package/lib/components/FilterBar/components/guests/GuestCount/GuestCount.d.ts +4 -0
- package/lib/components/FilterBar/components/guests/Guests.d.ts +2 -1
- package/lib/components/FilterBar/hooks/useFilterBar.d.ts +4 -5
- package/lib/index.d.ts +12 -3
- package/lib/index.esm.js +135 -84
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +134 -83
- package/lib/index.js.map +1 -1
- package/lib/index.umd.js +134 -83
- package/lib/index.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/FilterBar/FilterBar.css +3 -2
- package/src/components/FilterBar/FilterBar.stories.tsx +23 -0
- package/src/components/FilterBar/FilterBar.tsx +15 -13
- package/src/components/FilterBar/FilterBarTypes.ts +17 -0
- package/src/components/FilterBar/components/calendar/Calendar.css +1 -0
- package/src/components/FilterBar/components/calendar/Calendar.tsx +9 -1
- package/src/components/FilterBar/components/guests/GuestCount/GuestCount.css +54 -0
- package/src/components/FilterBar/components/guests/GuestCount/GuestCount.tsx +49 -0
- package/src/components/FilterBar/components/guests/Guests.css +5 -40
- package/src/components/FilterBar/components/guests/Guests.tsx +14 -58
- package/src/components/FilterBar/hooks/useFilterBar.tsx +29 -15
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
.will-root {
|
|
2
|
-
position: relative;
|
|
3
2
|
z-index: 99999;
|
|
4
3
|
width: 100%;
|
|
4
|
+
max-height: calc(100vh - 56px);
|
|
5
|
+
position: relative;
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
.will-filter-bar {
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
width: 100%;
|
|
18
19
|
height: 100%;
|
|
19
20
|
cursor: pointer;
|
|
20
|
-
min-height:
|
|
21
|
+
min-height: 200vh;
|
|
21
22
|
z-index: 88888;
|
|
22
23
|
}
|
|
23
24
|
|
|
@@ -16,5 +16,28 @@ export const Primary: Story = {
|
|
|
16
16
|
args: {
|
|
17
17
|
vendor: '',
|
|
18
18
|
language: '',
|
|
19
|
+
ageCategories: [
|
|
20
|
+
{
|
|
21
|
+
id: '1',
|
|
22
|
+
name: 'Alle 6 vuotiaat',
|
|
23
|
+
minAge: null,
|
|
24
|
+
maxAge: 6,
|
|
25
|
+
minVal: 1,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: '2',
|
|
29
|
+
name: '6-16 vuotiaat',
|
|
30
|
+
minAge: 6,
|
|
31
|
+
maxAge: 17,
|
|
32
|
+
minVal: 0,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: '3',
|
|
36
|
+
name: 'Aikuiset',
|
|
37
|
+
minAge: 17,
|
|
38
|
+
maxAge: null,
|
|
39
|
+
minVal: 0,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
19
42
|
},
|
|
20
43
|
}
|
|
@@ -10,17 +10,23 @@ import Categories from './components/categories/Categories'
|
|
|
10
10
|
|
|
11
11
|
import useTheme from '../../themes/useTheme'
|
|
12
12
|
import useFilterBar from './hooks/useFilterBar'
|
|
13
|
+
import { AgeCategoryType } from './FilterBarTypes'
|
|
13
14
|
|
|
14
15
|
import './FilterBar.css'
|
|
15
16
|
import '../../themes/Default.css'
|
|
16
17
|
import i18n from '../../i18n'
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
interface FilterBarProps {
|
|
19
20
|
vendor?: string
|
|
20
21
|
language?: string
|
|
22
|
+
ageCategories: AgeCategoryType[]
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
export default function FilterBar({
|
|
25
|
+
export default function FilterBar({
|
|
26
|
+
vendor,
|
|
27
|
+
language,
|
|
28
|
+
ageCategories,
|
|
29
|
+
}: FilterBarProps) {
|
|
24
30
|
const themeClass = useTheme({ vendor })
|
|
25
31
|
const [rerenderKey, setRerenderKey] = useState(0)
|
|
26
32
|
|
|
@@ -35,17 +41,17 @@ export default function FilterBar({ vendor, language }: FilterBarProps) {
|
|
|
35
41
|
|
|
36
42
|
const {
|
|
37
43
|
selectedFilter,
|
|
38
|
-
|
|
39
|
-
guestsKids,
|
|
44
|
+
ageCategoryCounts,
|
|
40
45
|
categories,
|
|
41
46
|
calendarRange,
|
|
42
47
|
setCalendarRange,
|
|
43
|
-
|
|
44
|
-
setGuestsKids,
|
|
48
|
+
setAgeCategoryCounts,
|
|
45
49
|
setCategories,
|
|
46
50
|
handleSelectedFilter,
|
|
47
51
|
handleSubmit,
|
|
48
|
-
|
|
52
|
+
|
|
53
|
+
updateGuestsCount,
|
|
54
|
+
} = useFilterBar(ageCategories)
|
|
49
55
|
|
|
50
56
|
return (
|
|
51
57
|
<>
|
|
@@ -96,12 +102,8 @@ export default function FilterBar({ vendor, language }: FilterBarProps) {
|
|
|
96
102
|
)}
|
|
97
103
|
{selectedFilter === 3 && (
|
|
98
104
|
<Guests
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
decrementAdults={() => setGuestsAdults(guestsAdults - 1)}
|
|
102
|
-
incrementAdults={() => setGuestsAdults(guestsAdults + 1)}
|
|
103
|
-
decrementKids={() => setGuestsKids(guestsKids - 1)}
|
|
104
|
-
incrementKids={() => setGuestsKids(guestsKids + 1)}
|
|
105
|
+
updateGuestsCount={updateGuestsCount}
|
|
106
|
+
ageCategories={ageCategories}
|
|
105
107
|
/>
|
|
106
108
|
)}
|
|
107
109
|
{selectedFilter === 4 && (
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface AgeCategoryType {
|
|
2
|
+
id: string
|
|
3
|
+
name: string
|
|
4
|
+
minAge: number | null
|
|
5
|
+
maxAge: number | null
|
|
6
|
+
maxVal: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface GuestsPropsType {
|
|
10
|
+
ageCategories: AgeCategoryType[]
|
|
11
|
+
updateGuestsCount: (arg1: string, arg2: number) => void
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface GuestsCountPropsType {
|
|
15
|
+
label: string
|
|
16
|
+
updateGuestsCount: (arg1: string, arg2: number) => void
|
|
17
|
+
}
|
|
@@ -7,9 +7,17 @@ import { useMediaQuery } from 'react-responsive'
|
|
|
7
7
|
import 'react-day-picker/dist/style.css'
|
|
8
8
|
import './Calendar.css'
|
|
9
9
|
|
|
10
|
+
interface CalendarPropsType {
|
|
11
|
+
calendarRange: DateRange | undefined
|
|
12
|
+
setCalendarRange: (range: DateRange | undefined) => void
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
const currentMonth = new Date()
|
|
11
16
|
|
|
12
|
-
export default function Calendar({
|
|
17
|
+
export default function Calendar({
|
|
18
|
+
calendarRange,
|
|
19
|
+
setCalendarRange,
|
|
20
|
+
}: CalendarPropsType) {
|
|
13
21
|
const { t } = useTranslation('filterBar')
|
|
14
22
|
const isTablet = useMediaQuery({ maxWidth: 1024 })
|
|
15
23
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
.will-guests-filter-label, .will-guests-filter-count {
|
|
2
|
+
font-size: 18px;
|
|
3
|
+
color: var(--will-text)
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.will-guests-filter-inner {
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.will-guests-filter-inner {
|
|
12
|
+
margin-top: 30px;
|
|
13
|
+
margin-right: 50px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.will-guests-filter-label {
|
|
17
|
+
display: block;
|
|
18
|
+
margin-right: 20px;
|
|
19
|
+
font-weight: bold;
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.will-guests-filter-inner > div {
|
|
24
|
+
display: flex;
|
|
25
|
+
align-items: center;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.will-guests-filter-count {
|
|
29
|
+
margin: 0 10px;
|
|
30
|
+
min-width: 30px;
|
|
31
|
+
text-align: center;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.will-guests-filter-button {
|
|
35
|
+
border-radius: 50%;
|
|
36
|
+
border: none;
|
|
37
|
+
background-color: var(--will-onahau);
|
|
38
|
+
width: 25px;
|
|
39
|
+
height: 25px;
|
|
40
|
+
display: flex;
|
|
41
|
+
justify-content: center;
|
|
42
|
+
align-items: center;
|
|
43
|
+
font-size: 20px;
|
|
44
|
+
cursor: pointer;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@media (max-width: 1024px) {
|
|
48
|
+
|
|
49
|
+
.will-guests-filter-inner {
|
|
50
|
+
width: 100%;
|
|
51
|
+
margin: 15px 0;
|
|
52
|
+
justify-content: space-between;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import { useTranslation } from 'react-i18next'
|
|
3
|
+
|
|
4
|
+
import { GuestsCountPropsType } from '../../../FilterBarTypes'
|
|
5
|
+
|
|
6
|
+
import './GuestCount.css'
|
|
7
|
+
|
|
8
|
+
export default function GuestCount({
|
|
9
|
+
label,
|
|
10
|
+
updateGuestsCount,
|
|
11
|
+
}: GuestsCountPropsType) {
|
|
12
|
+
const { t } = useTranslation('filterBar')
|
|
13
|
+
|
|
14
|
+
const [count, setCount] = useState(0)
|
|
15
|
+
|
|
16
|
+
const handleDecrement = () => {
|
|
17
|
+
if (count > 0) {
|
|
18
|
+
setCount(count - 1)
|
|
19
|
+
updateGuestsCount(label, count - 1)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const handleIncrement = () => {
|
|
24
|
+
setCount(count + 1)
|
|
25
|
+
updateGuestsCount(label, count + 1)
|
|
26
|
+
}
|
|
27
|
+
return (
|
|
28
|
+
<div className="will-guests-filter-inner">
|
|
29
|
+
<span className="will-guests-filter-label">{label}</span>
|
|
30
|
+
<div>
|
|
31
|
+
<button
|
|
32
|
+
className="will-guests-filter-button"
|
|
33
|
+
onClick={handleDecrement}
|
|
34
|
+
disabled={count < 2}
|
|
35
|
+
style={{
|
|
36
|
+
cursor: count < 2 ? 'initial' : 'pointer',
|
|
37
|
+
paddingBottom: '4px',
|
|
38
|
+
}}
|
|
39
|
+
>
|
|
40
|
+
-
|
|
41
|
+
</button>
|
|
42
|
+
<span className="will-guests-filter-count">{count}</span>
|
|
43
|
+
<button className="will-guests-filter-button" onClick={handleIncrement}>
|
|
44
|
+
+
|
|
45
|
+
</button>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
@@ -15,49 +15,14 @@
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
.will-guests-filter-label, .will-guests-filter-count {
|
|
19
|
-
font-size: 18px;
|
|
20
|
-
color: var(--will-text)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
18
|
.will-guests-filter-container {
|
|
24
19
|
display: flex;
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.will-guests-filter-inner {
|
|
29
|
-
display: flex;
|
|
30
|
-
align-items: center;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.will-guests-filter-inner:not(:last-child) {
|
|
34
|
-
margin-right: 50px;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.will-guests-filter-label {
|
|
38
|
-
display: block;
|
|
39
|
-
margin-right: 20px;
|
|
40
|
-
font-weight: bold;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.will-guests-filter-inner > div {
|
|
44
|
-
display: flex;
|
|
45
|
-
align-items: center;
|
|
20
|
+
flex-wrap: wrap;
|
|
46
21
|
}
|
|
47
22
|
|
|
48
|
-
.will-guests-filter-count {
|
|
49
|
-
margin: 0 15px;
|
|
50
|
-
}
|
|
51
23
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
width: 25px;
|
|
57
|
-
height: 25px;
|
|
58
|
-
display: flex;
|
|
59
|
-
justify-content: center;
|
|
60
|
-
align-items: center;
|
|
61
|
-
font-size: 20px;
|
|
62
|
-
cursor: pointer;
|
|
24
|
+
@media (max-width: 1024px) {
|
|
25
|
+
.will-guests-filter-container {
|
|
26
|
+
margin-top: 15px;
|
|
27
|
+
}
|
|
63
28
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
2
|
import { useTranslation } from 'react-i18next'
|
|
3
3
|
|
|
4
|
+
import GuestCount from './GuestCount/GuestCount'
|
|
5
|
+
import { GuestsPropsType } from '../../FilterBarTypes'
|
|
6
|
+
|
|
4
7
|
import './Guests.css'
|
|
5
8
|
|
|
6
9
|
export default function Guests({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
incrementAdults,
|
|
11
|
-
decrementKids,
|
|
12
|
-
incrementKids,
|
|
13
|
-
}: any) {
|
|
10
|
+
ageCategories,
|
|
11
|
+
updateGuestsCount,
|
|
12
|
+
}: GuestsPropsType) {
|
|
14
13
|
const { t } = useTranslation('filterBar')
|
|
15
14
|
|
|
16
15
|
return (
|
|
@@ -19,56 +18,13 @@ export default function Guests({
|
|
|
19
18
|
<p className="will-guests-filter-subtitle">{t('guests.subtitle')}</p>
|
|
20
19
|
|
|
21
20
|
<div className="will-guests-filter-container">
|
|
22
|
-
|
|
23
|
-
<
|
|
24
|
-
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
onClick={decrementAdults}
|
|
30
|
-
disabled={guestsAdults < 2}
|
|
31
|
-
style={{
|
|
32
|
-
cursor: guestsAdults < 2 ? 'initial' : 'pointer',
|
|
33
|
-
paddingBottom: '4px',
|
|
34
|
-
}}
|
|
35
|
-
>
|
|
36
|
-
-
|
|
37
|
-
</button>
|
|
38
|
-
<span className="will-guests-filter-count">{guestsAdults}</span>
|
|
39
|
-
<button
|
|
40
|
-
className="will-guests-filter-button"
|
|
41
|
-
onClick={incrementAdults}
|
|
42
|
-
>
|
|
43
|
-
+
|
|
44
|
-
</button>
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
<div className="will-guests-filter-inner">
|
|
48
|
-
<span className="will-guests-filter-label">
|
|
49
|
-
{t('guests.kidsLabel')}
|
|
50
|
-
</span>
|
|
51
|
-
<div>
|
|
52
|
-
<button
|
|
53
|
-
className="will-guests-filter-button"
|
|
54
|
-
onClick={decrementKids}
|
|
55
|
-
disabled={guestsKids < 1}
|
|
56
|
-
style={{
|
|
57
|
-
cursor: guestsKids < 1 ? 'initial' : 'pointer',
|
|
58
|
-
paddingBottom: '4px',
|
|
59
|
-
}}
|
|
60
|
-
>
|
|
61
|
-
-
|
|
62
|
-
</button>
|
|
63
|
-
<span className="will-guests-filter-count">{guestsKids}</span>
|
|
64
|
-
<button
|
|
65
|
-
className="will-guests-filter-button"
|
|
66
|
-
onClick={incrementKids}
|
|
67
|
-
>
|
|
68
|
-
+
|
|
69
|
-
</button>
|
|
70
|
-
</div>
|
|
71
|
-
</div>
|
|
21
|
+
{ageCategories?.map((category) => (
|
|
22
|
+
<GuestCount
|
|
23
|
+
key={category.id}
|
|
24
|
+
label={category.name}
|
|
25
|
+
updateGuestsCount={updateGuestsCount}
|
|
26
|
+
/>
|
|
27
|
+
))}
|
|
72
28
|
</div>
|
|
73
29
|
</div>
|
|
74
30
|
)
|
|
@@ -1,13 +1,24 @@
|
|
|
1
|
-
import { useEffect,
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
2
|
import { DateRange } from 'react-day-picker'
|
|
3
3
|
import { format } from 'date-fns'
|
|
4
4
|
|
|
5
|
-
export default function useFilterBar() {
|
|
5
|
+
export default function useFilterBar(ageCategories: any) {
|
|
6
6
|
const [selectedFilter, setSelectedFilter] = useState<number | boolean>(false)
|
|
7
|
-
const [calendarRange, setCalendarRange] = useState<DateRange>()
|
|
8
|
-
|
|
9
|
-
const [
|
|
10
|
-
|
|
7
|
+
const [calendarRange, setCalendarRange] = useState<DateRange | undefined>()
|
|
8
|
+
|
|
9
|
+
const [categories, setCategories] = useState<number>(0)
|
|
10
|
+
|
|
11
|
+
//
|
|
12
|
+
const [ageCategoryCounts, setAgeCategoryCounts] = useState({})
|
|
13
|
+
|
|
14
|
+
const updateGuestsCount = (label: string, newCount: number) => {
|
|
15
|
+
setAgeCategoryCounts((prevCounts) => ({
|
|
16
|
+
...prevCounts,
|
|
17
|
+
[label]: newCount,
|
|
18
|
+
}))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//
|
|
11
22
|
|
|
12
23
|
useEffect(() => {
|
|
13
24
|
const urlSearchParams = new URLSearchParams(window.location.search)
|
|
@@ -34,8 +45,8 @@ export default function useFilterBar() {
|
|
|
34
45
|
})
|
|
35
46
|
}
|
|
36
47
|
|
|
37
|
-
setGuestsAdults(parsedGuestsAdults)
|
|
38
|
-
setGuestsKids(parsedGuestsKids)
|
|
48
|
+
// setGuestsAdults(parsedGuestsAdults)
|
|
49
|
+
// setGuestsKids(parsedGuestsKids)
|
|
39
50
|
setCategories(parsedCategories)
|
|
40
51
|
}, [])
|
|
41
52
|
|
|
@@ -51,9 +62,8 @@ export default function useFilterBar() {
|
|
|
51
62
|
? format(calendarRange.from, 'yyyy-MM-dd')
|
|
52
63
|
: '',
|
|
53
64
|
endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
|
|
54
|
-
guestsAdults,
|
|
55
|
-
guestsKids,
|
|
56
65
|
categories,
|
|
66
|
+
ageCategoryCounts: JSON.stringify(ageCategoryCounts),
|
|
57
67
|
}
|
|
58
68
|
|
|
59
69
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -67,22 +77,26 @@ export default function useFilterBar() {
|
|
|
67
77
|
handleSelectedFilter(false)
|
|
68
78
|
}
|
|
69
79
|
|
|
70
|
-
|
|
80
|
+
useEffect(() => {
|
|
71
81
|
document.body.style.overflow = selectedFilter ? 'hidden' : 'visible'
|
|
82
|
+
|
|
83
|
+
return () => {
|
|
84
|
+
document.body.style.overflow = 'visible'
|
|
85
|
+
}
|
|
72
86
|
}, [selectedFilter])
|
|
73
87
|
|
|
74
88
|
return {
|
|
75
89
|
selectedFilter,
|
|
76
|
-
|
|
77
|
-
guestsKids,
|
|
90
|
+
ageCategoryCounts,
|
|
78
91
|
categories,
|
|
79
92
|
calendarRange,
|
|
80
93
|
setCalendarRange,
|
|
81
94
|
setSelectedFilter,
|
|
82
|
-
|
|
83
|
-
setGuestsKids,
|
|
95
|
+
setAgeCategoryCounts,
|
|
84
96
|
setCategories,
|
|
85
97
|
handleSelectedFilter,
|
|
86
98
|
handleSubmit,
|
|
99
|
+
|
|
100
|
+
updateGuestsCount,
|
|
87
101
|
}
|
|
88
102
|
}
|