|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { FrameworkSelect } from "components/framework-select" |
| 4 | +import { MdxFooter } from "components/mdx-footer" |
| 5 | +import { EditPageLink } from "components/mdx/edit-page-link" |
| 6 | +import { Search } from "components/search-dialog" |
| 7 | +import { Sidebar } from "components/sidebar" |
| 8 | +import { SkipNavContent, SkipNavLink } from "components/skip-nav" |
| 9 | +import { TableOfContents } from "components/toc" |
| 10 | +import { TopNavigation } from "components/top-navigation" |
| 11 | +import { Box, Spacer, styled } from "styled-system/jsx" |
| 12 | + |
| 13 | +type DocsLayoutProps = { |
| 14 | + children: React.ReactNode |
| 15 | + doc: any |
| 16 | + toc?: { |
| 17 | + title?: string |
| 18 | + data?: any[] |
| 19 | + getSlug?: (slug: string) => string |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +export default function DocsLayout(props: DocsLayoutProps) { |
| 24 | + const { children, doc, toc } = props |
| 25 | + const tableOfContent = toc?.data ?? doc.frontmatter?.toc ?? [] |
| 26 | + const hideToc = tableOfContent.length < 2 |
| 27 | + |
| 28 | + return ( |
| 29 | + <Box> |
| 30 | + <SkipNavLink>Skip to main content</SkipNavLink> |
| 31 | + <TopNavigation /> |
| 32 | + <styled.div pt="10"> |
| 33 | + <SkipNavContent /> |
| 34 | + <Box maxW="8xl" mx="auto" px={{ sm: "6", base: "4", md: "8" }}> |
| 35 | + <Box |
| 36 | + display={{ base: "none", lg: "block" }} |
| 37 | + position="fixed" |
| 38 | + zIndex={20} |
| 39 | + bottom="0" |
| 40 | + top="4rem" |
| 41 | + left="max(0px, calc(50% - 45rem - calc(var(--scrollbar-width, 0px) / 2)))" |
| 42 | + right="auto" |
| 43 | + width="19.5rem" |
| 44 | + pb="10" |
| 45 | + px="8" |
| 46 | + overflowY="auto" |
| 47 | + overscrollBehavior="contain" |
| 48 | + > |
| 49 | + <Box position="relative"> |
| 50 | + <Box position="sticky" top="0" bg="bg.subtle" pb="8"> |
| 51 | + <Spacer height="10" bg="transparent" /> |
| 52 | + <Search /> |
| 53 | + <Spacer mt="px" height="5" bg="transparent" /> |
| 54 | + <FrameworkSelect /> |
| 55 | + </Box> |
| 56 | + <Sidebar /> |
| 57 | + </Box> |
| 58 | + </Box> |
| 59 | + |
| 60 | + <Box |
| 61 | + as="main" |
| 62 | + className="mdx-content" |
| 63 | + pl={{ lg: "19.5rem" }} |
| 64 | + pt="4" |
| 65 | + pr={{ xl: "16" }} |
| 66 | + > |
| 67 | + <Box mr={{ xl: "15.5rem" }}> |
| 68 | + {children} |
| 69 | + {doc?.editUrl && ( |
| 70 | + <EditPageLink href={doc.editUrl}> |
| 71 | + Edit this page on GitHub |
| 72 | + </EditPageLink> |
| 73 | + )} |
| 74 | + <MdxFooter /> |
| 75 | + </Box> |
| 76 | + </Box> |
| 77 | + |
| 78 | + <Box |
| 79 | + py="10" |
| 80 | + px="8" |
| 81 | + overflowY="auto" |
| 82 | + position="fixed" |
| 83 | + top="3.8rem" |
| 84 | + bottom="0" |
| 85 | + right="max(0px,calc(50% - 45rem + calc(var(--scrollbar-width, 0px) / 2)))" |
| 86 | + display={{ base: "none", xl: "block" }} |
| 87 | + width="19.5rem" |
| 88 | + visibility={hideToc ? "hidden" : undefined} |
| 89 | + > |
| 90 | + <TableOfContents |
| 91 | + title={toc?.title} |
| 92 | + data={tableOfContent} |
| 93 | + getSlug={toc?.getSlug} |
| 94 | + /> |
| 95 | + </Box> |
| 96 | + </Box> |
| 97 | + </styled.div> |
| 98 | + </Box> |
| 99 | + ) |
| 100 | +} |
0 commit comments