-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathLayout.tsx
More file actions
712 lines (673 loc) · 29.6 KB
/
Layout.tsx
File metadata and controls
712 lines (673 loc) · 29.6 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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
import { useMap } from '@react-hookz/web'
import merge from 'lodash/merge'
import NextImage from 'next/image'
import { NextSeo, type NextSeoProps } from 'next-seo'
import type { NextraThemeLayoutProps } from 'nextra'
import { useFSRoute, useRouter } from 'nextra/hooks'
import { MDXProvider } from 'nextra/mdx'
import { normalizePages } from 'nextra/normalize-pages'
import {
type ComponentProps,
createContext,
type ReactNode,
useContext,
useEffect,
useMemo,
useRef,
useState,
} from 'react'
import type { WithOptional } from '@edgeandnode/common'
import {
ButtonOrLink,
classNames,
ExperimentalAppLauncher,
ExperimentalButton,
ExperimentalCodeInline,
ExperimentalLink,
type ExperimentalLinkProps,
ExperimentalLocaleSwitcher,
ExperimentalNavLink,
type NestedStrings,
useIsomorphicLayoutEffect,
} from '@edgeandnode/gds'
import {
APIToken,
BookOpenText,
Files,
House,
Hypergraph,
MagnifyingGlass,
RoleIndexer,
SidebarSimple,
SocialDiscord,
SocialGitHub,
SocialTelegram,
SocialX,
Sparkle,
Stack,
Subgraph,
Substreams,
SubstreamsPoweredSubgraph,
TheGraph,
Translate,
} from '@edgeandnode/gds/icons'
import {
Callout,
CodeBlock,
DocSearch,
Heading,
Image,
NavigationGroup,
NavigationItem,
Table,
VideoEmbed,
} from '@/components'
import { useI18n } from '@/i18n'
import { MDXContent } from './MDXContent'
import { type FrontMatter, LayoutContext, type TemplateOptions, templateOptionsSchema } from './shared'
const removeBasePathFromUrl = (url: string) => url.substring((process.env.BASE_PATH ?? '').length)
const DocSearchHit = ({ hit, children }: { hit: { url: string }; children?: ReactNode }) => (
<ButtonOrLink href={removeBasePathFromUrl(hit.url)}>{children}</ButtonOrLink>
)
export default function Layout({ pageOpts, children }: NextraThemeLayoutProps<FrontMatter>) {
const { filePath, frontMatter, pageMap, readingTime, timestamp } = pageOpts
const fsPath = useFSRoute()
const normalizedPages = normalizePages({
list: pageMap,
route: fsPath,
})
const activeRoute = normalizedPages.activePath.at(-1)?.route ?? null
const router = useRouter()
const { t, translations, locale } = useI18n()
const [sidebarExpandedOnMobile, setSidebarExpandedOnMobile] = useState(false)
const [sidebarExpandedOnDesktop, setSidebarExpandedOnDesktop] = useState(true)
// Collapse the sidebar on mobile when the route changes
useEffect(() => {
setSidebarExpandedOnMobile(false)
}, [activeRoute])
// TODO: Create `useTailwindScreen` hook in GDS, with usage like `const screen = useTailwindScreen()` and then you can check `screen.md`, etc.
const [mobile, setMobile] = useState(false)
useIsomorphicLayoutEffect(() => {
const mediaQueryList = matchMedia('(min-width: 768px)')
setMobile(!mediaQueryList.matches)
const onChange = (event: MediaQueryListEvent) => setMobile(!event.matches)
mediaQueryList.addEventListener('change', onChange)
return () => mediaQueryList.removeEventListener('change', onChange)
}, [])
type PartialNavItem = WithOptional<(typeof normalizedPages.directories)[number], 'children'>
type NavItem = Omit<(typeof normalizedPages.directories)[number], 'children'> & {
children: NavItem[]
group: NavItemGroup
ancestors: NavItem[]
frontMatter?: FrontMatter
}
type NavItemGroup = {
title: string | undefined
route: string | undefined
href: string | undefined
items: NavItem[]
}
const selectedNavItemRef = useRef<NavItem | null>(null)
const navItemExpandedByRoute = useMap<string, boolean | 'manually-expanded'>()
// Refresh the expansion state of nav items on load and when the route changes
useEffect(() => {
// Only keep the manually expanded items
for (const [route, expanded] of navItemExpandedByRoute.entries()) {
if (expanded !== 'manually-expanded') {
navItemExpandedByRoute.delete(route)
}
}
// Expand the selected item's ancestors and group that are not already expanded (as to not override the manually expanded states)
if (selectedNavItemRef.current) {
const routesToExpand = [
selectedNavItemRef.current.route,
...selectedNavItemRef.current.ancestors.map((ancestor) => ancestor.route),
selectedNavItemRef.current.group.route,
]
for (const route of routesToExpand) {
if (route === undefined) continue
const alreadyExpanded = navItemExpandedByRoute.get(route)
if (alreadyExpanded) continue
navItemExpandedByRoute.set(route, true)
}
}
}, [activeRoute, navItemExpandedByRoute])
const { navItemGroups, getNavItemSelected, getNavItemExpanded, setNavItemExpanded, getNavItemIcon, getNavItemHref } =
useMemo(() => {
const getRouteWithoutLocale = (route: string) => route.slice(3)
const getNavItemSelected = (route: string) => {
if (route === activeRoute) {
return true
}
const parentRouteKey = frontMatter.parentRouteKey
if (parentRouteKey && getRouteWithoutLocale(route) === `/${parentRouteKey}`) {
return true
}
if (
selectedNavItemRef.current &&
selectedNavItemRef.current.ancestors.some((ancestor) => ancestor.route === route)
) {
return 'partially'
}
return false
}
const getNavItemExpanded = (route: string) => Boolean(navItemExpandedByRoute.get(route))
const setNavItemExpanded = (route: string, expanded: boolean, manual?: boolean) => {
navItemExpandedByRoute.set(route, expanded ? (manual ? 'manually-expanded' : true) : false)
}
const getNavItemIcon = (navItem: NavItem) => {
const routeWithoutLocale = getRouteWithoutLocale(navItem.route)
const selected = getNavItemSelected(navItem.group.route ?? navItem.route)
if (routeWithoutLocale === '') {
return <House alt="" variant={selected ? 'fill' : 'regular'} />
}
if (routeWithoutLocale === '/about' || routeWithoutLocale.startsWith('/about/')) {
return <TheGraph alt="" />
}
if (routeWithoutLocale === '/supported-networks' || routeWithoutLocale.startsWith('/supported-networks/')) {
return <Stack alt="" variant={selected ? 'fill' : 'regular'} />
}
if (routeWithoutLocale === '/contracts' || routeWithoutLocale.startsWith('/contracts/')) {
return <Files alt="" variant={selected ? 'fill' : 'regular'} />
}
if (routeWithoutLocale === '/subgraphs' || routeWithoutLocale.startsWith('/subgraphs/')) {
return <Subgraph alt="" />
}
if (routeWithoutLocale === '/substreams' || routeWithoutLocale.startsWith('/substreams/')) {
return <Substreams alt="" />
}
if (routeWithoutLocale === '/sps' || routeWithoutLocale.startsWith('/sps/')) {
return <SubstreamsPoweredSubgraph alt="" />
}
if (routeWithoutLocale === '/token-api' || routeWithoutLocale.startsWith('/token-api/')) {
return <APIToken alt="" />
}
if (routeWithoutLocale === '/hypergraph' || routeWithoutLocale.startsWith('/hypergraph/')) {
return <Hypergraph alt="" />
}
if (routeWithoutLocale === '/ai-suite' || routeWithoutLocale.startsWith('/ai-suite/')) {
return <Sparkle alt="" variant={selected ? 'fill' : 'regular'} />
}
if (routeWithoutLocale === '/indexing' || routeWithoutLocale.startsWith('/indexing/')) {
return <RoleIndexer alt="" />
}
if (
routeWithoutLocale === '/resources' ||
routeWithoutLocale.startsWith('/resources/') ||
routeWithoutLocale === '/archived' ||
routeWithoutLocale.startsWith('/archived/')
) {
return <BookOpenText alt="" variant={selected ? 'fill' : 'regular'} />
}
return null
}
const getNavItemHref = (navItem: NavItem) => {
let currentNavItem = navItem
while (currentNavItem.children.length > 0 && !currentNavItem.withIndexPage) {
currentNavItem = currentNavItem.children[0]!
}
return currentNavItem.route
}
const navItemGroups = normalizedPages.directories.reduce<NavItemGroup[]>(
(groups, partialNavItem: PartialNavItem) => {
const navItemHasChildren = Boolean(partialNavItem.children?.length)
if (partialNavItem.type === 'children' && !navItemHasChildren) return groups
/**
* When an item of type `children` doesn't have a title set in the meta file, we want to render it without a `NavigationItem` wrapper.
* Unfortunately, Nextra defaults `title` to `name`, so the way to check if it's empty is to check if it's equal to `name`, which should
* never happen with an explicitly set `title` because it should be title case whereas `name` will always be lowercase.
*/
const navItemHasNoWrapper = partialNavItem.type === 'children' && partialNavItem.title === partialNavItem.name
let currentGroup = groups[groups.length - 1]
/**
* Create a new group if it's the first one, if the current item is a separator, or if the current group has some items but no title
* (meaning its items are rendered at the top level instead of in an expandable panel) while the current item has children and a wrapper.
*/
if (
!currentGroup ||
partialNavItem.type === 'separator' ||
(currentGroup.title === undefined &&
currentGroup.items.length > 0 &&
navItemHasChildren &&
!navItemHasNoWrapper)
) {
groups.push({
title: partialNavItem.type === 'separator' ? partialNavItem.title : undefined,
route: undefined,
href: undefined,
items: [],
})
}
if (partialNavItem.type === 'separator') return groups
currentGroup = groups[groups.length - 1]!
const getNavItem = (partialNavItem: PartialNavItem, ancestors: NavItem[] = []) => {
const navItem: NavItem = {
...partialNavItem,
children: [] as NavItem[],
group: currentGroup,
ancestors,
}
if (partialNavItem.children) {
navItem.children = partialNavItem.children.map((child) => getNavItem(child, [...ancestors, navItem]))
}
if (navItem.route === activeRoute) {
selectedNavItemRef.current = navItem
}
return navItem
}
const navItem = getNavItem(partialNavItem)
/**
* If the group has no title and the first item we want to add to it has children and a wrapper, give the item's title, route,
* href (if different from the first child's), and children to the group, instead of adding the item itself.
*/
if (
currentGroup.title === undefined &&
currentGroup.items.length === 0 &&
navItemHasChildren &&
!navItemHasNoWrapper
) {
currentGroup.title = navItem.title
currentGroup.route = navItem.route
const href = getNavItemHref(navItem)
currentGroup.href = href !== getNavItemHref(navItem.children[0]!) ? href : undefined
currentGroup.items.push(...navItem.children)
} else if (navItemHasNoWrapper) {
// Otherwise, if the first or next item to add to the group has no wrapper, just add its children to it
currentGroup.items.push(...navItem.children)
} else {
// Otherwise, add the item (which may or may not have children) to the group
currentGroup.items.push(navItem)
}
return groups
},
[],
)
return {
navItemGroups,
getNavItemSelected,
getNavItemExpanded,
setNavItemExpanded,
getNavItemIcon,
getNavItemHref,
}
}, [normalizedPages.directories, activeRoute, frontMatter.parentRouteKey, navItemExpandedByRoute])
const socialImage =
frontMatter.socialImage ??
(frontMatter.title
? // TODO: Use `vercel/og` instead
`https://thegraph-docs-opengraph-image.the-guild.dev?title=${encodeURI(frontMatter.title)}`
: null)
let seo: NextSeoProps = {
title: `${frontMatter.title ? `${frontMatter.title} | ` : ''}Docs | The Graph`,
description: frontMatter.description,
openGraph: {
title: frontMatter.title,
images: socialImage ? [{ url: socialImage }] : undefined,
},
}
if (frontMatter.seo) {
seo = merge(seo, frontMatter.seo)
}
const template: TemplateOptions = templateOptionsSchema.parse({
type: 'default',
...(typeof frontMatter.template === 'object' ? frontMatter.template : {}),
})
return (
<LayoutContext.Provider
value={{
filePath,
frontMatter,
template,
// TODO: Why is `timestamp` undefined?
lastUpdated: timestamp ? new Date(timestamp) : null,
readingTime: readingTime && readingTime.minutes > 1 ? readingTime : null,
remotePageUrl: frontMatter.remotePageUrl || null,
// TODO: Replace the following by a more cleaned up `navigation` object
flatDocsDirectories: normalizedPages.flatDocsDirectories,
activeIndex: normalizedPages.activeIndex,
activePath: normalizedPages.activePath,
}}
>
<NextSeo {...seo} />
<div
className={`
isolate ${/* Without this, the locale switcher's menu appears below the header */ ''}
[--graph-docs-content-padding:theme(spacing.6)]
[--graph-docs-footer-padding:theme(spacing.6)]
[--graph-docs-header-height:theme(spacing.16)]
[--graph-docs-header-padding:theme(spacing.3)]
[--graph-docs-layout-transition-duration:300ms]
[--graph-docs-sidebar-width:theme(spacing.72)]
[--graph-docs-viewport-height:calc(100dvh-var(--graph-docs-header-height))]
md:[--graph-docs-content-padding:theme(spacing.16)]
md:[--graph-docs-footer-padding:theme(spacing.8)]
md:[--graph-docs-header-padding:theme(spacing.6)]
`}
>
{/* TODO: Fix issue where the page scrolls up when elements in the header are tabbed to */}
<header
className={`
sticky top-0 z-10 grid h-[var(--graph-docs-header-height)] grid-cols-[auto_auto_1fr] items-center border-b border-space-1500 bg-space-1800
md:grid-cols-[var(--graph-docs-sidebar-width)_auto]
`}
>
<div className="contents md:flex md:items-center md:justify-center md:ps-[var(--graph-docs-header-padding)]">
<div className="flex items-center max-md:ml-2 md:me-auto">
<ButtonOrLink href="https://thegraph.com/">
<TheGraph size={7} color="white" />
</ButtonOrLink>
<span className="me-4.5 ms-3.5 h-5 w-px shrink-0 bg-space-1300" />
<ButtonOrLink
href="/"
className="text-body-large text-space-300 outline-offset-4 transition hover:text-white"
>
Docs
</ButtonOrLink>
</div>
<div className="order-first px-[var(--graph-docs-header-padding)] md:order-none md:px-0">
<ExperimentalButton
data-sidebar-expanded-on-mobile={sidebarExpandedOnMobile || undefined}
data-sidebar-expanded-on-desktop={sidebarExpandedOnDesktop || undefined}
onClick={() => {
if (mobile) {
setSidebarExpandedOnMobile((expanded) => !expanded)
} else {
if (!sidebarExpandedOnDesktop) {
setSidebarExpandedOnDesktop(true)
} else {
setSidebarExpandedOnDesktop(false)
setSidebarExpandedOnMobile(false)
}
}
}}
className="prop-variant-tertiary md:prop-variant-naked md:nested-icon:prop-size-6"
>
<SidebarSimple
alt={t('global.navigation.show')}
variant="regular"
className={`
max-md:in-clickable-[[data-sidebar-expanded-on-mobile]]:hidden
md:in-clickable-[[data-sidebar-expanded-on-desktop]]:hidden
`}
/>
<SidebarSimple
alt={t('global.navigation.hide')}
variant="fill"
className={`
max-md:in-clickable-not-[[data-sidebar-expanded-on-mobile]]:hidden
md:in-clickable-not-[[data-sidebar-expanded-on-desktop]]:hidden
`}
/>
</ExperimentalButton>
</div>
<div className="ms-3.5 h-[var(--graph-docs-header-height)] w-px shrink-0 bg-space-1500 max-md:hidden" />
</div>
<div className="flex min-w-auto items-center gap-2 px-[var(--graph-docs-header-padding)]">
{/* TODO: Add breadcrumbs */}
<DocSearch
apiKey={process.env.ALGOLIA_API_KEY ?? ''}
appId={process.env.ALGOLIA_APP_ID ?? ''}
indexName="thegraph-docs"
searchParameters={{
facetFilters: [`language:${locale}`],
}}
disableUserPersonalization={true}
transformItems={(items: any) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
items.map((item: any) => ({
...item,
url: item.url.replace('https://thegraph.com/docs', process.env.BASE_PATH ?? ''),
}))
}
hitComponent={DocSearchHit}
navigator={{
navigate({ itemUrl }: { itemUrl: string }) {
void router.push(removeBasePathFromUrl(itemUrl))
},
navigateNewTab({ itemUrl }: { itemUrl: string }) {
const windowReference = window.open(itemUrl, '_blank', 'noopener')
windowReference?.focus()
},
navigateNewWindow({ itemUrl }: { itemUrl: string }) {
window.open(itemUrl, '_blank', 'noopener')
},
}}
translations={translations.docsearch as NestedStrings}
>
{({ buttonRef, openModal }) => (
<div className="ms-auto xl:w-56">
<ExperimentalButton
ref={buttonRef}
variant="tertiary"
iconBefore={<MagnifyingGlass alt="" className="xl:hidden" />}
onClick={openModal}
className="peer w-full prop-hide-label-true md:prop-size-small md:prop-hide-label-false xl:prop-hide-label-true"
>
{t('docsearch.button.buttonText')}
</ExperimentalButton>
<div
className={`
absolute inset-0 flex items-center gap-1 px-2 text-12 text-space-500 transition pointer-events-none
peer-hover:text-space-200
max-xl:hidden
`}
>
<MagnifyingGlass size={3.5} alt="" />
<span aria-hidden="true" className="flex-1 truncate">
{t('docsearch.button.buttonText')}
</span>
<span>
<kbd>⌘</kbd> <kbd>K</kbd>
</span>
</div>
</div>
)}
</DocSearch>
<ExperimentalLocaleSwitcher>
{({ localeDetails }) => (
<ExperimentalButton
variant="tertiary"
iconBefore={<Translate alt={t('components.localeSwitcher.language')} />}
className="prop-hide-label-true md:prop-size-small md:prop-hide-label-false"
>
<span className="xl:hidden">{localeDetails.shortName}</span>
<span className="max-xl:hidden">{localeDetails.displayName}</span>
</ExperimentalButton>
)}
</ExperimentalLocaleSwitcher>
<ExperimentalAppLauncher
variant="tertiary"
className="prop-hide-label-true md:prop-size-small md:prop-hide-label-false"
/>
</div>
</header>
<div
data-sidebar-expanded-on-mobile={sidebarExpandedOnMobile || undefined}
data-sidebar-expanded-on-desktop={sidebarExpandedOnDesktop || undefined}
className={`
group/layout-sidebar-grid isolate grid grid-cols-[0_auto]
transition-[grid-template-columns]
duration-[var(--graph-docs-layout-transition-duration)]
md:data-[sidebar-expanded-on-desktop]:grid-cols-[var(--graph-docs-sidebar-width)_auto]
`}
>
<div
onClick={() => setSidebarExpandedOnMobile(false)}
className={`
absolute inset-0 z-10 hidden bg-space-1800/50 opacity-0 transition-[opacity,display]
duration-[var(--graph-docs-layout-transition-duration)] pointer-events-none transition-allow-discrete +:starting:opacity-0
max-md:group-data-[sidebar-expanded-on-mobile]/layout-sidebar-grid:block
max-md:group-data-[sidebar-expanded-on-mobile]/layout-sidebar-grid:opacity-100
max-md:group-data-[sidebar-expanded-on-mobile]/layout-sidebar-grid:pointer-events-auto
`}
/>
<div className="sticky top-[var(--graph-docs-header-height)] z-10 h-[var(--graph-docs-viewport-height)]">
<nav
aria-label={t('global.navigation.title')}
className={`
invisible absolute inset-y-0 end-0 w-[var(--graph-docs-sidebar-width)] border-e border-space-1500 bg-space-1800
transition-[transform,visibility]
duration-[var(--graph-docs-layout-transition-duration)]
max-md:group-data-[sidebar-expanded-on-mobile]/layout-sidebar-grid:visible
max-md:group-data-[sidebar-expanded-on-mobile]/layout-sidebar-grid:translate-x-full
md:group-data-[sidebar-expanded-on-desktop]/layout-sidebar-grid:visible
`}
>
<div className="gradient-mask-y h-full overflow-y-auto overflow-x-clip scrollbar-thin">
{navItemGroups.map((group, groupIndex) => {
if (group.items.length === 0) {
return null
}
const groupContent = group.items.map((groupItem) =>
(function renderNavItem(navItem) {
return (
<NavigationItem
key={navItem.name}
title={navItem.title}
icon={getNavItemIcon(navItem)}
href={getNavItemHref(navItem)}
selected={getNavItemSelected(navItem.route)}
expanded={getNavItemExpanded(navItem.route)}
onExpandedChange={(expanded, manual) => setNavItemExpanded(navItem.route, expanded, manual)}
children={
navItem.children.length > 0 ? <>{navItem.children.map(renderNavItem)}</> : undefined
}
/>
)
})(groupItem),
)
return (
<NavigationGroup key={groupIndex}>
{group.title !== undefined ? (
<NavigationItem
title={group.title}
icon={getNavItemIcon(group.items[0]!)}
href={group.href ?? getNavItemHref(group.items[0]!)}
selected={group.route ? getNavItemSelected(group.route) : undefined}
expanded={group.route ? getNavItemExpanded(group.route) : undefined}
onExpandedChange={
group.route
? (expanded, manual) => setNavItemExpanded(group.route!, expanded, manual)
: undefined
}
>
{groupContent}
</NavigationItem>
) : (
groupContent
)}
</NavigationGroup>
)
})}
</div>
</nav>
</div>
<div>
<MDXProvider
components={{
a: LinkWrapper,
blockquote: Callout,
// TODO: Get rid of the `as any`
code: ExperimentalCodeInline as any,
h1: Heading.H1,
h2: Heading.H2,
h3: Heading.H3,
h4: Heading.H4,
h5: Heading.H5,
h6: Heading.H6,
img: ImageWrapper,
// TODO: Fix "[Shiki] X instances have been created. Shiki is supposed to be used as a singleton" warnings
pre: CodeBlock,
// TODO: Build and use `ExperimentalTable`
table: Table,
VideoEmbed,
wrapper: MDXContent,
}}
>
{children}
</MDXProvider>
<footer className="border-t border-space-1500 px-[var(--graph-docs-footer-padding)] py-8">
<nav className="flex flex-col gap-6 md:flex-row md:items-start">
<div className="flex flex-1 flex-wrap items-center gap-x-6 gap-y-4 md:py-2">
<ExperimentalNavLink href="https://thegraph.com/" target="_self" variant="secondary">
The Graph
</ExperimentalNavLink>
<ExperimentalNavLink href="https://status.thegraph.com/" target="_self" variant="secondary">
{t('components.globalFooter.status')}
</ExperimentalNavLink>
<ExperimentalNavLink href="https://testnet.thegraph.com/" target="_self" variant="secondary">
{t('components.globalFooter.testnet')}
</ExperimentalNavLink>
<ExperimentalNavLink href="https://thegraph.com/brand/" target="_self" variant="secondary">
{t('components.globalFooter.brandAssets')}
</ExperimentalNavLink>
<ExperimentalNavLink href="https://forum.thegraph.com/" target="_self" variant="secondary">
{t('components.globalFooter.forum')}
</ExperimentalNavLink>
<ExperimentalNavLink href="https://immunefi.com/bounty/thegraph/" target="_self" variant="secondary">
{t('components.globalFooter.security')}
</ExperimentalNavLink>
<ExperimentalNavLink href="https://thegraph.com/privacy/" target="_self" variant="secondary">
{t('components.globalFooter.privacyPolicy')}
</ExperimentalNavLink>
<ExperimentalNavLink href="https://thegraph.com/terms-of-service/" target="_self" variant="secondary">
{t('components.globalFooter.termsOfService')}
</ExperimentalNavLink>
</div>
<div className="flex items-center gap-2">
<ExperimentalButton
href="https://github.com/graphprotocol"
target="_self"
variant="tertiary"
size="small"
className="text-space-700"
>
<SocialGitHub />
</ExperimentalButton>
<ExperimentalButton href="https://x.com/graphprotocol" target="_self" variant="tertiary" size="small">
<SocialX />
</ExperimentalButton>
<ExperimentalButton
href="https://discord.gg/graphprotocol"
target="_self"
variant="tertiary"
size="small"
>
<SocialDiscord />
</ExperimentalButton>
<ExperimentalButton href="https://t.me/graphprotocol" target="_self" variant="tertiary" size="small">
<SocialTelegram />
</ExperimentalButton>
</div>
</nav>
</footer>
</div>
</div>
</div>
</LayoutContext.Provider>
)
}
const LinkContext = createContext<{} | null>(null)
function LinkWrapper({ children, ...props }: ComponentProps<'a'>) {
if ('data-wrapping-image' in props) {
return (
<LinkContext.Provider value={{}}>
<a {...props}>{children}</a>
</LinkContext.Provider>
)
}
return <ExperimentalLink {...(props as ExperimentalLinkProps.ExternalLinkProps)}>{children}</ExperimentalLink>
}
interface ImageWrapperProps extends Omit<ComponentProps<'img'>, 'src'> {
src?: ComponentProps<typeof NextImage>['src']
placeholder?: ComponentProps<typeof NextImage>['placeholder']
}
function ImageWrapper({ src: passedSrc, placeholder: _placeholder, className, ...props }: ImageWrapperProps) {
const linkContext = useContext(LinkContext)
const src =
typeof passedSrc === 'object' ? ('default' in passedSrc ? passedSrc.default.src : passedSrc.src) : passedSrc
if (linkContext || 'data-inline-image' in props) {
return <img src={src} alt="" className={classNames(['inline-block', className])} {...props} />
}
return <Image src={src} className={className} {...props} />
}