This repository has been archived by the owner on Jan 24, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathindex.js
68 lines (64 loc) · 1.81 KB
/
index.js
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
/** @jsx jsx */
import { jsx, Box, Flex, useColorMode } from 'theme-ui'
import { useConfig, useCurrentDoc } from 'docz'
import * as styles from './styles'
import { Edit, Menu, Sun, Github } from '../Icons'
import { Logo } from '../Logo'
export const Header = props => {
const { onOpen } = props
const {
repository,
themeConfig: { showDarkModeSwitch, showMarkdownEditButton },
} = useConfig()
const { edit = true, ...doc } = useCurrentDoc()
const [colorMode, setColorMode] = useColorMode()
const toggleColorMode = () => {
setColorMode(colorMode === 'light' ? 'dark' : 'light')
}
return (
<div sx={styles.wrapper} data-testid="header">
<Box sx={styles.menuIcon}>
<button sx={styles.menuButton} onClick={onOpen}>
<Menu size={25} />
</button>
</Box>
<div sx={styles.innerContainer}>
<Logo />
<Flex>
{repository && (
<Box sx={{ mr: 2 }}>
<a
href={repository}
sx={styles.headerButton}
target="_blank"
rel="noopener noreferrer"
>
<Github size={15} />
</a>
</Box>
)}
{showDarkModeSwitch && (
<button
sx={styles.headerButton}
onClick={toggleColorMode}
aria-label={`Switch to ${colorMode} mode`}
>
<Sun size={15} />
</button>
)}
</Flex>
{showMarkdownEditButton && edit && doc.link && (
<a
sx={styles.editButton}
href={doc.link}
target="_blank"
rel="noopener noreferrer"
>
<Edit width={14} />
<Box sx={{ pl: 2 }}>Edit page</Box>
</a>
)}
</div>
</div>
)
}