Skip to content

Commit f21bdf6

Browse files
Add Layout component with sticky header (#88)
* imported Layout component * removed container from index file * updated headerSticky prop to true in docs * Fix the build * removed unnecessary div * removed unnecessary div Co-authored-by: Benoît Rouleau <[email protected]>
1 parent 8550593 commit f21bdf6

File tree

11 files changed

+90
-118
lines changed

11 files changed

+90
-118
lines changed

components/Container.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

components/EditPageLink.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
useUniqueId,
1212
} from '@edgeandnode/components'
1313

14-
import { NavContext } from '@/layout'
14+
import { NavContext } from '@/layout/NavContext'
1515
import { Link } from '@/components'
1616
import { useI18n } from '@/i18n'
1717

components/Heading.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as VisuallyHidden from '@radix-ui/react-visually-hidden'
44
import { useInView } from 'react-intersection-observer'
55
import { useDebounce } from 'react-use'
66

7-
import { DocumentContext } from '@/layout'
7+
import { DocumentContext } from '@/layout/DocumentContext'
88
import { LinkInline } from '@/components'
99
import { useI18n } from '@/i18n'
1010

components/NavTree.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ const NavTreeItem = ({
101101
)
102102
}
103103

104-
export const NavTreeGroupContext = createContext(null) as Context<{
105-
active: boolean
106-
open: boolean
107-
} | null>
104+
export const NavTreeGroupContext = createContext({
105+
active: false,
106+
open: false,
107+
})
108108

109109
const NavTreeGroup = ({ active = false, children, ...props }: NavTreeGroupProps) => {
110110
const [open, setOpen] = useState(active)
@@ -121,7 +121,7 @@ const NavTreeGroup = ({ active = false, children, ...props }: NavTreeGroupProps)
121121

122122
const NavTreeGroupHeading = ({ children, buttonProps = {}, ...props }: NavTreeGroupHeadingProps) => {
123123
const { sx: buttonSx, ...buttonOtherProps } = buttonProps
124-
const context = useContext(NavTreeGroupContext)!
124+
const context = useContext(NavTreeGroupContext)
125125
const { t } = useI18n()
126126

127127
return (
@@ -160,7 +160,7 @@ const NavTreeGroupHeading = ({ children, buttonProps = {}, ...props }: NavTreeGr
160160
}
161161

162162
const NavTreeGroupContent = ({ children, ...props }: NavTreeGroupContentProps) => {
163-
const context = useContext(NavTreeGroupContext)!
163+
const context = useContext(NavTreeGroupContext)
164164
return (
165165
<Collapsible.Content
166166
sx={{

components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from './Blockquote'
22
export * from './Code'
3-
export * from './Container'
43
export * from './Difficulty'
54
export * from './EditPageLink'
65
export * from './Heading'

layout/DocumentContext.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createContext, Context } from 'react'
2+
3+
export type Frontmatter = {
4+
title?: string
5+
}
6+
7+
export type OutlineItem = {
8+
id: string
9+
title: string
10+
level: 1 | 2 | 3 | 4 | 5 | 6
11+
}
12+
13+
export type DocumentContextProps = {
14+
frontmatter?: Frontmatter
15+
outline: OutlineItem[]
16+
markOutlineItem: (id: string, inOrAboveView: boolean) => void
17+
highlightedOutlineItemId: string | null
18+
}
19+
20+
export const DocumentContext = createContext(null) as Context<DocumentContextProps | null>

layout/Layout.tsx

Lines changed: 0 additions & 50 deletions
This file was deleted.

layout/MDXLayout.tsx

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ import { ThemeUIStyleObject } from 'theme-ui'
55
import { NewGDSDivider, NewGDSDividerProps, Spacing, Flex } from '@edgeandnode/components'
66
import { useSet } from 'react-use'
77

8-
import { NavItem, NavItemPage } from '@/navigation'
9-
import { MDXLayoutNav, MDXLayoutPagination, MDXLayoutOutline } from '@/layout'
8+
import {
9+
NavContext,
10+
NavContextProps,
11+
DocumentContext,
12+
DocumentContextProps,
13+
MDXLayoutNav,
14+
MDXLayoutPagination,
15+
MDXLayoutOutline,
16+
} from '@/layout'
1017
import {
1118
Blockquote,
1219
CodeBlock,
@@ -60,36 +67,6 @@ const mdxStyles = {
6067
},
6168
} as ThemeUIStyleObject
6269

63-
export type NavContextProps = {
64-
pagePath: string
65-
navItems: NavItem[]
66-
pageNavItems: NavItemPage[]
67-
previousPage: NavItemPage | null
68-
currentPage: NavItemPage | null
69-
nextPage: NavItemPage | null
70-
}
71-
72-
export const NavContext = createContext(null) as Context<NavContextProps | null>
73-
74-
export type Frontmatter = {
75-
title?: string
76-
}
77-
78-
export type OutlineItem = {
79-
id: string
80-
title: string
81-
level: 1 | 2 | 3 | 4 | 5 | 6
82-
}
83-
84-
export type DocumentContextProps = {
85-
frontmatter?: Frontmatter
86-
outline: OutlineItem[]
87-
markOutlineItem: (id: string, inOrAboveView: boolean) => void
88-
highlightedOutlineItemId: string | null
89-
}
90-
91-
export const DocumentContext = createContext(null) as Context<DocumentContextProps | null>
92-
9370
export type MDXLayoutProps = PropsWithChildren<
9471
Pick<NavContextProps, 'pagePath' | 'navItems'> & Pick<DocumentContextProps, 'frontmatter' | 'outline'>
9572
>

layout/NavContext.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { createContext, Context } from 'react'
2+
3+
import { NavItem, NavItemPage } from '@/navigation'
4+
5+
export type NavContextProps = {
6+
pagePath: string
7+
navItems: NavItem[]
8+
pageNavItems: NavItemPage[]
9+
previousPage: NavItemPage | null
10+
currentPage: NavItemPage | null
11+
nextPage: NavItemPage | null
12+
}
13+
14+
export const NavContext = createContext(null) as Context<NavContextProps | null>

layout/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export * from './Layout'
1+
export * from './DocumentContext'
2+
export * from './NavContext'
23
export * from './MDXLayout'
34
export * from './MDXLayoutNav'
45
export * from './MDXLayoutPagination'

0 commit comments

Comments
 (0)