Files
react.dev/src/utils/createLink.js
Alexander Nanberg 71b03486c0 Upgrade to Gatsby v2 (#1104)
* Upgrade to Gatsby v2

* Remove unnecessary polyfills since gatsby already provides them

* Move global styles to gatsby-browser

* Add fb comment and convert to cjs

* Revert to use pageQuery again

* Add back html.js

* Update dependencies

* Move TitleAndMetaTags

* Replace glamor/reset with normalize.css which fixes style order in prod

* Prettier formatting

* Remove unused types

* Remove old layout

* Fix versions link

* Update deps

* Update deps

* Remove hack since it's no longer needed

* Update dependencies

* Fix build error

* Fix prettier config resolution

* Update gatsby

* Remove custom onCreatePage logic

* Update dependencies

* Fix build

* Update dependencies

* prettier formatting

* update dependencies

* add custom babel config for flow

* upgrade dependencies

* update dependencies

* use stable gatsby release
2018-09-19 13:11:19 +01:00

134 lines
2.4 KiB
JavaScript

/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* @emails react-core
* @flow
*/
import {Link} from 'gatsby';
import React from 'react';
import ExternalLinkSvg from 'templates/components/ExternalLinkSvg';
import slugify from 'utils/slugify';
import {colors, media} from 'theme';
import type {Node} from 'react';
type CreateLinkBaseProps = {
isActive: boolean,
item: Object,
section: Object,
};
const createLinkBlog = ({
isActive,
item,
section,
}: CreateLinkBaseProps): Node => {
return (
<Link css={[linkCss, isActive && activeLinkCss]} to={item.id}>
{isActive && <span css={activeLinkBefore} />}
{item.title}
</Link>
);
};
const createLinkCommunity = ({
isActive,
item,
section,
}: CreateLinkBaseProps): Node => {
if (item.href) {
return (
<a css={[linkCss]} href={item.href} target="_blank" rel="noopener">
{item.title}
<ExternalLinkSvg
cssProps={{
verticalAlign: -2,
display: 'inline-block',
marginLeft: 5,
color: colors.subtle,
}}
/>
</a>
);
}
return createLinkDocs({
isActive,
item,
section,
});
};
const createLinkDocs = ({
isActive,
item,
section,
}: CreateLinkBaseProps): Node => {
return (
<Link
css={[linkCss, isActive && activeLinkCss]}
to={slugify(item.id, section.directory)}>
{isActive && <span css={activeLinkBefore} />}
{item.title}
</Link>
);
};
type CreateLinkTutorialProps = {
onLinkClick: Function,
} & CreateLinkBaseProps;
const createLinkTutorial = ({
isActive,
item,
onLinkClick,
section,
}: CreateLinkTutorialProps): Node => {
return (
<Link
css={[linkCss, isActive && activeLinkCss]}
onClick={onLinkClick}
to={item.href}>
{isActive && <span css={activeLinkBefore} />}
{item.title}
</Link>
);
};
const activeLinkCss = {
fontWeight: 700,
};
const activeLinkBefore = {
width: 4,
height: 25,
borderLeft: `4px solid ${colors.brand}`,
paddingLeft: 16,
position: 'absolute',
left: 0,
marginTop: -3,
[media.greaterThan('largerSidebar')]: {
left: 15,
},
};
const linkCss = {
color: colors.text,
display: 'inline-block',
borderBottom: '1px solid transparent',
transition: 'border 0.2s ease',
marginTop: 5,
'&:hover': {
color: colors.subtle,
},
};
export {
createLinkBlog,
createLinkCommunity,
createLinkDocs,
createLinkTutorial,
};