forked from onnimonni/nextjs-notion-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotionPageHeader.tsx
90 lines (78 loc) · 2.53 KB
/
NotionPageHeader.tsx
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
import type * as types from 'notion-types'
import cs from 'classnames'
import * as React from 'react'
import { IoMoonSharp, IoSunnyOutline } from 'react-icons/io5'
import { Header, Search, useNotionContext } from 'react-notion-x'
import { isSearchEnabled, navigationLinks, navigationStyle } from '@/lib/config'
import { useDarkMode } from '@/lib/use-dark-mode'
import { StaticLogo } from './StaticLogo'
import styles from './styles.module.css'
function ToggleThemeButton() {
const [hasMounted, setHasMounted] = React.useState(false)
const { isDarkMode, toggleDarkMode } = useDarkMode()
React.useEffect(() => {
setHasMounted(true)
}, [])
const onToggleTheme = React.useCallback(() => {
toggleDarkMode()
}, [toggleDarkMode])
return (
<button
type="button"
className={cs('breadcrumb', 'button', styles.toggleDarkMode, !hasMounted && styles.hidden)}
onClick={onToggleTheme}
>
{hasMounted && isDarkMode ? <IoMoonSharp /> : <IoSunnyOutline />}
</button>
)
}
export function NotionPageHeader({
block
}: {
block: types.CollectionViewPageBlock | types.PageBlock
}) {
const { components, mapPageUrl } = useNotionContext()
if (navigationStyle === 'default') {
return <Header block={block} />
}
return (
<header className='notion-header'>
<div className='notion-nav-header'>
<div className="notion-nav-header-rhs breadcrumbs">
<StaticLogo />
</div>
<div className='notion-nav-header-rhs breadcrumbs'>
{navigationLinks
?.map((link) => {
if (!link.pageId && !link.url) {
return null
}
if (link.pageId) {
return (
<components.PageLink
href={mapPageUrl(link.pageId)}
key={`nav-${link.pageId}-${link.title}`}
className={cs(styles.navLink, 'breadcrumb', 'button')}
>
{link.title}
</components.PageLink>
)
}
return (
<components.Link
href={link.url}
key={`nav-${link.url}-${link.title}`}
className={cs(styles.navLink, 'breadcrumb', 'button')}
>
{link.title}
</components.Link>
)
})
.filter(Boolean)}
<ToggleThemeButton />
{isSearchEnabled && <Search block={block} title={null} />}
</div>
</div>
</header>
)
}