willba-component-library 0.1.27 → 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.27",
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,34 +46,6 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
49
46
  setCategories(parsedCategories)
50
47
  }, [])
51
48
 
52
- const handleSelectedFilter = (id: number | boolean) => {
53
- setSelectedFilter(id)
54
- }
55
-
56
- const handleSubmit = () => {
57
- const queryParams = new URLSearchParams()
58
-
59
- const params = {
60
- startDate: calendarRange?.from
61
- ? format(calendarRange.from, 'yyyy-MM-dd')
62
- : '',
63
- endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
64
- categories,
65
- ageCategoryCounts: JSON.stringify(ageCategoryCounts),
66
- }
67
-
68
- for (const [key, value] of Object.entries(params)) {
69
- if (value) {
70
- queryParams.append(key, value.toString())
71
- }
72
- }
73
-
74
- window.location.href = `${redirectUrl}/${selectedPath}${
75
- queryParams ? `?${queryParams.toString()}` : ''
76
- }`
77
- handleSelectedFilter(false)
78
- }
79
-
80
49
  useEffect(() => {
81
50
  if (typeof window === 'undefined') return
82
51
 
@@ -101,6 +70,82 @@ export default function useFilterBar({ redirectUrl }: UseFilterBarPropsType) {
101
70
  }
102
71
  }, [])
103
72
 
73
+ const updateGuestsCount = (id: string, newCount: number) => {
74
+ setAgeCategoryCounts((prevCounts) => ({
75
+ ...prevCounts,
76
+ [id]: newCount,
77
+ }))
78
+ }
79
+
80
+ const handleSelectedFilter = (id: number | boolean) => {
81
+ setSelectedFilter(id)
82
+ }
83
+
84
+ const handleSubmit = () => {
85
+ const newParams = {
86
+ startDate: calendarRange?.from
87
+ ? format(calendarRange.from, 'yyyy-MM-dd')
88
+ : '',
89
+ endDate: calendarRange?.to ? format(calendarRange.to, 'yyyy-MM-dd') : '',
90
+ categories,
91
+ ageCategoryCounts: Object.entries(ageCategoryCounts).length
92
+ ? JSON.stringify(ageCategoryCounts)
93
+ : '',
94
+ }
95
+
96
+ // const getQueryParams = () => {
97
+ // const currentSearchParams = new URLSearchParams(window.location.search)
98
+
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)
112
+ }
113
+
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
+ }
121
+
122
+ console.log(currentSearchParams.toString(), updatedParams.toString())
123
+
124
+ // Get the current URL without the query string
125
+ const baseUrl = window.location.origin + window.location.pathname
126
+
127
+ // Construct the updated URL with the modified query parameters
128
+ const updatedUrl = `${baseUrl}?${updatedParams.toString()}`
129
+
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()
134
+
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
+ }`)
144
+ }
145
+
146
+ handleSelectedFilter(false)
147
+ }
148
+
104
149
  const handleResetFilters = () => {
105
150
  setAgeCategoryCounts({})
106
151
  handleSubmit()
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,