willba-component-library 0.1.6 → 0.1.11

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.
@@ -1,5 +1,14 @@
1
- type ThemeProps = {
2
- vendor?: string;
3
- };
4
- export default function useTheme({ vendor }: ThemeProps): "" | "will-root-kis" | "will-root-paj";
1
+ import { CSSProperties } from 'react';
2
+ export interface Palette {
3
+ primary: string;
4
+ secondary: string;
5
+ }
6
+ export interface ThemeProps {
7
+ palette?: Palette;
8
+ }
9
+ interface CustomPaletteTypes extends CSSProperties {
10
+ '--will-primary'?: string;
11
+ '--will-secondary'?: string;
12
+ }
13
+ export default function useTheme({ palette }: ThemeProps): CustomPaletteTypes;
5
14
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "willba-component-library",
3
- "version": "0.1.6",
3
+ "version": "0.1.11",
4
4
  "description": "A stroybook 6 with TypeScript demo",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.esm.js",
@@ -18,7 +18,7 @@
18
18
  "classnames": "^2.3.2",
19
19
  "react-day-picker": "^8.8.0",
20
20
  "react-i18next": "^13.1.2",
21
- "react-icons": "^4.10.1",
21
+ "react-icons": "^4.11.0",
22
22
  "react-responsive": "^9.0.2"
23
23
  },
24
24
  "peerDependencies": {
@@ -14,13 +14,15 @@
14
14
  .will-filter-bar-underlay {
15
15
  background-color: rgba(0,0,0,.8);
16
16
  position: absolute;
17
- top:0;
17
+ /* top:0; */
18
18
  left: 0;
19
19
  width: 100%;
20
20
  height: 100%;
21
21
  cursor: pointer;
22
22
  min-height: 200vh;
23
23
  z-index: 88888;
24
+
25
+ transform: translateY(-50%);
24
26
  }
25
27
 
26
28
  /* Header */
@@ -70,7 +72,7 @@
70
72
  .will-filter-bar-container {
71
73
  margin-top: 20px;
72
74
  padding: 30px 40px;
73
- position: initial;
75
+ position: relative;
74
76
  }
75
77
 
76
78
  .isMobileAbsolute {
@@ -14,8 +14,8 @@ type Story = StoryObj<typeof FilterBar>
14
14
 
15
15
  export const Primary: Story = {
16
16
  args: {
17
- vendor: '',
18
17
  language: '',
18
+ redirectUrl: '',
19
19
  ageCategories: [
20
20
  {
21
21
  id: '1',
@@ -39,6 +39,9 @@ export const Primary: Story = {
39
39
  minVal: 0,
40
40
  },
41
41
  ],
42
- redirectUrl: '',
42
+ palette: {
43
+ primary: '',
44
+ secondary: '',
45
+ },
43
46
  },
44
47
  }
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react'
1
+ import React, { useEffect, useState, useRef } from 'react'
2
2
  import { useTranslation } from 'react-i18next'
3
3
 
4
4
  import Divider from './components/divider/Divider'
@@ -8,39 +8,41 @@ import Calendar from './components/calendar/Calendar'
8
8
  import Guests from './components/guests/Guests'
9
9
  import Categories from './components/categories/Categories'
10
10
 
11
- import useTheme from '../../themes/useTheme'
11
+ import useTheme, { Palette } from '../../themes/useTheme'
12
12
  import useFilterBar from './hooks/useFilterBar'
13
- import { AgeCategoryType } from './FilterBarTypes'
14
13
 
15
14
  import './FilterBar.css'
16
15
  import '../../themes/Default.css'
17
16
  import i18n from '../../i18n'
18
17
  import CloseButton from './components/close-button/CloseButton'
18
+ import { AgeCategoryType } from './FilterBarTypes'
19
19
 
20
- interface FilterBarProps {
20
+ export interface FilterBarProps {
21
21
  vendor?: string
22
22
  language?: string
23
23
  ageCategories?: AgeCategoryType[]
24
24
  redirectUrl: string
25
+ palette: Palette
25
26
  }
26
27
 
27
28
  export default function FilterBar({
28
- vendor,
29
29
  language,
30
30
  ageCategories = AGE_CATEGORIES_FALLBACK,
31
31
  redirectUrl = REDIRECT_URL_FALLBACK,
32
+ palette,
32
33
  }: FilterBarProps) {
33
- const themeClass = useTheme({ vendor })
34
- const [rerenderKey, setRerenderKey] = useState(0)
34
+ const themePalette = useTheme({ palette })
35
35
 
36
+ // Translations
37
+ const [rerenderKey, setRerenderKey] = useState(0)
36
38
  useEffect(() => {
37
39
  i18n.changeLanguage(language)
38
40
 
39
41
  setRerenderKey((prevKey) => prevKey + 1)
40
42
  }, [language])
41
-
42
43
  const { t } = useTranslation('filterBar')
43
44
 
45
+ // Filters
44
46
  const {
45
47
  selectedFilter,
46
48
  ageCategoryCounts,
@@ -51,9 +53,19 @@ export default function FilterBar({
51
53
  handleSelectedFilter,
52
54
  handleSubmit,
53
55
  updateGuestsCount,
54
- handleResetFilters,
55
56
  } = useFilterBar({ redirectUrl })
56
57
 
58
+ // Scroll in to view
59
+ const targetElementRef = useRef<HTMLDivElement | null>(null)
60
+ useEffect(() => {
61
+ if (targetElementRef.current) {
62
+ targetElementRef.current.scrollIntoView({
63
+ behavior: 'smooth',
64
+ block: 'start',
65
+ })
66
+ }
67
+ }, [selectedFilter])
68
+
57
69
  return (
58
70
  <>
59
71
  {selectedFilter && (
@@ -65,11 +77,10 @@ export default function FilterBar({
65
77
  />
66
78
  )}
67
79
  <div
68
- className={`will-root ${themeClass} ${
69
- selectedFilter ? 'isMobileAbsolute' : ''
70
- }`}
80
+ className={`will-root ${selectedFilter ? 'isMobileAbsolute' : ''}`}
81
+ style={themePalette}
71
82
  >
72
- <div className="will-filter-bar-header">
83
+ <div className="will-filter-bar-header" ref={targetElementRef}>
73
84
  <SelectButton
74
85
  style={fontWigthBold(selectedFilter === 1 || selectedFilter === 2)}
75
86
  label={t('calendar.startDate')}
@@ -82,7 +93,7 @@ export default function FilterBar({
82
93
  onClick={() => handleSelectedFilter(2)}
83
94
  />
84
95
 
85
- {/* TODO - Add strapi settings to add or remove functionality */}
96
+ {/* TODO - Add strapi settings to show or hide filter sections */}
86
97
  {/* <Divider />
87
98
  <SelectButton
88
99
  label={t('guests.label')}
@@ -98,12 +109,12 @@ export default function FilterBar({
98
109
  /> */}
99
110
 
100
111
  <SubmitButton onClick={handleSubmit} />
101
-
102
- <CloseButton handleClose={handleResetFilters} />
103
112
  </div>
104
113
 
105
114
  {selectedFilter && (
106
115
  <div className="will-filter-bar-container">
116
+ <CloseButton handleClose={() => handleSelectedFilter(false)} />
117
+
107
118
  {(selectedFilter === 1 || selectedFilter === 2) && (
108
119
  <Calendar
109
120
  calendarRange={calendarRange}
@@ -1,17 +1,21 @@
1
1
  .will-filter-bar-close-button {
2
2
  width: auto;
3
3
  height: auto;
4
- background-color: var(--will-grey);
5
- color: var(--will-white);
4
+ /* background-color: var(--will-grey); */
5
+ color: var(--will-grey);
6
6
  padding: 2px 7px;
7
7
  border-radius: 50%;
8
8
  cursor: pointer;
9
9
  border: none;
10
10
  display: flex;
11
11
  align-items: center;
12
- font-size: 25px;
13
- margin-left: 15px;
12
+ font-size: 23px;
14
13
  display: none;
14
+
15
+ position: absolute;
16
+ top: 10px;
17
+ right: 10px;
18
+
15
19
  }
16
20
 
17
21
  @media (max-width: 960px) {
@@ -19,7 +23,7 @@
19
23
  min-height: 35px;
20
24
  border-radius: 25px;
21
25
  margin-left:0;
22
- margin-bottom: 25px;
26
+
23
27
  display: flex;
24
28
  justify-content: center;
25
29
  }
@@ -22,6 +22,6 @@
22
22
  @media (max-width: 960px) {
23
23
  .will-filter-bar-submit-button {
24
24
  justify-content: center;
25
- margin-bottom: 25px;
25
+ margin-bottom: 15px;
26
26
  }
27
27
  }
@@ -60,7 +60,7 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
60
60
  : '',
61
61
  endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
62
62
  categories,
63
- ageCategoryCounts: JSON.stringify(ageCategoryCounts),
63
+ //ageCategoryCounts: JSON.stringify(ageCategoryCounts),
64
64
  }
65
65
 
66
66
  for (const [key, value] of Object.entries(params)) {
@@ -13,6 +13,7 @@
13
13
 
14
14
  /* Pallete */
15
15
  --will-primary: #374269;
16
+ --will-secondary: #374269;
16
17
  --will-grey: #ABA7AF;
17
18
  --will-white: #fff;
18
19
  --will-onahau: #CDEEFF;
@@ -39,14 +40,4 @@
39
40
  .will-root p, h1, h2, h3, h4, h5, h6, span {
40
41
  margin: 0;
41
42
  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
43
  }
@@ -1,14 +1,24 @@
1
- type ThemeProps = {
2
- vendor?: string
1
+ import { CSSProperties } from 'react'
2
+
3
+ export interface Palette {
4
+ primary: string
5
+ secondary: string
6
+ }
7
+
8
+ export interface ThemeProps {
9
+ palette?: Palette
10
+ }
11
+
12
+ interface CustomPaletteTypes extends CSSProperties {
13
+ '--will-primary'?: string
14
+ '--will-secondary'?: string
3
15
  }
4
16
 
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
- : ''
17
+ export default function useTheme({ palette }: ThemeProps) {
18
+ const themePalette: CustomPaletteTypes = {
19
+ '--will-primary': palette?.primary,
20
+ '--will-secondary': palette?.secondary,
21
+ }
12
22
 
13
- return themeClass
23
+ return themePalette
14
24
  }