willba-component-library 0.1.75 → 0.1.77

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.75",
3
+ "version": "0.1.77",
4
4
  "description": "A stroybook 6 with TypeScript demo",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib/index.esm.js",
@@ -46,10 +46,28 @@ export const Primary: Story = {
46
46
  primary: '',
47
47
  secondary: '',
48
48
  },
49
- currentViewApply: 'roomFilters',
50
49
  mode: 'dark',
51
50
  defaultTab: '/rooms',
52
- //tabs: ['/rooms', '/events'], -> TODO - show only available tabs -> also related to "currentViewApply"
51
+ tabs: [
52
+ {
53
+ path: '/rooms',
54
+ default: true,
55
+ order: 2,
56
+ label: {
57
+ en: 'Rooms',
58
+ fi: 'Rooms fi',
59
+ },
60
+ },
61
+ {
62
+ path: '/events',
63
+ default: false,
64
+ order: 1,
65
+ label: {
66
+ en: 'Events',
67
+ fi: 'Events fi',
68
+ },
69
+ },
70
+ ],
53
71
  },
54
72
  render: (args) => (
55
73
  <div style={{ background: 'white', padding: '30px', height: '100vh' }}>
@@ -11,7 +11,7 @@ import {
11
11
  FilterSections,
12
12
  Filters,
13
13
  Pages,
14
- ViewApply,
14
+ Tab,
15
15
  } from './FilterBarTypes'
16
16
  import {
17
17
  useCloseFilterSection,
@@ -37,12 +37,12 @@ export type FilterBarProps = {
37
37
  ageCategories?: AgeCategoryType[]
38
38
  redirectUrl?: string
39
39
  palette?: Palette
40
- currentViewApply?: string
41
40
  onSubmit?: ((val: Filters) => void) | null
42
41
  fullWidth?: boolean
43
42
  calendarOffset?: CalendarOffset
44
43
  mode?: string
45
44
  defaultTab?: string
45
+ tabs?: Tab[]
46
46
  }
47
47
 
48
48
  export default function FilterBar({
@@ -50,12 +50,11 @@ export default function FilterBar({
50
50
  ageCategories = AGE_CATEGORIES_FALLBACK,
51
51
  redirectUrl = REDIRECT_URL_FALLBACK,
52
52
  palette,
53
- currentViewApply,
54
53
  onSubmit,
55
54
  fullWidth,
56
55
  calendarOffset,
57
56
  mode,
58
- defaultTab,
57
+ tabs,
59
58
  }: FilterBarProps) {
60
59
  const themePalette = useTheme({ palette })
61
60
 
@@ -79,19 +78,11 @@ export default function FilterBar({
79
78
  handleResetFilters,
80
79
  } = useFilterBar({
81
80
  redirectUrl,
82
- currentViewApply,
83
81
  ageCategories,
84
82
  onSubmit,
85
- defaultTab,
83
+ tabs,
86
84
  })
87
85
 
88
- // Default selected tab when tabs are hidden
89
- useEffect(() => {
90
- if (currentViewApply === ViewApply.ROOMS) {
91
- setSelectedPath(Pages.ROOMS)
92
- }
93
- }, [])
94
-
95
86
  // Scroll in to view
96
87
  const { isMobile, targetFilterBarRef } = useScrollInToView({ selectedFilter })
97
88
 
@@ -124,33 +115,31 @@ export default function FilterBar({
124
115
  className={`will-root ${fullWidth ? 'is-full-width' : ''}`}
125
116
  style={themePalette}
126
117
  >
127
- {!currentViewApply && (
128
- <div
129
- className="will-filter-bar-tabs"
130
- ref={!currentViewApply ? targetFilterBarRef : null}
131
- >
132
- <TabButton
133
- label={t('tabs.events')}
134
- onClick={() => {
135
- setSelectedPath(Pages.EVENTS), handleResetFilters()
136
- }}
137
- active={selectedPath === Pages.EVENTS}
138
- mode={mode}
139
- />
140
- <TabButton
141
- label={t('tabs.rooms')}
142
- onClick={() => {
143
- setSelectedPath(Pages.ROOMS), handleResetFilters()
144
- }}
145
- active={selectedPath === Pages.ROOMS}
146
- mode={mode}
147
- />
118
+ {tabs && tabs.length > 1 && (
119
+ <div className="will-filter-bar-tabs" ref={targetFilterBarRef}>
120
+ {tabs
121
+ .sort((a, b) => a.order - b.order)
122
+ .map((tab, idx) => (
123
+ <TabButton
124
+ key={`tab-${idx}`}
125
+ label={
126
+ tab.label && language
127
+ ? tab.label[language]
128
+ : t(`tabs.${tab.path.substring(1)}`)
129
+ }
130
+ onClick={() => {
131
+ setSelectedPath(tab.path), handleResetFilters()
132
+ }}
133
+ active={selectedPath === tab.path}
134
+ mode={mode}
135
+ />
136
+ ))}
148
137
  </div>
149
138
  )}
150
139
 
151
140
  <div
152
141
  className={`will-filter-bar-header ${mode || 'dark'}`}
153
- ref={currentViewApply ? targetFilterBarRef : null}
142
+ ref={tabs?.length === 1 ? targetFilterBarRef : null}
154
143
  >
155
144
  <SelectButton
156
145
  label={t('calendar.label')}
@@ -184,7 +173,7 @@ export default function FilterBar({
184
173
  {selectedFilter && (
185
174
  <div
186
175
  className={`will-filter-bar-container ${mode || 'dark'}`}
187
- style={currentViewApply && !isMobile ? { top: 66 } : {}}
176
+ style={tabs && tabs.length === 1 && !isMobile ? { top: 66 } : {}}
188
177
  >
189
178
  <CloseButton handleClose={() => handleSelectedFilter(false)} />
190
179
 
@@ -26,10 +26,6 @@ export enum FilterSections {
26
26
 
27
27
  export type Filters = { [key: string]: string }
28
28
 
29
- export enum ViewApply {
30
- ROOMS = 'roomFilters',
31
- }
32
-
33
29
  export enum Pages {
34
30
  ROOMS = '/rooms',
35
31
  EVENTS = '/events',
@@ -38,3 +34,16 @@ export enum Pages {
38
34
  export type CalendarOffset = {
39
35
  [key: string]: number
40
36
  }
37
+
38
+ type Translations = {
39
+ en: string
40
+ fi: string
41
+ [key: string]: string
42
+ }
43
+
44
+ export type Tab = {
45
+ path: string
46
+ default?: boolean
47
+ order: number
48
+ label?: Translations
49
+ }
@@ -37,7 +37,6 @@
37
37
  .will-calendar-filter-container .rdp-month .rdp-nav {
38
38
  border: 1px solid var(--will-primary);
39
39
  border-radius: 50%;
40
- left: 25;
41
40
  }
42
41
 
43
42
  .will-calendar-filter-container .rdp-month .rdp-nav svg {
@@ -7,24 +7,23 @@ import {
7
7
  AgeCategoryType,
8
8
  Filters,
9
9
  Pages,
10
+ Tab,
10
11
  } from '../FilterBarTypes'
11
12
 
12
13
  type Props = {
13
14
  redirectUrl?: string
14
- currentViewApply?: string
15
15
  ageCategories?: AgeCategoryType[]
16
16
  onSubmit?: ((val: Filters) => void) | null
17
- defaultTab?: string
17
+ tabs?: Tab[]
18
18
  }
19
19
 
20
20
  export const useFilterBar = ({
21
21
  redirectUrl,
22
- currentViewApply,
23
22
  ageCategories,
24
23
  onSubmit,
25
- defaultTab,
24
+ tabs,
26
25
  }: Props) => {
27
- const [selectedPath, setSelectedPath] = useState(Pages.EVENTS)
26
+ const [selectedPath, setSelectedPath] = useState<string>(Pages.EVENTS)
28
27
  const [selectedFilter, setSelectedFilter] = useState<string | boolean>(false)
29
28
  const [calendarRange, setCalendarRange] = useState<DateRange | undefined>()
30
29
 
@@ -71,12 +70,14 @@ export const useFilterBar = ({
71
70
  useEffect(() => {
72
71
  // Handle default selected tab
73
72
  if (typeof window === 'undefined') return
73
+ const defaultTab =
74
+ tabs?.length === 1 ? tabs[0] : tabs?.find((tab) => tab.default)
74
75
 
75
76
  const currentPath =
76
- defaultTab === Pages.EVENTS ||
77
+ defaultTab?.path === Pages.EVENTS ||
77
78
  window.location.pathname.includes(Pages.EVENTS)
78
79
  ? Pages.EVENTS
79
- : defaultTab === Pages.ROOMS ||
80
+ : defaultTab?.path === Pages.ROOMS ||
80
81
  window.location.pathname.includes(Pages.ROOMS)
81
82
  ? Pages.ROOMS
82
83
  : Pages.EVENTS
@@ -108,7 +109,7 @@ export const useFilterBar = ({
108
109
  }),
109
110
  }
110
111
 
111
- if (currentViewApply) {
112
+ if (tabs?.length === 1) {
112
113
  const currentSearchParams = new URLSearchParams(window.location.search)
113
114
  const updatedParams = new URLSearchParams()
114
115