Skip to content

Commit

Permalink
fix: update lefnav icon logic (#196)
Browse files Browse the repository at this point in the history
* fix: update icon logic. closes #195

* update prop name
  • Loading branch information
vpicone authored Jun 25, 2019
1 parent b908aa6 commit 2d39cbf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React from 'react';
import ResourceLinks from 'gatsby-theme-carbon/src/components/LeftNav/ResourceLinks';

const links = [
{ title: 'Github', href: 'https://github.com' },
{ title: 'Resources', href: '/resources' },
{ title: 'Storybook', href: 'https://react.carbondesignsystem.com' },
];

const CustomResources = () => <ResourceLinks links={links} />;
// shouldOpenNewTabs: true if outbound links should open in a new tab
const CustomResources = () => <ResourceLinks shouldOpenNewTabs links={links} />;

export default CustomResources;
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,20 @@
.current-item .current-item-text {
color: #171717;
}

.resource-link {
&:first-of-type {
margin-top: $spacing-05;
}
}
// Moves icons to the right
.outboundLink {
flex-direction: row-reverse;
justify-content: space-between;
}

// Icons
.outboundLink div {
display: inline-block !important;
flex: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,53 @@ import React from 'react';
import { SideNavLink } from 'carbon-components-react/lib/components/UIShell';
import { Link } from 'gatsby';
import LaunchIcon from '@carbon/icons-react/es/launch/16';
import cx from 'classnames';
import PropTypes from 'prop-types';

const LeftNavResourceLinks = ({ links }) =>
links ? (
import { resourceLink, outboundLink } from './LeftNav.module.scss';

const LeftNavResourceLinks = ({ links, shouldOpenNewTabs }) => {
if (!links) return null;

const shouldOpenNewTabsProps = {
...(shouldOpenNewTabs && { rel: 'noopener noreferrer', target: '_blank' }),
};

return (
<>
<hr className="bx--side-nav__divider" />
{links.map((link, i) => (
<SideNavLink
key={i}
style={{ marginTop: i === 0 ? '1rem' : 0 }}
icon={<LaunchIcon />}
href={link.href}
className="bx--side-nav--website-link"
element={!link.href.includes('http') ? Link : 'a'}
>
{link.title}
</SideNavLink>
))}
{links.map(({ title, href, ...rest }, i) => {
const outbound = !/^\/(?!\/)/.test(href);
return (
<SideNavLink
key={i}
style={{ marginTop: i === 0 ? '1rem' : 0 }}
icon={<LaunchIcon />}
// eslint-disable-next-line jsx-a11y/aria-proptypes
aria-current=""
to={href}
href={href}
className={cx(resourceLink, { [outboundLink]: outbound })}
element={outbound ? 'a' : Link}
{...shouldOpenNewTabsProps}
>
{title}
</SideNavLink>
);
})}
</>
) : null;
);
};

LeftNavResourceLinks.propTypes = {
links: PropTypes.arrayOf(
PropTypes.objectOf({
title: PropTypes.string,
href: PropTypes.string,
})
),
// true if outbound links should open in a new tab
shouldOpenNewTabs: PropTypes.bool,
};

export default LeftNavResourceLinks;

1 comment on commit 2d39cbf

@vercel
Copy link

@vercel vercel bot commented on 2d39cbf Jun 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.