Skip to content

Commit

Permalink
Merge branch 'master' of github.com:carbon-design-system/gatsby-theme…
Browse files Browse the repository at this point in the history
…-carbon
  • Loading branch information
jnm2377 committed Jun 23, 2020
2 parents 63231f7 + e09e5d4 commit 8fd5deb
Show file tree
Hide file tree
Showing 25 changed files with 234 additions and 19 deletions.
1 change: 0 additions & 1 deletion packages/example/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ module.exports = {
{
resolve: 'gatsby-theme-carbon',
options: {
isSearchEnabled: true,
mediumAccount: 'carbondesign',
repository: {
baseUrl:
Expand Down
15 changes: 8 additions & 7 deletions packages/example/src/pages/components/ImageCard.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ The `<ImageCard>` component should generally be used inside of a `<Row>` and `<C
<Column colMd={4} colLg={4} noGutterSm>
<ImageCard
title="Title"
subTitle="Subtitle"
href="/"
>

Expand All @@ -28,8 +27,8 @@ The `<ImageCard>` component should generally be used inside of a `<Row>` and `<C
aspectRatio="1:1"
href="/"
actionIcon="arrowRight"
subTitleColor="light"
subTitle="Light subtitle"
subTitleColor="dark"
subTitle="Dark subtitle"
>

![Light dark](./images/light-dark.jpg)
Expand Down Expand Up @@ -63,11 +62,13 @@ The `<ImageCard>` component should generally be used inside of a `<Row>` and `<C
</ImageCard>
<ImageCard
disabled
title="Title"
subTitle="Subtitle"
aspectRatio="1:1"
href="/"
>

![Square](/images/square.jpg)
![IBM Cloud Server](/images/IBM_Cloud_Server.png)

</ImageCard>
</Column>
Expand All @@ -87,8 +88,8 @@ The `<ImageCard>` component should generally be used inside of a `<Row>` and `<C
aspectRatio="1:1"
href="/"
actionIcon="arrowRight"
subTitleColor="light"
subTitle="Light subtitle"
subTitleColor="dark"
subTitle="Dark subtitle"
>
![Light dark](./images/light-dark.jpg)
</ImageCard>
Expand Down Expand Up @@ -124,7 +125,7 @@ The `<ImageCard>` component should generally be used inside of a `<Row>` and `<C
| children | node | | | Background image for the card, make sure it is saved out at the correct aspect ratio or it will appear distorted |
| href | string | | | Set url for card |
| aspectRatio | string | | `1:1` | Set card aspect ratio, default is `1:1`, options are `1:1`, `16:9`, `4:3`, `2:1`, `1:2` |
| subTitle | string | | | Smaller title in bottom left of card |
| subTitle | string | | | Smaller title on top left of card |
| title | string | | | Large title |
| actionIcon | string | | | Action icon, default is no icon, options are `Launch`, `ArrowRight`, `Download`, `Disabled`, `Email` |
| titleColor | string | | `light` | Set title text color, default is `light`, options are `light` or `dark` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ title: Video
description: Usage instructions for the Video component
---

import localVideo from './local-video.mp4';
import localPoster from './local-poster.png';

<PageDescription>

The `<Video>` component can render a Vimeo player or a html video player.
Expand All @@ -21,6 +24,10 @@ The `<Video>` component can render a Vimeo player or a html video player.
<track kind="captions" default src="/videos/vtt/hero-video.vtt" srcLang="en" />
</Video>

<Title>Video in MDX</Title>

<Video src={localVideo} poster={localPoster} />

## Code

<Title>Vimeo</Title>
Expand All @@ -37,6 +44,15 @@ The `<Video>` component can render a Vimeo player or a html video player.
</Video>
```

<Title>Video in MDX</Title>

```markdown path=components/Video.mdx src=https://github.com/carbon-design-system/gatsby-theme-carbon/blob/master/packages/example/src/pages/components/Video/index.mdx
import localVideo from './local-video.mp4';
import localPoster from './local-poster.png';

<Video src={localVideo} poster={localPoster} />
```

### Props

| property | propType | required | default | description |
Expand Down
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.
35 changes: 34 additions & 1 deletion packages/example/src/pages/guides/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Gatsby themes allow you to override configuration from the theme by defining the
<AnchorLink>Additional font weights</AnchorLink>
<AnchorLink>Image compression</AnchorLink>
<AnchorLink>Global search</AnchorLink>
<AnchorLink>Navigation style</AnchorLink>
<AnchorLink>Edit on Github link</AnchorLink>
<AnchorLink>Medium</AnchorLink>
<AnchorLink>Other options</AnchorLink>
Expand Down Expand Up @@ -139,6 +140,38 @@ Global search is enabled by default. To disable it, set the `isSearchEnabled` op
Under the hood, we use [Lunr](https://lunrjs.com/) to create our search index. If necessary, you tweak the search scoring algorithm and source nodes.
To do so, provide your own [resolvers object](https://www.gatsbyjs.org/packages/gatsby-plugin-lunr/#getting-started) to the `lunrOptions` theme option.
## Navigation style
By default, the navigation style used by the theme is a sidebar that sits on the left-hand side of the screen. You can see it right now as you read this documentation. This style works great for websites with a lot of content, like documentation sites.
However, if your site is more editorial in nature, and has less pages of content, you may want to use the `header` navigation. This will remove the sidebar on the left-hand side of the page and replace it with a navigation menu that sits in the header. If in the future, the content on your site evolves and you feel the left nav is better suited, you can always change it back.
To enable the header nav, provide `header` as a string to the `navigationStyle` option. To switch back to the default left nav provide an empty string `''` to the `navigationStyle` option. Note: By using the `header` navigation style, you will lose the ResourceLinks that sit directly below the left nav.
```js
plugins: [
{
resolve: 'gatsby-theme-carbon',
options: {
navigationStyle: 'header',
},
},
],
```
When enabled, your header navigation will look like the image below:
<Row>
<Column colMd={8} colLg={8}>
![Header navigation style](header-nav-config.png)
</Column>
</Row>
With the header navigation style enabled, the content on your page will be further left-aligned to allow for more content space.
**Just a note:** In mobile-view, when the header navigation is enabled, the sidebar will persist.
## Edit on GitHub link
To add a link to the bottom of each page that points to the current page source in GitHub, provide a `repository` object to `siteMetadata` in your `gatsby-config.js` file. You can provide a `baseUrl`, and if needed, the `subDirectory` and `branch` where your site source lives.
Expand Down Expand Up @@ -287,4 +320,4 @@ After installing the `remark-grid-tables` plugin, add it to the `remarkPlugins`
},
},
],
```
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/gatsby-theme-carbon/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = (themeOptions) => {

const {
isSearchEnabled = true,
navigationStyle = '',
withWebp = false,
iconPath,
mdxExtensions = ['.mdx', '.md'],
Expand Down Expand Up @@ -57,6 +58,7 @@ module.exports = (themeOptions) => {
return {
siteMetadata: {
isSearchEnabled,
navigationStyle,
title: 'Gatsby Theme Carbon',
description:
'Add a description by supplying it to siteMetadata in your gatsby-config.js file.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classnames from 'classnames';
import cx from 'classnames';
import NavContext from '../../util/context/NavContext';
import useWindowSize from '../../util/hooks/useWindowSize';
import useMetadata from '../../util/hooks/useMetadata';
import { overlay, visible } from './Container.module.scss';

const Container = ({ children, homepage, theme }) => {
Expand All @@ -12,6 +13,7 @@ const Container = ({ children, homepage, theme }) => {
);
const windowSize = useWindowSize();
const lastWindowSize = useRef(windowSize);
const { navigationStyle } = useMetadata();

const closeNavs = useCallback(() => {
toggleNavState('leftNavIsOpen', 'close');
Expand All @@ -37,6 +39,7 @@ const Container = ({ children, homepage, theme }) => {
container: true,
'container--homepage': homepage,
'container--dark': theme === 'dark',
'container--header--nav': navigationStyle,
});

return (
Expand Down
4 changes: 3 additions & 1 deletion packages/gatsby-theme-carbon/src/components/Header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { AppSwitcher20, Close20 } from '@carbon/icons-react';
import cx from 'classnames';

import HeaderNav from '../HeaderNav/HeaderNav';
import GlobalSearch from '../GlobalSearch';
import NavContext from '../../util/context/NavContext';
import useMetadata from '../../util/hooks/useMetadata';
Expand All @@ -31,7 +32,7 @@ const Header = ({ children }) => {
switcherIsOpen,
searchIsOpen,
} = useContext(NavContext);
const { isSearchEnabled } = useMetadata();
const { isSearchEnabled, navigationStyle } = useMetadata();

return (
<ShellHeader aria-label="Header" className={header}>
Expand All @@ -53,6 +54,7 @@ const Header = ({ children }) => {
>
{children}
</Link>
{navigationStyle && <HeaderNav />}
<HeaderGlobalBar>
{isSearchEnabled && <GlobalSearch />}
<HeaderGlobalAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ header.header {
transition: opacity $duration--fast-02 $carbon--standard-easing;
color: $inverse-01;
text-decoration: none;
position: absolute;
left: 3rem;
white-space: nowrap;
padding: 0 $spacing-05;
Expand Down
20 changes: 20 additions & 0 deletions packages/gatsby-theme-carbon/src/components/HeaderNav/HeaderNav.js
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;
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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import HeaderNav from './HeaderNav';

export default HeaderNav;
14 changes: 14 additions & 0 deletions packages/gatsby-theme-carbon/src/components/Homepage/homepage.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@
}
}

.container--header--nav .#{$prefix}--grid {
margin: 0;

@include carbon--breakpoint("lg") {
padding-left: calc(
2% + 2rem
); //2rem to account for 2rem left padding default on grid
}

@include carbon--breakpoint("max") {
padding-left: 2%;
}
}

.container--homepage .#{$prefix}--col-no-gutter {
padding: 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export default class ImageCard extends React.Component {

const cardContent = (
<>
{title ? <h4 className={titleClassNames}>{title}</h4> : null}
{subTitle ? <h5 className={subTitleClassNames}>{subTitle}</h5> : null}
{title ? <h4 className={titleClassNames}>{title}</h4> : null}
<div className={iconClassNames}>
{actionIcon === 'launch' && !disabled ? (
<Launch20 aria-label="Open resource" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
font-weight: 400;
text-decoration: none;
color: $text-04;
position: absolute;
bottom: 1rem;
left: 1rem;
position: relative;
top: 0;
left: 0;
z-index: 1;
}

Expand Down
Loading

0 comments on commit 8fd5deb

Please sign in to comment.