Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | import {Box, Flex, Link, StyledOcticon, Sticky} from '@primer/components'
import {
ChevronRightIcon,
MarkGithubIcon,
SearchIcon,
ThreeBarsIcon,
} from '@primer/octicons-react'
import {Link as GatsbyLink} from 'gatsby'
import React from 'react'
import {ThemeContext} from 'styled-components'
import primerNavItems from '../primer-nav.yml'
import useSiteMetadata from '../use-site-metadata'
import DarkButton from './dark-button'
import MobileSearch from './mobile-search'
import NavDrawer, {useNavDrawerState} from './nav-drawer'
import NavDropdown, {NavDropdownItem} from './nav-dropdown'
import Search from './search'
import NpmLogo from './npm-logo'
export const HEADER_HEIGHT = 66
function Header({isSearchEnabled}) {
const theme = React.useContext(ThemeContext)
const [isNavDrawerOpen, setIsNavDrawerOpen] = useNavDrawerState(
theme.breakpoints[2],
)
const [isMobileSearchOpen, setIsMobileSearchOpen] = React.useState(false)
const siteMetadata = useSiteMetadata()
const logoStyle = { 'color': '#cb0000' };
const titleStyle = { 'color': '#dddddd', 'font-weight': '600' };
return (
<Sticky>
<Flex
height={HEADER_HEIGHT}
px={[3, null, null, 4]}
alignItems="center"
justifyContent="space-between"
bg="#333333"
>
<Flex alignItems="center">
<Link as={GatsbyLink} to="/" style={logoStyle} mr={3}>
<NpmLogo size="32" />
</Link>
<Link as={GatsbyLink} to="/" style={titleStyle} mr={4}>
{siteMetadata.title}
</Link>
{isSearchEnabled ? (
<Box display={['none', null, null, 'block']} ml={4}>
<Search />
</Box>
) : null}
</Flex>
<Flex>
<Box display={['none', null, null, 'block']}>
<PrimerNavItems items={primerNavItems} />
</Box>
<Flex display={['flex', null, null, 'none']}>
{isSearchEnabled ? (
<>
<DarkButton
aria-label="Search"
aria-expanded={isMobileSearchOpen}
onClick={() => setIsMobileSearchOpen(true)}
>
<SearchIcon />
</DarkButton>
<MobileSearch
isOpen={isMobileSearchOpen}
onDismiss={() => setIsMobileSearchOpen(false)}
/>
</>
) : null}
<DarkButton
aria-label="Menu"
aria-expanded={isNavDrawerOpen}
onClick={() => setIsNavDrawerOpen(true)}
ml={3}
>
<ThreeBarsIcon />
</DarkButton>
<NavDrawer
isOpen={isNavDrawerOpen}
onDismiss={() => setIsNavDrawerOpen(false)}
/>
</Flex>
</Flex>
</Flex>
</Sticky>
)
}
Header.defaultProps = {
isSearchEnabled: true,
}
function PrimerNavItems({items}) {
return (
<Flex alignItems="center" color="gray.2">
{items.map((item, index) => {
if (item.children) {
return (
<Box ml={4} key={index}>
<NavDropdown title={item.title}>
{item.children.map((child) => (
<NavDropdownItem key={child.title} href={child.url}>
{child.title}
</NavDropdownItem>
))}
</NavDropdown>
</Box>
)
}
return (
<Link
key={index}
href={item.url}
display="block"
color="inherit"
ml={4}
>
{item.title}
</Link>
)
})}
</Flex>
)
}
export default Header
|