-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
…-carbon
- Loading branch information
Showing
25 changed files
with
234 additions
and
19 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
20 changes: 20 additions & 0 deletions
20
packages/gatsby-theme-carbon/src/components/HeaderNav/HeaderNav.js
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,20 @@ | ||
import React from 'react'; | ||
|
||
import { HeaderNavigation } from 'carbon-components-react/lib/components/UIShell'; | ||
import HeaderNavItem from './HeaderNavItem'; | ||
|
||
import { useNavItems } from '../../util/NavItems'; | ||
|
||
const HeaderNav = () => { | ||
const navItems = useNavItems(); | ||
|
||
return ( | ||
<HeaderNavigation aria-label="Carbon Design System"> | ||
{navItems.map(({pages, title}) => ( | ||
<HeaderNavItem items={pages} category={title} key={title} /> | ||
))} | ||
</HeaderNavigation> | ||
); | ||
}; | ||
|
||
export default HeaderNav; |
95 changes: 95 additions & 0 deletions
95
packages/gatsby-theme-carbon/src/components/HeaderNav/HeaderNavItem.js
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,95 @@ | ||
import React, { useContext } from 'react'; | ||
|
||
import { Link } from 'gatsby'; | ||
import { Location } from '@reach/router'; | ||
import cx from 'classnames'; | ||
|
||
import { | ||
HeaderMenu, | ||
HeaderMenuItem, | ||
} from 'carbon-components-react/lib/components/UIShell'; | ||
import styles from '../Header/Header.module.scss'; | ||
|
||
import NavContext from '../../util/context/NavContext'; | ||
import usePathprefix from '../../util/hooks/usePathprefix'; | ||
|
||
const HeaderNavItem = (props) => { | ||
const { items, category } = props; | ||
const { toggleNavState } = useContext(NavContext); | ||
const closeLeftNav = () => toggleNavState('leftNavIsOpen', 'close'); | ||
const pathPrefix = usePathprefix(); | ||
|
||
return ( | ||
<Location> | ||
{({ location }) => { | ||
const pathname = pathPrefix | ||
? location.pathname.replace(pathPrefix, '') | ||
: location.pathname; | ||
|
||
const isActive = items.some( | ||
(item) => item.path.split('/')[1] === pathname.split('/')[1] | ||
); | ||
|
||
if (items.length === 1) { | ||
return ( | ||
<HeaderMenuItem | ||
onClick={closeLeftNav} | ||
icon={<span>dummy icon</span>} | ||
element={Link} | ||
isActive={isActive} | ||
to={`${items[0].path}`} | ||
> | ||
{category} | ||
</HeaderMenuItem> | ||
); | ||
} | ||
return ( | ||
<HeaderMenu | ||
icon={<span>dummy icon</span>} | ||
isActive={isActive} // TODO similar categories | ||
defaultExpanded={isActive} | ||
title={category} | ||
menuLinkName={category} | ||
> | ||
<TabItems | ||
onClick={closeLeftNav} | ||
items={items} | ||
pathname={pathname} | ||
/> | ||
</HeaderMenu> | ||
); | ||
}} | ||
</Location> | ||
); | ||
}; | ||
|
||
const TabItems = ({ items, pathname, onClick }) => | ||
items.map((item, i) => { | ||
const hasActiveTab = | ||
item.path.split('/') > 3 | ||
? item.path.split('/')[3] === pathname.split('/')[3] | ||
: item.path.split('/')[2] === pathname.split('/')[2]; | ||
|
||
return ( | ||
<HeaderMenuItem | ||
to={`${item.path}`} | ||
className={cx({ | ||
[styles.linkText__dark]: pathname === '/', | ||
})} | ||
onClick={onClick} | ||
element={Link} | ||
isActive={hasActiveTab} | ||
key={i} | ||
> | ||
<span | ||
className={cx(styles.linkText, { | ||
[styles.linkText__active]: hasActiveTab, | ||
})} | ||
> | ||
{item.title} | ||
</span> | ||
</HeaderMenuItem> | ||
); | ||
}); | ||
|
||
export default HeaderNavItem; |
3 changes: 3 additions & 0 deletions
3
packages/gatsby-theme-carbon/src/components/HeaderNav/index.js
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,3 @@ | ||
import HeaderNav from './HeaderNav'; | ||
|
||
export default HeaderNav; |
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
Oops, something went wrong.