-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavbar.tsx
More file actions
425 lines (402 loc) · 18.7 KB
/
Copy pathNavbar.tsx
File metadata and controls
425 lines (402 loc) · 18.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
import { ArrowRight } from 'lucide-react'
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import appImage from '@/assets/navbar_app_highlight.webp'
import { CalBookingDialog } from '@/components/CalBookingDialog'
import { Link } from '@/components/Link'
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion'
import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
navigationMenuTriggerStyle,
} from '@/components/ui/navigation-menu'
import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet'
import { Menu } from 'lucide-react'
import LanguageSwitcher from './LanguageSwitcher'
import VocdoniLogo from './Logo'
type ProductFeature =
| {
title: string
description: string
kind: 'link'
href: string
target?: string
rel?: string
}
| {
title: string
description: string
kind: 'booking'
triggerAriaLabel: string
}
const buildProductFeatures = (t: (key: string) => string) =>
[
{
title: t('navbar.product_features.digital_voting_platform.title'),
kind: 'link' as const,
href: '/app',
description: t('navbar.product_features.digital_voting_platform.description'),
},
{
title: t('navbar.product_features.sdk.title'),
kind: 'link' as const,
href: 'https://developer.vocdoni.io/sdk',
target: '_blank',
rel: 'noopener noreferrer',
description: t('navbar.product_features.sdk.description'),
},
{
title: t('navbar.product_features.custom_projects.title'),
kind: 'booking' as const,
triggerAriaLabel: 'Open custom project booking',
description: t('navbar.product_features.custom_projects.description'),
},
] satisfies ProductFeature[]
const buildFeaturedSolution = (t: (key: string) => string) => ({
title: t('navbar.featured_solution.vocdoni_app.title'),
description: t('navbar.featured_solution.vocdoni_app.description'),
href: 'https://app.vocdoni.io',
cta: t('navbar.featured_solution.vocdoni_app.cta'),
badge: t('navbar.featured_solution.vocdoni_app.badge'),
})
const buildResourcesItems = (t: (key: string) => string) => [
{
title: t('navbar.resources_items.blog.title'),
href: 'https://blog.vocdoni.io',
target: '_blank',
rel: 'noopener noreferrer',
description: t('navbar.resources_items.blog.description'),
},
{
title: t('navbar.resources_items.success_stories.title'),
href: '/use-cases#success-stories',
description: t('navbar.resources_items.success_stories.description'),
},
{
title: t('navbar.resources_items.docs.title'),
href: 'https://developer.vocdoni.io',
target: '_blank',
rel: 'noopener noreferrer',
description: t('navbar.resources_items.docs.description'),
},
]
export function Navbar() {
const { t } = useTranslation()
const [isOpen, setIsOpen] = React.useState(false)
const productFeatures = React.useMemo(() => buildProductFeatures(t), [t])
const featuredSolution = React.useMemo(() => buildFeaturedSolution(t), [t])
const resourcesItems = React.useMemo(() => buildResourcesItems(t), [t])
return (
<div className='fixed top-6 left-0 right-0 z-50 flex justify-center px-4 cursor-none pointer-events-none'>
<header className='cursor-default pointer-events-auto flex items-center justify-between gap-4 rounded-full border border-border/40 bg-background/80 px-4 py-2 shadow-sm backdrop-blur-md w-full max-w-[2000px] transition-all duration-300'>
{/* Logo */}
<div className='pointer-events'>
<Link href='/' variant='unstyled' aria-label={t('navbar.logo_aria_label', 'Vocdoni - go to homepage')}>
<VocdoniLogo minimal className='h-7 xl:hidden' aria-hidden='true' />
<VocdoniLogo className='hidden xl:block h-8' aria-hidden='true' />
</Link>
</div>
{/* Desktop Navigation */}
<NavigationMenu className='hidden xl:flex min-w-max'>
<NavigationMenuList>
{/* Solutions (formerly Product) */}
<NavigationMenuItem>
<NavigationMenuTrigger>{t('navbar.solutions')}</NavigationMenuTrigger>
<NavigationMenuContent>
<div className='w-[650px] p-6'>
<div className='grid grid-cols-2 gap-6'>
{/* Left column: Regular solution items */}
<div className='space-y-2'>
<p className='mb-3 px-2 text-sm text-muted-foreground font-medium'>
{t('navbar.solutions_header')}
</p>
<ul className='space-y-0.5'>
{productFeatures.map((item) => (
<li key={item.title}>
{item.kind === 'link' ? (
<NavigationMenuLink asChild>
<Link href={item.href} target={item.target} rel={item.rel} variant='navbarItem'>
<div className='text-sm font-medium leading-none'>{item.title}</div>
<p className='line-clamp-2 text-sm leading-snug text-muted-foreground'>
{item.description}
</p>
</Link>
</NavigationMenuLink>
) : (
<CalBookingDialog
className='block w-full select-none space-y-1 rounded-md p-3 text-left leading-none no-underline outline-none transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground'
triggerAriaLabel={item.triggerAriaLabel}
>
<div className='text-sm font-medium leading-none'>{item.title}</div>
<p className='line-clamp-2 text-sm leading-snug text-muted-foreground'>
{item.description}
</p>
</CalBookingDialog>
)}
</li>
))}
</ul>
</div>
{/* Right column: Featured card with image */}
<div className='relative flex flex-col'>
<p className='mb-2 px-2 text-sm text-muted-foreground font-medium'>
{t('navbar.featured_solution.header')}
</p>
<Link href={featuredSolution.href} target='_blank' rel='noopener noreferrer' variant='card'>
<div className='relative h-full'>
{/* App highlight image */}
<img
src={appImage}
alt='Vocdoni App'
className='aspect-video w-full object-cover'
loading='lazy'
decoding='async'
width={640}
height={360}
/>
{/* Gradient overlay */}
<span className='absolute inset-0 bg-gradient-to-t from-black/60 to-transparent' />
{/* Content overlay */}
<span className='absolute bottom-0 p-4 text-white'>
<div className='flex items-center gap-2 mb-1'>
<h3 className='font-semibold text-sm'>{featuredSolution.title}</h3>
{featuredSolution.badge && (
<Badge variant='secondary' className='text-xs px-2 py-0'>
{featuredSolution.badge}
</Badge>
)}
</div>
{featuredSolution.description && (
<p className='text-xs text-white/90'>{featuredSolution.description}</p>
)}
</span>
</div>
</Link>
</div>
</div>
</div>
</NavigationMenuContent>
</NavigationMenuItem>
{/* Use Cases */}
<NavigationMenuItem>
<Link href='/use-cases' variant='unstyled' className={navigationMenuTriggerStyle()}>
{t('navbar.use_cases')}
</Link>
</NavigationMenuItem>
<NavigationMenuItem>
<Link
href='https://davinci.vote'
target='_blank'
rel='noopener noreferrer'
variant='unstyled'
className={navigationMenuTriggerStyle()}
>
{t('navbar.technology')}
</Link>
</NavigationMenuItem>
{/* Resources (replaces Success stories) */}
<NavigationMenuItem>
<NavigationMenuTrigger>{t('navbar.resources')}</NavigationMenuTrigger>
<NavigationMenuContent>
<ul className='grid w-[400px] gap-3 p-4 md:w-[500px] md:grid-cols-2 lg:w-[600px]'>
{resourcesItems.map((item) => (
<ListItem key={item.title} title={item.title} href={item.href} target={item.target} rel={item.rel}>
{item.description}
</ListItem>
))}
</ul>
</NavigationMenuContent>
</NavigationMenuItem>
{/* About Us */}
<NavigationMenuItem>
<Link href='/about-us' variant='unstyled' className={navigationMenuTriggerStyle()}>
{t('navbar.about')}
</Link>
</NavigationMenuItem>
<NavigationMenuItem>
<Link href='/contact' variant='unstyled' className={navigationMenuTriggerStyle()}>
{t('navbar.contact')}
</Link>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
{/* Right Side: App Button, Language Switcher & Mobile Menu */}
<div className='flex items-center gap-2'>
<LanguageSwitcher />
{/* Mobile Menu Trigger */}
<div className='xl:hidden'>
<Sheet open={isOpen} onOpenChange={setIsOpen}>
<SheetTrigger asChild>
<Button variant='ghost' size='icon'>
<Menu className='h-6 w-6' />
<span className='sr-only'>Toggle menu</span>
</Button>
</SheetTrigger>
<SheetContent side='left' className='w-[300px] sm:w-[400px] p-0'>
<div className='flex flex-col h-full bg-background'>
{/* Header inside Sheet */}
<div className='p-6 border-b'>
<VocdoniLogo aria-hidden='true' />
</div>
{/* Menu Items */}
<div className='flex-1 overflow-auto py-6 px-4'>
<Accordion type='single' collapsible className='w-full'>
{/* Solutions (mobile) */}
<AccordionItem value='product' className='border-border/40'>
<AccordionTrigger className='font-sans text-sm font-medium py-3 hover:text-primary hover:no-underline transition-colors'>
{t('navbar.solutions')}
</AccordionTrigger>
<AccordionContent>
<div className='flex flex-col space-y-2 pl-4'>
{/* Featured solution - mobile version */}
<div className='mb-2 p-3 rounded-lg bg-primary/5 border border-primary/20'>
<Link
href={featuredSolution.href}
target='_blank'
rel='noopener noreferrer'
variant='unstyled'
className='block'
onClick={() => setIsOpen(false)}
>
<div className='flex items-start justify-between gap-2'>
<div className='flex-1'>
<div className='flex items-center gap-2 mb-1'>
<span className='text-sm font-semibold'>{featuredSolution.title}</span>
{featuredSolution.badge && (
<Badge variant='secondary' className='text-xs px-1.5 py-0'>
{featuredSolution.badge}
</Badge>
)}
</div>
<span className='text-xs text-muted-foreground block'>
{featuredSolution.description}
</span>
</div>
<ArrowRight className='h-4 w-4 text-primary flex-shrink-0 mt-0.5' />
</div>
</Link>
</div>
{/* Regular items */}
{productFeatures.map((item) =>
item.kind === 'link' ? (
<Link
key={item.title}
href={item.href}
target={item.target}
rel={item.rel}
variant='navbarMobile'
onClick={() => setIsOpen(false)}
>
{item.title}
</Link>
) : (
<CalBookingDialog
key={item.title}
className='block py-2 text-left text-sm text-muted-foreground transition-colors hover:text-foreground'
triggerAriaLabel={item.triggerAriaLabel}
onClick={() => setIsOpen(false)}
>
{item.title}
</CalBookingDialog>
)
)}
</div>
</AccordionContent>
</AccordionItem>
{/* Resources (mobile) */}
<AccordionItem value='resources' className='border-border/40'>
<AccordionTrigger className='font-sans text-sm font-medium py-3 hover:text-primary hover:no-underline transition-colors'>
{t('navbar.resources')}
</AccordionTrigger>
<AccordionContent>
<div className='flex flex-col space-y-2 pl-4'>
{resourcesItems.map((item) => (
<Link
key={item.title}
href={item.href}
target={item.target}
rel={item.rel}
variant='navbarMobile'
onClick={() => setIsOpen(false)}
>
{item.title}
</Link>
))}
</div>
</AccordionContent>
</AccordionItem>
</Accordion>
{/* Static Links */}
<div className='flex flex-col'>
<Link href='/use-cases' variant='navbarStatic' onClick={() => setIsOpen(false)}>
{t('navbar.use_cases')}
</Link>
<Link href='/about-us' variant='navbarStatic' onClick={() => setIsOpen(false)}>
{t('navbar.about')}
</Link>
<Link
href='https://davinci.vote'
target='_blank'
rel='noopener noreferrer'
variant='navbarStatic'
onClick={() => setIsOpen(false)}
>
{t('navbar.technology')}
</Link>
<Link href='/contact' variant='navbarStatic' onClick={() => setIsOpen(false)}>
{t('navbar.contact')}
</Link>
</div>
</div>
{/* Footer App Button */}
<div className='p-6 border-t mt-auto'>
<Button asChild className='w-full rounded-full'>
<Link
href='https://app.vocdoni.io'
target='_blank'
rel='noopener noreferrer'
variant='unstyled'
onClick={() => setIsOpen(false)}
>
App
</Link>
</Button>
</div>
</div>
</SheetContent>
</Sheet>
</div>
{/* App Button (hidden on mobile) */}
<div className='hidden xl:block'>
<Button asChild className='rounded-full px-6'>
<Link href='https://app.vocdoni.io' target='_blank' rel='noopener noreferrer' variant='unstyled'>
{t('navbar.app_button')}
</Link>
</Button>
</div>
</div>
</header>
</div>
)
}
const ListItem = React.forwardRef<React.ElementRef<'a'>, React.ComponentPropsWithoutRef<typeof Link>>(
({ className, title, children, ...props }, ref) => {
return (
<li>
<NavigationMenuLink asChild>
<Link ref={ref} variant='navbarItem' className={className} {...props}>
<div className='text-sm font-medium leading-none'>{title}</div>
<p className='line-clamp-2 text-sm leading-snug text-muted-foreground'>{children}</p>
</Link>
</NavigationMenuLink>
</li>
)
}
)
ListItem.displayName = 'ListItem'