willba-component-library 0.1.13 → 0.1.15

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 (64) hide show
  1. package/.nvmrc +1 -1
  2. package/.storybook/main.ts +19 -19
  3. package/.storybook/preview.ts +15 -15
  4. package/README.md +57 -57
  5. package/lib/index.esm.js +13 -13
  6. package/lib/index.esm.js.map +1 -1
  7. package/lib/index.js +13 -13
  8. package/lib/index.js.map +1 -1
  9. package/lib/index.umd.js +13 -13
  10. package/lib/index.umd.js.map +1 -1
  11. package/package.json +51 -51
  12. package/prettier.config.js +6 -6
  13. package/rollup.config.mjs +61 -61
  14. package/src/components/Button/Button.stories.tsx +34 -34
  15. package/src/components/Button/Button.tsx +56 -56
  16. package/src/components/Button/button.css +29 -29
  17. package/src/components/Button/index.ts +1 -1
  18. package/src/components/FilterBar/FilterBar.css +83 -83
  19. package/src/components/FilterBar/FilterBar.stories.tsx +47 -47
  20. package/src/components/FilterBar/FilterBar.tsx +180 -180
  21. package/src/components/FilterBar/FilterBarTypes.ts +25 -25
  22. package/src/components/FilterBar/components/buttons/close-button/CloseButton.css +33 -33
  23. package/src/components/FilterBar/components/buttons/close-button/CloseButton.tsx +16 -16
  24. package/src/components/FilterBar/components/buttons/select-button/SelectButton.css +36 -36
  25. package/src/components/FilterBar/components/buttons/select-button/SelectButton.tsx +24 -24
  26. package/src/components/FilterBar/components/buttons/submit-button/SubmitButton.css +27 -27
  27. package/src/components/FilterBar/components/buttons/submit-button/SubmitButton.tsx +18 -18
  28. package/src/components/FilterBar/components/calendar/Calendar.css +76 -76
  29. package/src/components/FilterBar/components/calendar/Calendar.tsx +52 -52
  30. package/src/components/FilterBar/components/categories/Categories.css +21 -21
  31. package/src/components/FilterBar/components/categories/Categories.tsx +41 -41
  32. package/src/components/FilterBar/components/divider/Divider.css +14 -14
  33. package/src/components/FilterBar/components/divider/Divider.tsx +7 -7
  34. package/src/components/FilterBar/components/guests/GuestCount/GuestCount.css +53 -53
  35. package/src/components/FilterBar/components/guests/GuestCount/GuestCount.tsx +51 -51
  36. package/src/components/FilterBar/components/guests/Guests.css +27 -27
  37. package/src/components/FilterBar/components/guests/Guests.tsx +38 -38
  38. package/src/components/FilterBar/hooks/useFilterBar.tsx +106 -106
  39. package/src/components/FilterBar/index.ts +1 -1
  40. package/src/i18n.ts +25 -25
  41. package/src/index.ts +4 -4
  42. package/src/locales/en/filterBar.json +20 -20
  43. package/src/locales/fi/filterBar.json +20 -20
  44. package/src/themes/Default.css +42 -42
  45. package/src/themes/useTheme.tsx +24 -24
  46. package/stories/Button.stories.ts +50 -50
  47. package/stories/Button.tsx +48 -48
  48. package/stories/Configure.mdx +364 -364
  49. package/stories/Header.stories.ts +27 -27
  50. package/stories/Header.tsx +56 -56
  51. package/stories/Page.stories.ts +29 -29
  52. package/stories/Page.tsx +73 -73
  53. package/stories/assets/accessibility.svg +4 -4
  54. package/stories/assets/discord.svg +15 -15
  55. package/stories/assets/github.svg +3 -3
  56. package/stories/assets/tutorials.svg +12 -12
  57. package/stories/assets/youtube.svg +4 -4
  58. package/stories/button.css +30 -30
  59. package/stories/header.css +32 -32
  60. package/stories/page.css +69 -69
  61. package/tsconfig.json +27 -27
  62. package/lib/components/FilterBar/components/close-button/CloseButton.d.ts +0 -7
  63. package/lib/components/FilterBar/components/select-button/SelectButton.d.ts +0 -3
  64. package/lib/components/FilterBar/components/submit-button/SubmitButton.d.ts +0 -3
@@ -1,51 +1,51 @@
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={minVal && count < 2 ? true : false}
32
- style={{
33
- cursor:
34
- minVal && count < 2
35
- ? 'initial'
36
- : !minVal && count < 1
37
- ? 'initial'
38
- : 'pointer',
39
- paddingBottom: '4px',
40
- }}
41
- >
42
- -
43
- </button>
44
- <span className="will-guests-filter-count">{count}</span>
45
- <button className="will-guests-filter-button" onClick={handleIncrement}>
46
- +
47
- </button>
48
- </div>
49
- </div>
50
- )
51
- }
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={minVal && count < 2 ? true : false}
32
+ style={{
33
+ cursor:
34
+ minVal && count < 2
35
+ ? 'initial'
36
+ : !minVal && count < 1
37
+ ? 'initial'
38
+ : 'pointer',
39
+ paddingBottom: '4px',
40
+ }}
41
+ >
42
+ -
43
+ </button>
44
+ <span className="will-guests-filter-count">{count}</span>
45
+ <button className="will-guests-filter-button" onClick={handleIncrement}>
46
+ +
47
+ </button>
48
+ </div>
49
+ </div>
50
+ )
51
+ }
@@ -1,28 +1,28 @@
1
- .will-filter-bar-guests {
2
- text-align: initial;
3
- }
4
-
5
- .will-guests-filter-title {
6
- font-size: 16px;
7
- text-transform: uppercase;
8
- margin: 10px 0;
9
- }
10
-
11
- .will-guests-filter-subtitle {
12
- font-size: 15px;
13
- font-weight: 500;
14
- color:var(--will-text)
15
- }
16
-
17
-
18
- .will-guests-filter-container {
19
- display: flex;
20
- flex-wrap: wrap;
21
- }
22
-
23
-
24
- @media (max-width: 960px) {
25
- .will-guests-filter-container {
26
- margin-top: 15px;
27
- }
1
+ .will-filter-bar-guests {
2
+ text-align: initial;
3
+ }
4
+
5
+ .will-guests-filter-title {
6
+ font-size: 16px;
7
+ text-transform: uppercase;
8
+ margin: 10px 0;
9
+ }
10
+
11
+ .will-guests-filter-subtitle {
12
+ font-size: 15px;
13
+ font-weight: 500;
14
+ color:var(--will-text)
15
+ }
16
+
17
+
18
+ .will-guests-filter-container {
19
+ display: flex;
20
+ flex-wrap: wrap;
21
+ }
22
+
23
+
24
+ @media (max-width: 960px) {
25
+ .will-guests-filter-container {
26
+ margin-top: 15px;
27
+ }
28
28
  }
@@ -1,38 +1,38 @@
1
- import React from 'react'
2
- import { useTranslation } from 'react-i18next'
3
-
4
- import GuestCount from './GuestCount/GuestCount'
5
- import { AgeCategoryCount, GuestsPropsType } from '../../FilterBarTypes'
6
-
7
- import './Guests.css'
8
-
9
- export default function Guests({
10
- ageCategories,
11
- updateGuestsCount,
12
- ageCategoryCounts,
13
- }: GuestsPropsType) {
14
- const { t } = useTranslation('filterBar')
15
-
16
- return (
17
- <div className="will-filter-bar-guests">
18
- <h3 className="will-guests-filter-title">{t('guests.title')}</h3>
19
- <p className="will-guests-filter-subtitle">{t('guests.subtitle')}</p>
20
-
21
- <div className="will-guests-filter-container">
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
- ))}
35
- </div>
36
- </div>
37
- )
38
- }
1
+ import React from 'react'
2
+ import { useTranslation } from 'react-i18next'
3
+
4
+ import GuestCount from './GuestCount/GuestCount'
5
+ import { AgeCategoryCount, GuestsPropsType } from '../../FilterBarTypes'
6
+
7
+ import './Guests.css'
8
+
9
+ export default function Guests({
10
+ ageCategories,
11
+ updateGuestsCount,
12
+ ageCategoryCounts,
13
+ }: GuestsPropsType) {
14
+ const { t } = useTranslation('filterBar')
15
+
16
+ return (
17
+ <div className="will-filter-bar-guests">
18
+ <h3 className="will-guests-filter-title">{t('guests.title')}</h3>
19
+ <p className="will-guests-filter-subtitle">{t('guests.subtitle')}</p>
20
+
21
+ <div className="will-guests-filter-container">
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
+ ))}
35
+ </div>
36
+ </div>
37
+ )
38
+ }
@@ -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
+ }
@@ -1 +1 @@
1
- export { default } from "./FilterBar";
1
+ export { default } from "./FilterBar";
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
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- import Button from './components/Button'
2
- import FilterBar from './components/FilterBar'
3
-
4
- export { Button, FilterBar }
1
+ import Button from './components/Button'
2
+ import FilterBar from './components/FilterBar'
3
+
4
+ export { Button, FilterBar }
@@ -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
  }