willba-component-library 0.0.79 → 0.0.81

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "willba-component-library",
3
- "version": "0.0.79",
3
+ "version": "0.0.81",
4
4
  "description": "A stroybook 6 with TypeScript demo",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.esm.js",
@@ -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: 100vh;
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
- type FilterBarProps = {
19
+ interface FilterBarProps {
19
20
  vendor?: string
20
21
  language?: string
22
+ ageCategories: AgeCategoryType[]
21
23
  }
22
24
 
23
- export default function FilterBar({ vendor, language }: FilterBarProps) {
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,15 @@ export default function FilterBar({ vendor, language }: FilterBarProps) {
35
41
 
36
42
  const {
37
43
  selectedFilter,
38
- guestsAdults,
39
- guestsKids,
44
+ ageCategoryCounts,
40
45
  categories,
41
46
  calendarRange,
42
47
  setCalendarRange,
43
- setGuestsAdults,
44
- setGuestsKids,
45
48
  setCategories,
46
49
  handleSelectedFilter,
47
50
  handleSubmit,
48
- } = useFilterBar()
51
+ updateGuestsCount,
52
+ } = useFilterBar(ageCategories)
49
53
 
50
54
  return (
51
55
  <>
@@ -96,12 +100,9 @@ export default function FilterBar({ vendor, language }: FilterBarProps) {
96
100
  )}
97
101
  {selectedFilter === 3 && (
98
102
  <Guests
99
- guestsAdults={guestsAdults}
100
- guestsKids={guestsKids}
101
- decrementAdults={() => setGuestsAdults(guestsAdults - 1)}
102
- incrementAdults={() => setGuestsAdults(guestsAdults + 1)}
103
- decrementKids={() => setGuestsKids(guestsKids - 1)}
104
- incrementKids={() => setGuestsKids(guestsKids + 1)}
103
+ updateGuestsCount={updateGuestsCount}
104
+ ageCategories={ageCategories}
105
+ ageCategoryCounts={ageCategoryCounts}
105
106
  />
106
107
  )}
107
108
  {selectedFilter === 4 && (
@@ -0,0 +1,25 @@
1
+ export interface AgeCategoryCount {
2
+ [categoryId: string]: number
3
+ }
4
+
5
+ export interface AgeCategoryType {
6
+ id: string
7
+ name: string
8
+ minAge: number | null
9
+ maxAge: number | null
10
+ minVal: number
11
+ }
12
+
13
+ export interface GuestsPropsType {
14
+ ageCategories: AgeCategoryType[]
15
+ updateGuestsCount: (arg1: number, arg2: number) => void
16
+ ageCategoryCounts: AgeCategoryCount | {}
17
+ }
18
+
19
+ export interface GuestsCountPropsType {
20
+ label: string
21
+ id: number
22
+ updateGuestsCount: (arg1: number, arg2: number) => void
23
+ count: number
24
+ minVal: number
25
+ }
@@ -9,6 +9,7 @@
9
9
  font-size: 16px;
10
10
  text-transform: uppercase;
11
11
  margin: 10px 0;
12
+ text-align: left;
12
13
  }
13
14
 
14
15
  .will-calendar-filter-container {
@@ -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({ calendarRange, setCalendarRange }: any) {
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,46 @@
1
+ import React from 'react'
2
+
3
+ import { GuestsCountPropsType } from '../../../FilterBarTypes'
4
+
5
+ import './GuestCount.css'
6
+
7
+ export default function GuestCount({
8
+ label,
9
+ id,
10
+ updateGuestsCount,
11
+ count,
12
+ minVal,
13
+ }: GuestsCountPropsType) {
14
+ const handleDecrement = () => {
15
+ if (count > minVal) {
16
+ updateGuestsCount(id, count - 1)
17
+ }
18
+ }
19
+
20
+ const handleIncrement = () => {
21
+ updateGuestsCount(id, count + 1)
22
+ }
23
+
24
+ return (
25
+ <div className="will-guests-filter-inner">
26
+ <span className="will-guests-filter-label">{label}</span>
27
+ <div>
28
+ <button
29
+ className="will-guests-filter-button"
30
+ onClick={handleDecrement}
31
+ disabled={count < 2}
32
+ style={{
33
+ cursor: count < 2 ? 'initial' : 'pointer',
34
+ paddingBottom: '4px',
35
+ }}
36
+ >
37
+ -
38
+ </button>
39
+ <span className="will-guests-filter-count">{count}</span>
40
+ <button className="will-guests-filter-button" onClick={handleIncrement}>
41
+ +
42
+ </button>
43
+ </div>
44
+ </div>
45
+ )
46
+ }
@@ -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
- margin-top: 30px;
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
- .will-guests-filter-button {
53
- border-radius: 50%;
54
- border: none;
55
- background-color: var(--will-onahau);
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,16 @@
1
1
  import React from 'react'
2
2
  import { useTranslation } from 'react-i18next'
3
3
 
4
+ import GuestCount from './GuestCount/GuestCount'
5
+ import { AgeCategoryCount, GuestsPropsType } from '../../FilterBarTypes'
6
+
4
7
  import './Guests.css'
5
8
 
6
9
  export default function Guests({
7
- guestsAdults,
8
- guestsKids,
9
- decrementAdults,
10
- incrementAdults,
11
- decrementKids,
12
- incrementKids,
13
- }: any) {
10
+ ageCategories,
11
+ updateGuestsCount,
12
+ ageCategoryCounts,
13
+ }: GuestsPropsType) {
14
14
  const { t } = useTranslation('filterBar')
15
15
 
16
16
  return (
@@ -19,56 +19,19 @@ export default function Guests({
19
19
  <p className="will-guests-filter-subtitle">{t('guests.subtitle')}</p>
20
20
 
21
21
  <div className="will-guests-filter-container">
22
- <div className="will-guests-filter-inner">
23
- <span className="will-guests-filter-label">
24
- {t('guests.adultsLabel')}
25
- </span>
26
- <div>
27
- <button
28
- className="will-guests-filter-button"
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>
22
+ {ageCategories?.map((category) => (
23
+ <GuestCount
24
+ key={category.id}
25
+ id={parseInt(category.id)}
26
+ label={category.name}
27
+ minVal={category.minVal}
28
+ updateGuestsCount={updateGuestsCount}
29
+ count={
30
+ (ageCategoryCounts as AgeCategoryCount)[category.id] ||
31
+ category.minVal
32
+ }
33
+ />
34
+ ))}
72
35
  </div>
73
36
  </div>
74
37
  )
@@ -1,26 +1,36 @@
1
- import { useEffect, useMemo, useState } from 'react'
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
+ import { AgeCategoryCount } from '../FilterBarTypes'
6
+
7
+ export default function useFilterBar(ageCategories: any) {
6
8
  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)
9
+ const [calendarRange, setCalendarRange] = useState<DateRange | undefined>()
10
+
11
+ const [categories, setCategories] = useState<number>(0)
12
+
13
+ //
14
+ const [ageCategoryCounts, setAgeCategoryCounts] = useState<AgeCategoryCount>(
15
+ {}
16
+ )
17
+
18
+ const updateGuestsCount = (id: number, newCount: number) => {
19
+ setAgeCategoryCounts((prevCounts) => ({
20
+ ...prevCounts,
21
+ [id]: newCount,
22
+ }))
23
+ }
24
+
25
+ //
11
26
 
12
27
  useEffect(() => {
13
28
  const urlSearchParams = new URLSearchParams(window.location.search)
14
29
 
15
30
  const startDateParam = urlSearchParams.get('startDate')
16
31
  const endDateParam = urlSearchParams.get('endDate')
17
- const parsedGuestsAdults = parseInt(
18
- urlSearchParams.get('guestsAdults') || '1',
19
- 10
20
- )
21
- const parsedGuestsKids = parseInt(
22
- urlSearchParams.get('guestsKids') || '0',
23
- 10
32
+ const ageCategoryCountsParam = JSON.parse(
33
+ urlSearchParams.get('ageCategoryCounts') || '{}'
24
34
  )
25
35
  const parsedCategories = parseInt(
26
36
  urlSearchParams.get('categories') || '0',
@@ -33,9 +43,7 @@ export default function useFilterBar() {
33
43
  to: new Date(endDateParam),
34
44
  })
35
45
  }
36
-
37
- setGuestsAdults(parsedGuestsAdults)
38
- setGuestsKids(parsedGuestsKids)
46
+ setAgeCategoryCounts(ageCategoryCountsParam)
39
47
  setCategories(parsedCategories)
40
48
  }, [])
41
49
 
@@ -51,9 +59,8 @@ export default function useFilterBar() {
51
59
  ? format(calendarRange.from, 'yyyy-MM-dd')
52
60
  : '',
53
61
  endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
54
- guestsAdults,
55
- guestsKids,
56
62
  categories,
63
+ ageCategoryCounts: JSON.stringify(ageCategoryCounts),
57
64
  }
58
65
 
59
66
  for (const [key, value] of Object.entries(params)) {
@@ -71,22 +78,22 @@ export default function useFilterBar() {
71
78
  document.body.style.overflow = selectedFilter ? 'hidden' : 'visible'
72
79
 
73
80
  return () => {
74
- document.body.style.overflow = 'visible' // Reset overflow when component unmounts
81
+ document.body.style.overflow = 'visible'
75
82
  }
76
83
  }, [selectedFilter])
77
84
 
78
85
  return {
79
86
  selectedFilter,
80
- guestsAdults,
81
- guestsKids,
87
+ ageCategoryCounts,
82
88
  categories,
83
89
  calendarRange,
84
90
  setCalendarRange,
85
91
  setSelectedFilter,
86
- setGuestsAdults,
87
- setGuestsKids,
92
+ setAgeCategoryCounts,
88
93
  setCategories,
89
94
  handleSelectedFilter,
90
95
  handleSubmit,
96
+
97
+ updateGuestsCount,
91
98
  }
92
99
  }