willba-component-library 0.1.4 → 0.1.6

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.
Files changed (32) hide show
  1. package/README.md +57 -57
  2. package/lib/index.esm.js +9 -11
  3. package/lib/index.esm.js.map +1 -1
  4. package/lib/index.js +9 -11
  5. package/lib/index.js.map +1 -1
  6. package/lib/index.umd.js +9 -11
  7. package/lib/index.umd.js.map +1 -1
  8. package/package.json +51 -51
  9. package/src/components/FilterBar/FilterBar.tsx +4 -3
  10. package/src/components/FilterBar/FilterBarTypes.ts +25 -25
  11. package/src/components/FilterBar/components/calendar/Calendar.css +76 -76
  12. package/src/components/FilterBar/components/calendar/Calendar.tsx +54 -54
  13. package/src/components/FilterBar/components/categories/Categories.css +21 -21
  14. package/src/components/FilterBar/components/categories/Categories.tsx +41 -41
  15. package/src/components/FilterBar/components/close-button/CloseButton.css +26 -26
  16. package/src/components/FilterBar/components/close-button/CloseButton.tsx +16 -16
  17. package/src/components/FilterBar/components/divider/Divider.css +14 -14
  18. package/src/components/FilterBar/components/divider/Divider.tsx +7 -7
  19. package/src/components/FilterBar/components/guests/GuestCount/GuestCount.css +53 -53
  20. package/src/components/FilterBar/components/guests/GuestCount/GuestCount.tsx +51 -51
  21. package/src/components/FilterBar/components/guests/Guests.css +27 -27
  22. package/src/components/FilterBar/components/guests/Guests.tsx +38 -38
  23. package/src/components/FilterBar/components/select-button/SelectButton.css +20 -20
  24. package/src/components/FilterBar/components/select-button/SelectButton.tsx +15 -15
  25. package/src/components/FilterBar/components/submit-button/SubmitButton.css +27 -27
  26. package/src/components/FilterBar/components/submit-button/SubmitButton.tsx +18 -18
  27. package/src/components/FilterBar/hooks/useFilterBar.tsx +106 -106
  28. package/src/i18n.ts +25 -25
  29. package/src/locales/en/filterBar.json +20 -20
  30. package/src/locales/fi/filterBar.json +20 -20
  31. package/src/themes/Default.css +51 -51
  32. package/src/themes/useTheme.tsx +14 -14
@@ -1,106 +1,106 @@
1
- import { useEffect, useState } from 'react'
2
- import { DateRange } from 'react-day-picker'
3
- import { format } from 'date-fns'
4
-
5
- import { AgeCategoryCount, AgeCategoryType } from '../FilterBarTypes'
6
-
7
- interface UseFilterBarPropsType {
8
- redirectUrl: string
9
- }
10
-
11
- export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
12
- const [selectedFilter, setSelectedFilter] = useState<number | boolean>(false)
13
- const [calendarRange, setCalendarRange] = useState<DateRange | undefined>()
14
-
15
- const [categories, setCategories] = useState<number>(0)
16
- const [ageCategoryCounts, setAgeCategoryCounts] = useState<AgeCategoryCount>(
17
- {}
18
- )
19
-
20
- const updateGuestsCount = (id: number, newCount: number) => {
21
- setAgeCategoryCounts((prevCounts) => ({
22
- ...prevCounts,
23
- [id]: newCount,
24
- }))
25
- }
26
-
27
- useEffect(() => {
28
- const urlSearchParams = new URLSearchParams(window.location.search)
29
-
30
- const startDateParam = urlSearchParams.get('startDate')
31
- const endDateParam = urlSearchParams.get('endDate')
32
- const ageCategoryCountsParam = JSON.parse(
33
- urlSearchParams.get('ageCategoryCounts') || '{}'
34
- )
35
- const parsedCategories = parseInt(
36
- urlSearchParams.get('categories') || '0',
37
- 10
38
- )
39
-
40
- if (startDateParam && endDateParam) {
41
- setCalendarRange({
42
- from: new Date(startDateParam),
43
- to: new Date(endDateParam),
44
- })
45
- }
46
- setAgeCategoryCounts(ageCategoryCountsParam)
47
- setCategories(parsedCategories)
48
- }, [])
49
-
50
- const handleSelectedFilter = (id: number | boolean) => {
51
- setSelectedFilter(id)
52
- }
53
-
54
- const handleSubmit = () => {
55
- const queryParams = new URLSearchParams()
56
-
57
- const params = {
58
- startDate: calendarRange?.from
59
- ? format(calendarRange.from, 'yyyy-MM-dd')
60
- : '',
61
- endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
62
- categories,
63
- ageCategoryCounts: JSON.stringify(ageCategoryCounts),
64
- }
65
-
66
- for (const [key, value] of Object.entries(params)) {
67
- if (value) {
68
- queryParams.append(key, value.toString())
69
- }
70
- }
71
-
72
- window.location.href = `${redirectUrl}${
73
- queryParams ? `?${queryParams.toString()}` : ''
74
- }`
75
- handleSelectedFilter(false)
76
- }
77
-
78
- useEffect(() => {
79
- document.body.style.overflow = selectedFilter ? 'hidden' : 'visible'
80
-
81
- return () => {
82
- document.body.style.overflow = 'visible'
83
- }
84
- }, [selectedFilter])
85
-
86
- const handleResetFilters = () => {
87
- setAgeCategoryCounts({})
88
- handleSubmit()
89
- setSelectedFilter(false)
90
- }
91
-
92
- return {
93
- selectedFilter,
94
- ageCategoryCounts,
95
- categories,
96
- calendarRange,
97
- setCalendarRange,
98
- setSelectedFilter,
99
- setAgeCategoryCounts,
100
- setCategories,
101
- handleSelectedFilter,
102
- handleSubmit,
103
- updateGuestsCount,
104
- handleResetFilters,
105
- }
106
- }
1
+ import { useEffect, useState } from 'react'
2
+ import { DateRange } from 'react-day-picker'
3
+ import { format } from 'date-fns'
4
+
5
+ import { AgeCategoryCount, AgeCategoryType } from '../FilterBarTypes'
6
+
7
+ interface UseFilterBarPropsType {
8
+ redirectUrl: string
9
+ }
10
+
11
+ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
12
+ const [selectedFilter, setSelectedFilter] = useState<number | boolean>(false)
13
+ const [calendarRange, setCalendarRange] = useState<DateRange | undefined>()
14
+
15
+ const [categories, setCategories] = useState<number>(0)
16
+ const [ageCategoryCounts, setAgeCategoryCounts] = useState<AgeCategoryCount>(
17
+ {}
18
+ )
19
+
20
+ const updateGuestsCount = (id: number, newCount: number) => {
21
+ setAgeCategoryCounts((prevCounts) => ({
22
+ ...prevCounts,
23
+ [id]: newCount,
24
+ }))
25
+ }
26
+
27
+ useEffect(() => {
28
+ const urlSearchParams = new URLSearchParams(window.location.search)
29
+
30
+ const startDateParam = urlSearchParams.get('startDate')
31
+ const endDateParam = urlSearchParams.get('endDate')
32
+ const ageCategoryCountsParam = JSON.parse(
33
+ urlSearchParams.get('ageCategoryCounts') || '{}'
34
+ )
35
+ const parsedCategories = parseInt(
36
+ urlSearchParams.get('categories') || '0',
37
+ 10
38
+ )
39
+
40
+ if (startDateParam && endDateParam) {
41
+ setCalendarRange({
42
+ from: new Date(startDateParam),
43
+ to: new Date(endDateParam),
44
+ })
45
+ }
46
+ setAgeCategoryCounts(ageCategoryCountsParam)
47
+ setCategories(parsedCategories)
48
+ }, [])
49
+
50
+ const handleSelectedFilter = (id: number | boolean) => {
51
+ setSelectedFilter(id)
52
+ }
53
+
54
+ const handleSubmit = () => {
55
+ const queryParams = new URLSearchParams()
56
+
57
+ const params = {
58
+ startDate: calendarRange?.from
59
+ ? format(calendarRange.from, 'yyyy-MM-dd')
60
+ : '',
61
+ endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
62
+ categories,
63
+ ageCategoryCounts: JSON.stringify(ageCategoryCounts),
64
+ }
65
+
66
+ for (const [key, value] of Object.entries(params)) {
67
+ if (value) {
68
+ queryParams.append(key, value.toString())
69
+ }
70
+ }
71
+
72
+ window.location.href = `${redirectUrl}${
73
+ queryParams ? `?${queryParams.toString()}` : ''
74
+ }`
75
+ handleSelectedFilter(false)
76
+ }
77
+
78
+ useEffect(() => {
79
+ document.body.style.overflow = selectedFilter ? 'hidden' : 'visible'
80
+
81
+ return () => {
82
+ document.body.style.overflow = 'visible'
83
+ }
84
+ }, [selectedFilter])
85
+
86
+ const handleResetFilters = () => {
87
+ setAgeCategoryCounts({})
88
+ handleSubmit()
89
+ setSelectedFilter(false)
90
+ }
91
+
92
+ return {
93
+ selectedFilter,
94
+ ageCategoryCounts,
95
+ categories,
96
+ calendarRange,
97
+ setCalendarRange,
98
+ setSelectedFilter,
99
+ setAgeCategoryCounts,
100
+ setCategories,
101
+ handleSelectedFilter,
102
+ handleSubmit,
103
+ updateGuestsCount,
104
+ handleResetFilters,
105
+ }
106
+ }
package/src/i18n.ts CHANGED
@@ -1,25 +1,25 @@
1
- import i18n from 'i18next'
2
- import { initReactI18next } from 'react-i18next'
3
-
4
- import enFilterBar from './locales/en/filterBar.json'
5
- import fiFilterBar from './locales/fi/filterBar.json'
6
-
7
- const urlParams =
8
- typeof window !== 'undefined'
9
- ? new URLSearchParams(window.location.search)
10
- : null
11
- const localeFromUrl = urlParams?.get('locale') || 'fi'
12
-
13
- i18n.use(initReactI18next).init({
14
- resources: {
15
- en: { filterBar: enFilterBar },
16
- fi: { filterBar: fiFilterBar },
17
- },
18
- lng: localeFromUrl,
19
- fallbackLng: 'fi',
20
- interpolation: {
21
- escapeValue: false,
22
- },
23
- })
24
-
25
- export default i18n
1
+ import i18n from 'i18next'
2
+ import { initReactI18next } from 'react-i18next'
3
+
4
+ import enFilterBar from './locales/en/filterBar.json'
5
+ import fiFilterBar from './locales/fi/filterBar.json'
6
+
7
+ const urlParams =
8
+ typeof window !== 'undefined'
9
+ ? new URLSearchParams(window.location.search)
10
+ : null
11
+ const localeFromUrl = urlParams?.get('locale') || 'fi'
12
+
13
+ i18n.use(initReactI18next).init({
14
+ resources: {
15
+ en: { filterBar: enFilterBar },
16
+ fi: { filterBar: fiFilterBar },
17
+ },
18
+ lng: localeFromUrl,
19
+ fallbackLng: 'fi',
20
+ interpolation: {
21
+ escapeValue: false,
22
+ },
23
+ })
24
+
25
+ export default i18n
@@ -1,21 +1,21 @@
1
- {
2
- "calendar": {
3
- "startDate": "Start date",
4
- "endDate": "End date",
5
- "title": "Calendar"
6
- },
7
- "guests": {
8
- "label": "Guests",
9
- "title": "Guests",
10
- "subtitle": "Who's coming?",
11
- "adultsLabel": "Adults",
12
- "kidsLabel": "kids"
13
- },
14
- "categories": {
15
- "label": "Categories",
16
- "title": "Category"
17
- },
18
- "submit": {
19
- "label": "Search"
20
- }
1
+ {
2
+ "calendar": {
3
+ "startDate": "Start date",
4
+ "endDate": "End date",
5
+ "title": "Calendar"
6
+ },
7
+ "guests": {
8
+ "label": "Guests",
9
+ "title": "Guests",
10
+ "subtitle": "Who's coming?",
11
+ "adultsLabel": "Adults",
12
+ "kidsLabel": "kids"
13
+ },
14
+ "categories": {
15
+ "label": "Categories",
16
+ "title": "Category"
17
+ },
18
+ "submit": {
19
+ "label": "Search"
20
+ }
21
21
  }
@@ -1,21 +1,21 @@
1
- {
2
- "calendar": {
3
- "startDate": "Aloitus päivämäärä",
4
- "endDate": "Päättymis päivämäärä",
5
- "title": "Kalenteri"
6
- },
7
- "guests": {
8
- "label": "Vieraat",
9
- "title": "Vieraat",
10
- "subtitle": "Kuka saapuu?",
11
- "adultsLabel": "Aikuiset",
12
- "kidsLabel": "lapset"
13
- },
14
- "categories": {
15
- "label": "Kategoriat",
16
- "title": "Kategoria"
17
- },
18
- "submit": {
19
- "label": "Hae"
20
- }
1
+ {
2
+ "calendar": {
3
+ "startDate": "Aloitus päivämäärä",
4
+ "endDate": "Päättymis päivämäärä",
5
+ "title": "Kalenteri"
6
+ },
7
+ "guests": {
8
+ "label": "Vieraat",
9
+ "title": "Vieraat",
10
+ "subtitle": "Kuka saapuu?",
11
+ "adultsLabel": "Aikuiset",
12
+ "kidsLabel": "lapset"
13
+ },
14
+ "categories": {
15
+ "label": "Kategoriat",
16
+ "title": "Kategoria"
17
+ },
18
+ "submit": {
19
+ "label": "Hae"
20
+ }
21
21
  }
@@ -1,52 +1,52 @@
1
- @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap');
2
-
3
- .will-root * {
4
- font-family: 'Montserrat', sans-serif;
5
- }
6
-
7
- .will-root {
8
-
9
- box-sizing: border-box;
10
- font-size: 14px;
11
-
12
- color: #1E1E1E;
13
-
14
- /* Pallete */
15
- --will-primary: #374269;
16
- --will-grey: #ABA7AF;
17
- --will-white: #fff;
18
- --will-onahau: #CDEEFF;
19
- --will-text: #5A5959;
20
-
21
- /* Confines */
22
- --will-box-shadow: 0px 6px 11px 0px #a7a4a480;
23
-
24
- /* Breakpoints */
25
-
26
- --will-lg: 1140px;
27
- --will-md: 960px;
28
- --will-sm: 600px;
29
- --will-xl: 1280px;
30
- --will-xs: 0px;
31
- }
32
-
33
- /* Typography */
34
-
35
- .will-root h1, h2, h3, h4, h5, h6 {
36
- font-weight: 700;
37
- }
38
-
39
- .will-root p, h1, h2, h3, h4, h5, h6, span {
40
- margin: 0;
41
- padding: 0;
42
- }
43
-
44
- /* Overrides as themes */
45
-
46
- .will-root-kis {
47
- --will-primary: #374269;
48
- }
49
-
50
- .will-root-paj {
51
- --will-primary: #1897D8;
1
+ @import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap');
2
+
3
+ .will-root * {
4
+ font-family: 'Montserrat', sans-serif;
5
+ }
6
+
7
+ .will-root {
8
+
9
+ box-sizing: border-box;
10
+ font-size: 14px;
11
+
12
+ color: #1E1E1E;
13
+
14
+ /* Pallete */
15
+ --will-primary: #374269;
16
+ --will-grey: #ABA7AF;
17
+ --will-white: #fff;
18
+ --will-onahau: #CDEEFF;
19
+ --will-text: #5A5959;
20
+
21
+ /* Confines */
22
+ --will-box-shadow: 0px 6px 11px 0px #a7a4a480;
23
+
24
+ /* Breakpoints */
25
+
26
+ --will-lg: 1140px;
27
+ --will-md: 960px;
28
+ --will-sm: 600px;
29
+ --will-xl: 1280px;
30
+ --will-xs: 0px;
31
+ }
32
+
33
+ /* Typography */
34
+
35
+ .will-root h1, h2, h3, h4, h5, h6 {
36
+ font-weight: 700;
37
+ }
38
+
39
+ .will-root p, h1, h2, h3, h4, h5, h6, span {
40
+ margin: 0;
41
+ padding: 0;
42
+ }
43
+
44
+ /* Overrides as themes */
45
+
46
+ .will-root-kis {
47
+ --will-primary: #374269;
48
+ }
49
+
50
+ .will-root-paj {
51
+ --will-primary: #1897D8;
52
52
  }
@@ -1,14 +1,14 @@
1
- type ThemeProps = {
2
- vendor?: string
3
- }
4
-
5
- export default function useTheme({ vendor }: ThemeProps) {
6
- const themeClass =
7
- vendor === 'Kisakallio'
8
- ? 'will-root-kis'
9
- : vendor === 'Pajulahti'
10
- ? 'will-root-paj'
11
- : ''
12
-
13
- return themeClass
14
- }
1
+ type ThemeProps = {
2
+ vendor?: string
3
+ }
4
+
5
+ export default function useTheme({ vendor }: ThemeProps) {
6
+ const themeClass =
7
+ vendor === 'Kisakallio'
8
+ ? 'will-root-kis'
9
+ : vendor === 'Pajulahti'
10
+ ? 'will-root-paj'
11
+ : ''
12
+
13
+ return themeClass
14
+ }