Skip to content

Commit b08df60

Browse files
landing page: scroll to hash and UI fixes
1 parent e75f068 commit b08df60

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

landing/src/components/confidant-header.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import Link from 'next/link'
44
import { Menu, X } from 'lucide-react'
55
import { Button } from '@/components/ui/button'
6+
import { scrollToHash } from '@/lib/scroll-to-hash'
67
import React from 'react'
78
import { cn } from '@/lib/utils'
89
import { ConfidantLogo } from './confidant-logo'
@@ -31,13 +32,14 @@ export function ConfidantHeader() {
3132
<Link
3233
href={item.href}
3334
{...(item.external ? { target: '_blank', rel: 'noopener noreferrer' } : {})}
35+
{...(item.href.startsWith('#') ? { onClick: (e) => scrollToHash(e, item.href) } : {})}
3436
>
3537
{item.name}
3638
</Link>
3739
</Button>
3840
))}
3941
<Button asChild size="sm" className="ml-2">
40-
<Link href="#download">Download</Link>
42+
<Link href="#download" onClick={(e) => scrollToHash(e, '#download')}>Download</Link>
4143
</Button>
4244
</div>
4345
<button
@@ -55,12 +57,22 @@ export function ConfidantHeader() {
5557
key={item.name}
5658
href={item.href}
5759
{...(item.external ? { target: '_blank', rel: 'noopener noreferrer' } : {})}
58-
onClick={() => setMenuState(false)}
60+
{...(item.href.startsWith('#') ? { onClick: (e) => { scrollToHash(e, item.href); setMenuState(false) } } : { onClick: () => setMenuState(false) })}
5961
className="block py-2 text-muted-foreground hover:text-foreground"
6062
>
6163
{item.name}
6264
</Link>
6365
))}
66+
<Link
67+
href="#download"
68+
onClick={(e) => {
69+
scrollToHash(e, '#download')
70+
setMenuState(false)
71+
}}
72+
className="block py-2 text-muted-foreground hover:text-foreground"
73+
>
74+
Download
75+
</Link>
6476
</div>
6577
)}
6678
</div>

landing/src/components/confidant-hero.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
'use client'
2+
13
import Link from 'next/link'
24
import { Button } from '@/components/ui/button'
5+
import { scrollToHash } from '@/lib/scroll-to-hash'
36
import { ChevronRight } from 'lucide-react'
47
import { ConfidantHeader } from './confidant-header'
58

@@ -18,7 +21,7 @@ export function ConfidantHero() {
1821
</p>
1922
<div className="mt-8 flex flex-col sm:flex-row gap-4 justify-center">
2023
<Button asChild size="lg" className="pr-2">
21-
<Link href="#download">
24+
<Link href="#download" onClick={(e) => scrollToHash(e, '#download')}>
2225
Download for free
2326
<ChevronRight className="ml-1 size-4 opacity-70" />
2427
</Link>

landing/src/lib/scroll-to-hash.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { MouseEvent } from 'react'
2+
3+
export function scrollToHash(e: MouseEvent<HTMLAnchorElement>, hash: string) {
4+
const el = document.getElementById(hash.replace('#', ''))
5+
if (el) {
6+
e.preventDefault()
7+
el.scrollIntoView({ behavior: 'smooth' })
8+
window.history.pushState(null, '', hash)
9+
}
10+
}

0 commit comments

Comments
 (0)