1 import React from 'react'
2 import {BaseStyles, themeGet, Box} from '@primer/react'
3 import {createGlobalStyle} from 'styled-components'
4 import Slugger from 'github-slugger'
5 import Header from './components/header'
6 import Sidebar from './components/sidebar'
7 import {SkipBox, SkipLink} from './components/skip-nav'
8 import {SKIP_TO_CONTENT_ID, SKIP_TO_SEARCH_ID} from './constants'
9
10 import {PageProvider} from './hooks/use-page'
11 import Layout from './layout'
12
13 const GlobalStyles = createGlobalStyle`
14 body {
15 color: ${themeGet('colors.fg.default')};
16 background-color: ${themeGet('colors.canvas.default')};
17 }
18 `
19
20 const PageElement = ({element, props}) => {
21 const page = {
22 pageContext: props.pageContext,
23 frontmatter: props.pageContext?.frontmatter || {},
24 location: props.location,
25 path: props.location.pathname,
26 slugger: new Slugger(),
27 }
28 return (
29 <BaseStyles>
30 <GlobalStyles />
31 <SkipBox>
32 <SkipLink href={`#${SKIP_TO_SEARCH_ID}`}>Skip to search</SkipLink>
33 <SkipLink href={`#${SKIP_TO_CONTENT_ID}`}>Skip to content</SkipLink>
34 </SkipBox>
35 <PageProvider value={page}>
36 <Box sx={{display: 'flex', flexDirection: 'column', minHeight: '100vh'}}>
37 <Header />
38 <Box sx={{zIndex: 0, display: 'flex', flex: '1 1 auto', flexDirection: 'row'}} role="main">
39 <Box sx={{display: ['none', null, null, 'block']}}>
40 <Sidebar />
41 </Box>
42 <Layout>{element}</Layout>
43 </Box>
44 </Box>
45 </PageProvider>
46 </BaseStyles>
47 )
48 }
49
50 export default PageElement