-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathDaoDappTabbedHome.tsx
78 lines (71 loc) · 2.19 KB
/
DaoDappTabbedHome.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
import clsx from 'clsx'
import { DaoDappTabbedHomeProps } from '@dao-dao/types'
import {
PAGE_PADDING_HORIZONTAL_CLASSES,
UNDO_PAGE_PADDING_HORIZONTAL_CLASSES,
UNDO_PAGE_PADDING_TOP_CLASSES_WITH_TOP,
} from '@dao-dao/utils'
import { PageLoader, TabBar } from '../components'
import { DaoSplashHeader } from '../components/dao/DaoSplashHeader'
import { useDao } from '../contexts'
import { useTabBarScrollReset } from '../hooks'
export const DaoDappTabbedHome = ({
SuspenseLoader,
ButtonLink,
LinkWrapper,
tabs,
selectedTabId,
onSelectTabId,
...headerProps
}: DaoDappTabbedHomeProps) => {
const dao = useDao()
// Auto scroll to top of tab on change.
const { tabBarRef, tabContainerRef } = useTabBarScrollReset({
selectedTabId,
})
return (
<div className="relative z-[1] flex flex-col items-stretch">
<div className="mb-4">
<DaoSplashHeader
ButtonLink={ButtonLink}
LinkWrapper={LinkWrapper}
dao={dao}
{...headerProps}
/>
</div>
<div
className={clsx(
// Stick to the top when the tab content scrolls down. Use higher z
// index to make sure this stays above tab content.
'sticky z-20 flex flex-col items-stretch bg-background-base',
UNDO_PAGE_PADDING_TOP_CLASSES_WITH_TOP,
UNDO_PAGE_PADDING_HORIZONTAL_CLASSES,
PAGE_PADDING_HORIZONTAL_CLASSES
)}
>
<TabBar
onSelect={onSelectTabId}
ref={tabBarRef}
selectedTabId={selectedTabId}
tabs={tabs.map(({ id, label, IconFilled }) => ({
id,
label,
Icon: IconFilled,
}))}
/>
</div>
<div className="z-10 pt-5 pb-4" ref={tabContainerRef}>
{tabs.map(({ id, Component, lazy }) => (
<div key={id} className={clsx(selectedTabId !== id && 'hidden')}>
{/* Render tab if it shouldn't lazy load or if it's selected. */}
{(!lazy || selectedTabId === id) && (
<SuspenseLoader fallback={<PageLoader size={32} />}>
<Component />
</SuspenseLoader>
)}
</div>
))}
</div>
</div>
)
}