willba-component-library 0.1.28 → 0.1.30

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.1.28",
3
+ "version": "0.1.30",
4
4
  "description": "A stroybook 6 with TypeScript demo",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.esm.js",
@@ -43,7 +43,8 @@
43
43
  position: relative;
44
44
  z-index: 222;
45
45
  border-radius: 40px;
46
- background-color: var(--will-white);
46
+ background-color: var(--will-white);
47
+ box-shadow: 0px 3px 10px 0px lightgrey;
47
48
  }
48
49
 
49
50
  @media (max-width: 960px) {
@@ -40,6 +40,7 @@ export const Primary: Story = {
40
40
  primary: '',
41
41
  secondary: '',
42
42
  },
43
+ currentViewApply: 'roomFilters',
43
44
  },
44
45
  render: (args) => (
45
46
  <div style={{ background: 'grey', padding: '30px', height: '100vh' }}>
@@ -23,8 +23,9 @@ export interface FilterBarProps {
23
23
  vendor?: string
24
24
  language?: string
25
25
  ageCategories?: AgeCategoryType[]
26
- redirectUrl: string
26
+ redirectUrl?: string
27
27
  palette?: Palette
28
+ currentViewApply?: string
28
29
  }
29
30
 
30
31
  export default function FilterBar({
@@ -32,11 +33,14 @@ export default function FilterBar({
32
33
  ageCategories = AGE_CATEGORIES_FALLBACK,
33
34
  redirectUrl = REDIRECT_URL_FALLBACK,
34
35
  palette,
36
+ currentViewApply,
35
37
  }: FilterBarProps) {
36
38
  const themePalette = useTheme({ palette })
37
39
 
38
40
  // Translations
39
41
  const [rerenderKey, setRerenderKey] = useState(0)
42
+ const [isMobile, setIsMobile] = useState(true)
43
+
40
44
  useEffect(() => {
41
45
  i18n.changeLanguage(language)
42
46
 
@@ -58,13 +62,20 @@ export default function FilterBar({
58
62
  handleSubmit,
59
63
  updateGuestsCount,
60
64
  setSelectedPath,
61
- } = useFilterBar({ redirectUrl })
65
+ } = useFilterBar({ redirectUrl, currentViewApply })
62
66
 
63
67
  // Scroll in to view
64
68
 
65
69
  const targetFilterBarRef = useRef<HTMLDivElement | null>(null)
66
70
  useEffect(() => {
67
- if (window !== undefined && window.innerWidth > 960) return
71
+ if (currentViewApply === 'roomFilters') {
72
+ setSelectedPath('/rooms')
73
+ }
74
+
75
+ if (window !== undefined && window.innerWidth > 960) {
76
+ setIsMobile(false)
77
+ return
78
+ }
68
79
  if (targetFilterBarRef.current && selectedFilter) {
69
80
  window.scrollTo({
70
81
  behavior: 'smooth',
@@ -91,18 +102,20 @@ export default function FilterBar({
91
102
  className={`will-root ${selectedFilter ? 'isMobileAbsolute' : ''}`}
92
103
  style={themePalette}
93
104
  >
94
- <div className="will-filter-bar-tabs" ref={targetFilterBarRef}>
95
- <TabButton
96
- label={t('tabs.events')}
97
- onClick={() => setSelectedPath('/events')}
98
- active={selectedPath === '/events'}
99
- />
100
- <TabButton
101
- label={t('tabs.rooms')}
102
- onClick={() => setSelectedPath('/rooms')}
103
- active={selectedPath === '/rooms'}
104
- />
105
- </div>
105
+ {!currentViewApply && (
106
+ <div className="will-filter-bar-tabs" ref={targetFilterBarRef}>
107
+ <TabButton
108
+ label={t('tabs.events')}
109
+ onClick={() => setSelectedPath('/events')}
110
+ active={selectedPath === '/events'}
111
+ />
112
+ <TabButton
113
+ label={t('tabs.rooms')}
114
+ onClick={() => setSelectedPath('/rooms')}
115
+ active={selectedPath === '/rooms'}
116
+ />
117
+ </div>
118
+ )}
106
119
 
107
120
  <div className="will-filter-bar-header">
108
121
  <SelectButton
@@ -129,7 +142,10 @@ export default function FilterBar({
129
142
  </div>
130
143
 
131
144
  {selectedFilter && (
132
- <div className="will-filter-bar-container">
145
+ <div
146
+ className="will-filter-bar-container"
147
+ style={currentViewApply && !isMobile ? { top: 66 } : {}}
148
+ >
133
149
  <CloseButton handleClose={() => handleSelectedFilter(false)} />
134
150
 
135
151
  {selectedFilter === 1 && (
@@ -17,6 +17,7 @@
17
17
  .will-guests-filter-container {
18
18
  display: flex;
19
19
  flex-direction: column;
20
+ min-width: 400px;
20
21
  }
21
22
 
22
23
 
@@ -27,5 +28,6 @@
27
28
 
28
29
  .will-guests-filter-container {
29
30
  margin-top: 15px;
31
+ min-width: 100%;
30
32
  }
31
33
  }
@@ -5,10 +5,14 @@ import { format } from 'date-fns'
5
5
  import { AgeCategoryCount } from '../FilterBarTypes'
6
6
 
7
7
  interface UseFilterBarPropsType {
8
- redirectUrl: string
8
+ redirectUrl?: string
9
+ currentViewApply?: string
9
10
  }
10
11
 
11
- export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
12
+ export default function useFilterBar({
13
+ redirectUrl,
14
+ currentViewApply,
15
+ }: UseFilterBarPropsType) {
12
16
  const [selectedPath, setSelectedPath] = useState('/events')
13
17
 
14
18
  const [selectedFilter, setSelectedFilter] = useState<number | boolean>(false)
@@ -19,13 +23,6 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
19
23
  {}
20
24
  )
21
25
 
22
- const updateGuestsCount = (id: string, newCount: number) => {
23
- setAgeCategoryCounts((prevCounts) => ({
24
- ...prevCounts,
25
- [id]: newCount,
26
- }))
27
- }
28
-
29
26
  useEffect(() => {
30
27
  const urlSearchParams = new URLSearchParams(window.location.search)
31
28
 
@@ -49,14 +46,43 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
49
46
  setCategories(parsedCategories)
50
47
  }, [])
51
48
 
49
+ useEffect(() => {
50
+ if (typeof window === 'undefined') return
51
+
52
+ document.body.style.overflow =
53
+ selectedFilter && window.innerWidth < 960 ? 'hidden' : 'visible'
54
+
55
+ return () => {
56
+ document.body.style.overflow = 'visible'
57
+ }
58
+ }, [selectedFilter])
59
+
60
+ useEffect(() => {
61
+ if (typeof window !== 'undefined') {
62
+ // Handle default selected tab
63
+ const currentPath = window.location.pathname.includes('/events')
64
+ ? '/events'
65
+ : window.location.pathname.includes('/rooms')
66
+ ? '/rooms'
67
+ : '/events'
68
+
69
+ setSelectedPath(currentPath)
70
+ }
71
+ }, [])
72
+
73
+ const updateGuestsCount = (id: string, newCount: number) => {
74
+ setAgeCategoryCounts((prevCounts) => ({
75
+ ...prevCounts,
76
+ [id]: newCount,
77
+ }))
78
+ }
79
+
52
80
  const handleSelectedFilter = (id: number | boolean) => {
53
81
  setSelectedFilter(id)
54
82
  }
55
83
 
56
84
  const handleSubmit = () => {
57
- const queryParams = new URLSearchParams()
58
-
59
- const params = {
85
+ const newParams = {
60
86
  startDate: calendarRange?.from
61
87
  ? format(calendarRange.from, 'yyyy-MM-dd')
62
88
  : '',
@@ -67,43 +93,60 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
67
93
  : '',
68
94
  }
69
95
 
70
- console.log(params)
96
+ // const getQueryParams = () => {
97
+ // const currentSearchParams = new URLSearchParams(window.location.search)
71
98
 
72
- for (const [key, value] of Object.entries(params)) {
73
- if (value) {
74
- queryParams.append(key, value.toString())
99
+ // const params: { [key: string]: string } = {}
100
+ // for (const [key, value] of currentSearchParams.entries()) {
101
+ // params[key] = value
102
+ // }
103
+ // return params
104
+ // }
105
+
106
+ if (currentViewApply) {
107
+ const currentSearchParams = new URLSearchParams(window.location.search)
108
+ const updatedParams = new URLSearchParams()
109
+
110
+ // Copy existing parameters to updatedParams
111
+ for (const [key, value] of currentSearchParams.entries()) {
112
+ updatedParams.append(key, value)
75
113
  }
76
- }
77
114
 
78
- window.location.href = `${redirectUrl}/${selectedPath}${
79
- queryParams ? `?${queryParams.toString()}` : ''
80
- }`
81
- handleSelectedFilter(false)
82
- }
115
+ // Update parameters based on newParams
116
+ for (const [key, value] of Object.entries(newParams)) {
117
+ if (value) {
118
+ console.log(value)
119
+ updatedParams.set(key, value.toString())
120
+ } else {
121
+ // Remove parameter if value is falsy
122
+ updatedParams.delete(key)
123
+ }
124
+ }
83
125
 
84
- useEffect(() => {
85
- if (typeof window === 'undefined') return
126
+ console.log(updatedParams.toString())
86
127
 
87
- document.body.style.overflow =
88
- selectedFilter && window.innerWidth < 960 ? 'hidden' : 'visible'
128
+ const baseUrl = window.location.origin + window.location.pathname
89
129
 
90
- return () => {
91
- document.body.style.overflow = 'visible'
92
- }
93
- }, [selectedFilter])
130
+ // Construct the updated URL with the modified query parameters
131
+ const updatedUrl = `${baseUrl}?${updatedParams.toString()}`
94
132
 
95
- useEffect(() => {
96
- if (typeof window !== 'undefined') {
97
- // Handle default selected tab
98
- const currentPath = window.location.pathname.includes('/events')
99
- ? '/events'
100
- : window.location.pathname.includes('/rooms')
101
- ? '/rooms'
102
- : '/events'
133
+ return (window.location.href = updatedUrl)
134
+ } else {
135
+ const querySearchParams = new URLSearchParams()
103
136
 
104
- setSelectedPath(currentPath)
137
+ for (const [key, value] of Object.entries(newParams)) {
138
+ if (value) {
139
+ querySearchParams.append(key, value.toString())
140
+ }
141
+ }
142
+
143
+ return (window.location.href = `${redirectUrl}/${selectedPath}${
144
+ querySearchParams ? `?${querySearchParams.toString()}` : ''
145
+ }`)
105
146
  }
106
- }, [])
147
+
148
+ handleSelectedFilter(false)
149
+ }
107
150
 
108
151
  const handleResetFilters = () => {
109
152
  setAgeCategoryCounts({})
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "es5",
4
+ "downlevelIteration": true,
4
5
  "outDir": "lib",
5
6
  "lib": ["dom", "dom.iterable", "esnext"],
6
7
  "declaration": true,