goobs-frontend 0.8.13 → 0.8.15

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,445 +0,0 @@
1
- 'use client'
2
- import React, { useState, useCallback } from 'react'
3
- import {
4
- Drawer,
5
- Box,
6
- Stack,
7
- Divider,
8
- MenuItem,
9
- Accordion as MuiAccordion,
10
- AccordionSummary,
11
- AccordionDetails,
12
- List,
13
- } from '@mui/material'
14
- import SearchableDropdown from '../../SearchableDropdown'
15
- import ExpandMoreIcon from '@mui/icons-material/ExpandMore'
16
- import Link from 'next/link'
17
- import { useRouter } from 'next/navigation'
18
- import { NavProps, SubNav, View } from '../index'
19
- import { white, ocean, semiTransparentWhite } from '../../../styles/palette'
20
- import { Typography } from './../../Typography'
21
-
22
- export interface VerticalVariantProps {
23
- items: (NavProps | SubNav | View)[]
24
- showSearchableNav: boolean
25
- showTitle: boolean
26
- showLine: boolean
27
- verticalNavTitle: string
28
- searchableNavLabel: string
29
- anchor: 'left' | 'right'
30
- expandedNavs: string[]
31
- setExpandedNavs: React.Dispatch<React.SetStateAction<string[]>>
32
- expandedSubnavs: string[]
33
- setExpandedSubnavs: React.Dispatch<React.SetStateAction<string[]>>
34
- verticalNavWidth: string
35
- backgroundcolor?: string
36
- shrunkfontcolor?: string
37
- unshrunkfontcolor?: string
38
- titleUrl?: string
39
- mobileOpen?: boolean
40
- onClose?: () => void
41
- variant?: 'temporary' | 'permanent'
42
- spacingfromtopofscreen?: string
43
- }
44
-
45
- function VerticalVariant({
46
- items,
47
- showSearchableNav,
48
- showTitle,
49
- showLine,
50
- verticalNavTitle,
51
- searchableNavLabel,
52
- anchor,
53
- expandedNavs,
54
- setExpandedNavs,
55
- expandedSubnavs,
56
- setExpandedSubnavs,
57
- verticalNavWidth,
58
- backgroundcolor,
59
- shrunkfontcolor = white.main,
60
- unshrunkfontcolor = white.main,
61
- titleUrl = '/',
62
- mobileOpen = false,
63
- onClose,
64
- variant = 'permanent',
65
- spacingfromtopofscreen = '0px',
66
- }: VerticalVariantProps) {
67
- const router = useRouter()
68
- const [selectedNav, setSelectedNav] = useState<string | null>(null)
69
-
70
- const navOptions = items
71
- .filter((item): item is NavProps => 'title' in item && 'subnavs' in item)
72
- .map(nav => ({ value: nav.title ?? '' }))
73
-
74
- const handleNavClick = useCallback(
75
- (nav: NavProps) => {
76
- console.log('Clicked Nav:', nav.title)
77
- if (nav.trigger === 'route') {
78
- if (nav.route) {
79
- router.push(nav.route)
80
- if (variant === 'temporary' && onClose) {
81
- onClose()
82
- }
83
- }
84
- } else if (nav.trigger === 'onClick') {
85
- if (nav.onClick) {
86
- nav.onClick()
87
- if (variant === 'temporary' && onClose) {
88
- onClose()
89
- }
90
- }
91
- }
92
- },
93
- [router, variant, onClose]
94
- )
95
-
96
- const handleSearchableNavChange = useCallback(
97
- (newValue: { value: string } | null) => {
98
- const newVal = newValue ? newValue.value : null
99
- setSelectedNav(newVal)
100
- console.log('SearchableNav selection changed to:', newVal)
101
- },
102
- []
103
- )
104
-
105
- const renderItem = useCallback(
106
- (
107
- item: NavProps | SubNav | View,
108
- level: number,
109
- activeAndHoverColor = semiTransparentWhite.main
110
- ) => {
111
- if ('title' in item && 'subnavs' in item) {
112
- const nav = item as NavProps
113
- const isExpanded = expandedNavs.includes(nav.title ?? '')
114
- return (
115
- <MuiAccordion
116
- key={nav.title}
117
- disableGutters
118
- elevation={0}
119
- square
120
- expanded={isExpanded}
121
- onChange={() => {
122
- if (isExpanded) {
123
- setExpandedNavs(
124
- expandedNavs.filter(title => title !== nav.title)
125
- )
126
- } else {
127
- setExpandedNavs([...expandedNavs, nav.title ?? ''])
128
- }
129
- }}
130
- sx={{
131
- pl: 0,
132
- backgroundColor: 'transparent',
133
- '.MuiAccordionSummary-root': {
134
- pl: 0,
135
- },
136
- '&:before': {
137
- display: 'none',
138
- },
139
- }}
140
- >
141
- <AccordionSummary
142
- expandIcon={
143
- nav.subnavs && nav.subnavs.length > 0 ? (
144
- <ExpandMoreIcon
145
- sx={{
146
- color: 'transparent',
147
- }}
148
- />
149
- ) : null
150
- }
151
- aria-controls="accordion-content"
152
- id="accordion-header"
153
- sx={{
154
- boxSizing: 'border-box',
155
- border: 'none',
156
- py: '6px',
157
- mt: 2,
158
- ml: 3,
159
- minHeight: 0,
160
- height: '32px',
161
- '& .MuiAccordionSummary-content': {
162
- m: 0,
163
- },
164
- '&:hover': {
165
- '& .MuiSvgIcon-root': {
166
- color: white.main,
167
- },
168
- },
169
- '&.Mui-expanded': {
170
- '& .MuiSvgIcon-root': {
171
- color: white.main,
172
- },
173
- },
174
- }}
175
- onClick={() => handleNavClick(nav)}
176
- >
177
- <Typography
178
- fontvariant="merrih5"
179
- fontcolor={white.main}
180
- text={nav.title ?? ''}
181
- marginLeft={4 * level}
182
- />
183
- </AccordionSummary>
184
- <AccordionDetails sx={{ border: 'none', p: 0 }}>
185
- <List sx={{ py: 0 }}>
186
- {nav.subnavs?.map(subnav =>
187
- renderItem(subnav, level + 1, activeAndHoverColor)
188
- )}
189
- </List>
190
- </AccordionDetails>
191
- </MuiAccordion>
192
- )
193
- } else if ('title' in item && 'views' in item) {
194
- const subnav = item as SubNav
195
- const isExpanded = expandedSubnavs.includes(subnav.title ?? '')
196
- if (subnav.views?.length === 0) {
197
- return (
198
- <Link
199
- key={subnav.title}
200
- style={{
201
- textDecoration: 'none',
202
- color: 'white',
203
- }}
204
- href={subnav.route ?? ''}
205
- >
206
- <MenuItem
207
- sx={{
208
- color: white.main,
209
- ml: '25px',
210
- '&:hover': {
211
- backgroundColor: activeAndHoverColor,
212
- },
213
- '&:active': {
214
- backgroundColor: activeAndHoverColor,
215
- },
216
- }}
217
- >
218
- <Typography
219
- fontvariant="merrih6"
220
- text={subnav.title ?? ''}
221
- fontcolor={white.main}
222
- />
223
- </MenuItem>
224
- </Link>
225
- )
226
- } else {
227
- return (
228
- <MuiAccordion
229
- key={subnav.title}
230
- disableGutters
231
- elevation={0}
232
- square
233
- expanded={isExpanded}
234
- onChange={() => {
235
- if (isExpanded) {
236
- setExpandedSubnavs(
237
- expandedSubnavs.filter(title => title !== subnav.title)
238
- )
239
- } else {
240
- setExpandedSubnavs([...expandedSubnavs, subnav.title ?? ''])
241
- }
242
- }}
243
- sx={{
244
- pl: 0,
245
- backgroundColor: 'transparent',
246
- '.MuiAccordionSummary-root': {
247
- pl: 0,
248
- },
249
- '&:before': {
250
- display: 'none',
251
- },
252
- }}
253
- >
254
- <AccordionSummary
255
- expandIcon={
256
- <ExpandMoreIcon
257
- sx={{
258
- color: 'transparent',
259
- }}
260
- />
261
- }
262
- aria-controls="accordion-content"
263
- id="accordion-header"
264
- sx={{
265
- boxSizing: 'border-box',
266
- border: 'none',
267
- py: '6px',
268
- mt: 0,
269
- ml: '8px',
270
- minHeight: 0,
271
- height: '32px',
272
- '& .MuiAccordionSummary-content': {
273
- m: 0,
274
- },
275
- '&:hover': {
276
- '& .MuiSvgIcon-root': {
277
- color: white.main,
278
- },
279
- },
280
- '&.Mui-expanded': {
281
- '& .MuiSvgIcon-root': {
282
- color: white.main,
283
- },
284
- },
285
- }}
286
- >
287
- <Typography
288
- fontvariant="merrih6"
289
- fontcolor={white.main}
290
- text={subnav.title ?? ''}
291
- marginLeft={4}
292
- />
293
- </AccordionSummary>
294
- <AccordionDetails sx={{ border: 'none', p: 0 }}>
295
- <List sx={{ py: 0 }}>
296
- {subnav.views?.map(view =>
297
- renderItem(view, level + 1, activeAndHoverColor)
298
- )}
299
- </List>
300
- </AccordionDetails>
301
- </MuiAccordion>
302
- )
303
- }
304
- } else if ('title' in item && 'route' in item) {
305
- const view = item as View
306
- return (
307
- <Link
308
- key={view.title}
309
- style={{
310
- textDecoration: 'none',
311
- color: 'white',
312
- }}
313
- href={view.route ?? ''}
314
- onClick={variant === 'temporary' ? onClose : undefined}
315
- >
316
- <MenuItem
317
- sx={{
318
- color: white.main,
319
- pl: level + 6,
320
- '&:hover': {
321
- backgroundColor: activeAndHoverColor,
322
- },
323
- '&:active': {
324
- backgroundColor: activeAndHoverColor,
325
- },
326
- }}
327
- >
328
- <Typography
329
- fontvariant="merriparagraph"
330
- text={view.title ?? ''}
331
- fontcolor={white.main}
332
- />
333
- </MenuItem>
334
- </Link>
335
- )
336
- }
337
- return null
338
- },
339
- [
340
- expandedNavs,
341
- setExpandedNavs,
342
- expandedSubnavs,
343
- setExpandedSubnavs,
344
- handleNavClick,
345
- variant,
346
- onClose,
347
- ]
348
- )
349
-
350
- const drawerContent = (
351
- <>
352
- <Box px={`15px`}>
353
- {showTitle && (
354
- <Box pt="0px" pb="0px">
355
- <Link
356
- href={titleUrl || '/'}
357
- passHref
358
- style={{ textDecoration: 'none' }}
359
- onClick={variant === 'temporary' ? onClose : undefined}
360
- >
361
- <Typography
362
- fontvariant="merrih4"
363
- fontcolor={white.main}
364
- text={verticalNavTitle}
365
- />
366
- </Link>
367
- </Box>
368
- )}
369
- {showSearchableNav && (
370
- <Stack mt={{ xs: '10px', md: '10px', lg: 0 }} spacing={0}>
371
- <Box
372
- sx={{
373
- position: 'relative',
374
- zIndex: theme => theme.zIndex.drawer + 1,
375
- width: '100%',
376
- minHeight: '40px',
377
- }}
378
- >
379
- <SearchableDropdown
380
- label={searchableNavLabel}
381
- options={navOptions}
382
- backgroundcolor={backgroundcolor || semiTransparentWhite.main}
383
- outlinecolor="none"
384
- fontcolor={white.main}
385
- shrunkfontcolor={shrunkfontcolor}
386
- unshrunkfontcolor={unshrunkfontcolor}
387
- shrunklabelposition="aboveNotch"
388
- onChange={handleSearchableNavChange}
389
- placeholder="Search..."
390
- />
391
- </Box>
392
- </Stack>
393
- )}
394
- </Box>
395
- {showLine && (
396
- <Divider
397
- sx={{
398
- width: verticalNavWidth,
399
- backgroundColor: white.main,
400
- mt: 2.5,
401
- }}
402
- />
403
- )}
404
- {selectedNav
405
- ? items
406
- .filter(
407
- (item): item is NavProps =>
408
- 'title' in item && item.title === selectedNav
409
- )
410
- .map(item => renderItem(item, 0))
411
- : items.map(item => renderItem(item, 0))}
412
- </>
413
- )
414
-
415
- return (
416
- <Drawer
417
- variant={variant}
418
- anchor={anchor}
419
- open={variant === 'temporary' ? mobileOpen : true}
420
- onClose={onClose}
421
- elevation={0}
422
- sx={{
423
- width: variant === 'permanent' ? verticalNavWidth : 'auto',
424
- height: '100%',
425
- flexShrink: 0,
426
- '& .MuiDrawer-paper': {
427
- width: verticalNavWidth,
428
- border: 0,
429
- zIndex: theme =>
430
- variant === 'temporary'
431
- ? theme.zIndex.drawer + 2
432
- : theme.zIndex.drawer - 1,
433
- backgroundColor: ocean.main,
434
- pt: '17px',
435
- boxSizing: 'border-box',
436
- marginTop: spacingfromtopofscreen,
437
- },
438
- }}
439
- >
440
- {drawerContent}
441
- </Drawer>
442
- )
443
- }
444
-
445
- export default VerticalVariant