willba-component-library 0.1.28 → 0.1.29

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.29",
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,58 @@ 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
+ for (const [key, value] of currentSearchParams.entries()) {
111
+ updatedParams.append(key, value)
75
112
  }
76
- }
77
113
 
78
- window.location.href = `${redirectUrl}/${selectedPath}${
79
- queryParams ? `?${queryParams.toString()}` : ''
80
- }`
81
- handleSelectedFilter(false)
82
- }
114
+ for (const [key, value] of Object.entries(newParams)) {
115
+ if (value) {
116
+ updatedParams.set(key, value.toString())
117
+ } else {
118
+ updatedParams.delete(key)
119
+ }
120
+ }
83
121
 
84
- useEffect(() => {
85
- if (typeof window === 'undefined') return
122
+ console.log(currentSearchParams.toString(), updatedParams.toString())
86
123
 
87
- document.body.style.overflow =
88
- selectedFilter && window.innerWidth < 960 ? 'hidden' : 'visible'
124
+ // Get the current URL without the query string
125
+ const baseUrl = window.location.origin + window.location.pathname
89
126
 
90
- return () => {
91
- document.body.style.overflow = 'visible'
92
- }
93
- }, [selectedFilter])
127
+ // Construct the updated URL with the modified query parameters
128
+ const updatedUrl = `${baseUrl}?${updatedParams.toString()}`
94
129
 
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'
130
+ // Replace the current URL with the updated URL in the browser's history
131
+ return (window.location.href = updatedUrl)
132
+ } else {
133
+ const querySearchParams = new URLSearchParams()
103
134
 
104
- setSelectedPath(currentPath)
135
+ for (const [key, value] of Object.entries(newParams)) {
136
+ if (value) {
137
+ querySearchParams.append(key, value.toString())
138
+ }
139
+ }
140
+
141
+ return (window.location.href = `${redirectUrl}/${selectedPath}${
142
+ querySearchParams ? `?${querySearchParams.toString()}` : ''
143
+ }`)
105
144
  }
106
- }, [])
145
+
146
+ handleSelectedFilter(false)
147
+ }
107
148
 
108
149
  const handleResetFilters = () => {
109
150
  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,