forked from chakra-ui/chakra-ui-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
70419cb
commit 1cb6d5f
Showing
10 changed files
with
156 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import PageContainer from 'components/page-container' | ||
import Sidebar from 'components/sidebar/sidebar' | ||
import componentsSidebar from 'configs/components.sidebar.json' | ||
import gettingStartedSidebar from 'configs/getting-started.sidebar.json' | ||
import hooksSidebar from 'configs/hooks.sidebar.json' | ||
import styledSystemSidebar from 'configs/styled-system.sidebar.json' | ||
import tutorialSidebar from 'configs/tutorial.sidebar.json' | ||
import communitySidebar from 'configs/community.sidebar.json' | ||
import semverRSort from 'semver/functions/rsort' | ||
import { ReactNode } from 'react' | ||
import { RouteItem } from 'utils/get-route-context' | ||
import { Frontmatter } from 'src/types/frontmatter' | ||
import { List, ListItem } from '@chakra-ui/react' | ||
import SidebarLink from 'components/sidebar/sidebar-link' | ||
import { allChangelogs } from 'contentlayer/generated' | ||
import TocNav from 'components/toc-nav' | ||
import { t } from 'utils/i18n' | ||
|
||
export function getRoutes(slug: string): RouteItem[] { | ||
// for home page, use docs sidebar | ||
if (slug === '/') { | ||
return gettingStartedSidebar.routes as RouteItem[] | ||
} | ||
|
||
const configMap = { | ||
'/getting-started': gettingStartedSidebar, | ||
'/docs/styled-system': styledSystemSidebar, | ||
'/docs/hooks': hooksSidebar, | ||
'/docs/components': componentsSidebar, | ||
'/tutorial': tutorialSidebar, | ||
'/community': communitySidebar, | ||
} | ||
|
||
const [, sidebar] = | ||
Object.entries(configMap).find(([path]) => slug.startsWith(path)) ?? [] | ||
|
||
const routes = sidebar?.routes ?? [] | ||
return routes as RouteItem[] | ||
} | ||
|
||
export function getVersions(): RouteItem[] { | ||
return semverRSort( | ||
allChangelogs | ||
.filter(({ version }) => version.startsWith('2.')) | ||
.map(({ version }) => version), | ||
).map((version) => ({ | ||
title: `v${version}`, | ||
path: `/changelog/${version}`, | ||
})) | ||
} | ||
|
||
interface MDXLayoutProps { | ||
frontmatter: Frontmatter | ||
children: ReactNode | ||
hideToc?: boolean | ||
maxWidth?: string | ||
} | ||
|
||
export default function MDXLayout(props: MDXLayoutProps) { | ||
const { frontmatter, children, maxWidth } = props | ||
|
||
const routes = getRoutes(frontmatter.slug) | ||
const versions = getVersions() | ||
|
||
return ( | ||
<PageContainer | ||
hideToc={true} | ||
maxWidth={maxWidth} | ||
frontmatter={frontmatter} | ||
leftSidebar={<Sidebar routes={routes} />} | ||
rightSidebar={ | ||
<TocNav title={t('component.table-of-content.versions')}> | ||
<List mt={2}> | ||
{versions.map(({ title, path }) => ( | ||
<ListItem key={path}> | ||
<SidebarLink href={path}>{title}</SidebarLink> | ||
</ListItem> | ||
))} | ||
</List> | ||
</TocNav> | ||
} | ||
> | ||
{children} | ||
</PageContainer> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Box, BoxProps, Text } from '@chakra-ui/react' | ||
|
||
export default function TocNav({ children, title, ...rest }: BoxProps) { | ||
return ( | ||
<Box | ||
as='nav' | ||
aria-labelledby='toc-title' | ||
width='16rem' | ||
flexShrink={0} | ||
display={{ base: 'none', xl: 'block' }} | ||
position='sticky' | ||
py='10' | ||
pr='4' | ||
top='6rem' | ||
right='0' | ||
fontSize='sm' | ||
alignSelf='start' | ||
maxHeight='calc(100vh - 8rem)' | ||
overflowY='auto' | ||
sx={{ overscrollBehavior: 'contain' }} | ||
{...rest} | ||
> | ||
{title && ( | ||
<Text | ||
as='h2' | ||
id='toc-title' | ||
textTransform='uppercase' | ||
fontWeight='bold' | ||
fontSize='xs' | ||
color='gray.700' | ||
_dark={{ color: 'gray.400' }} | ||
letterSpacing='wide' | ||
> | ||
{title} | ||
</Text> | ||
)} | ||
{children} | ||
</Box> | ||
) | ||
} |