Skip to content

Commit

Permalink
Create Resources component that can be defined in md
Browse files Browse the repository at this point in the history
  • Loading branch information
icaraps committed Jul 17, 2020
1 parent 35d0450 commit 30c86a8
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 75 deletions.
14 changes: 7 additions & 7 deletions example/src/pages/index.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
---
title: Overview - Adobe Analytics
description: This is an overview page of Adobe Analytics
resources:
- text: Adobe Analytics Product Docs
link: https://adobe.io
- text: Adobe Analytics Github Repo
link: https://adobe.io
contributors:
- https://github.com/icaraps
- https://github.com/macdonst
- https://github.com/simonwex
- https://github.com/schaulinsan
- https://github.com/duynguyen
---

<Hero slots="image, heading, text" background="rgb(64, 34, 138)"/>
Expand All @@ -22,6 +15,13 @@ contributors:

Adobe Product API offers limitless ways to integrate your most important customer data into key business processes. Adobe Product API offer limitless ways.

<Resources slots="heading, links"/>

#### Resources

* [Quickstart Guide](https://adobe.io)
* [Adobe Analytics Github Repo](https://adobe.io)

## Overview

This documentation provides instructions for Adobe Analytics 2.0 APIs. For working with Analytics 1.4 APIs, see [Analytics 1.4 API Documentation](https://adobe.io).
Expand Down
26 changes: 16 additions & 10 deletions packages/gatsby-theme-spectrum/src/components/ContentBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,46 @@ import React from 'react';
import { css } from '@emotion/core';
import { layoutColumns } from './utils';
import '@spectrum-css/typography';
import PropTypes from "prop-types";
import PropTypes from 'prop-types';

const imageWidth = '100px';

const ContentBlock = ({ width, heading, link, text, image }) => (
<div
css={css`
${image ? `
${image
? `
position: relative;
margin-left: calc(${imageWidth} + var(--spectrum-global-dimension-static-size-400));
` : ''}
`
: ''}
display: inline-flex;
flex-direction: column;
margin-right: var(--spectrum-global-dimension-static-size-200);
width: ${width ? width : layoutColumns(3, ['var(--spectrum-global-dimension-static-size-800)'])};
`}>
{image && React.cloneElement(image, {
css: css`
{image &&
React.cloneElement(image, {
css: css`
position: absolute;
top: var(--spectrum-heading-m-margin-top, var(--spectrum-alias-heading-m-margin-top));
left: calc(-${imageWidth} - var(--spectrum-global-dimension-static-size-400));
display: flex;
align-items: flex-start;
height: 100%;
width: ${imageWidth};
`
})}
{heading ?? <div className="spectrum-Heading--M" aria-hidden="true">&nbsp;</div>}
`
})}
{heading ?? (
<div className="spectrum-Heading--M" aria-hidden="true">
&nbsp;
</div>
)}
{link}
{text}
</div>
);


ContentBlock.propTypes = {
width: PropTypes.string,
heading: PropTypes.func,
Expand All @@ -56,4 +62,4 @@ ContentBlock.propTypes = {
link: PropTypes.func
};

export { ContentBlock }
export { ContentBlock };
20 changes: 20 additions & 0 deletions packages/gatsby-theme-spectrum/src/components/Heading4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import React from 'react';
import '@spectrum-css/typography';

export const Heading4 = ({ children, className, ...props }) => (
<h4 {...props} className={className ?? 'spectrum-Heading--XS'}>
{children}
</h4>
);
34 changes: 17 additions & 17 deletions packages/gatsby-theme-spectrum/src/components/Hero.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { css } from '@emotion/core';
import { Flex } from '@react-spectrum/layout';
import { View } from '@react-spectrum/view';
import '@spectrum-css/typography';
import PropTypes from "prop-types";
import PropTypes from 'prop-types';

const Hero = ({ background = '#1D7DEE', heading, text, image }) => {
return (
Expand Down Expand Up @@ -43,21 +43,21 @@ const Hero = ({ background = '#1D7DEE', heading, text, image }) => {
`
})}
</View>
{image &&
<View>
{React.cloneElement(image, {
className: '',
css: css`
margin: 0;
& img {
min-width: 750px;
max-height: 210px;
object-fit: contain;
}
`
})}
</View>
}
{image && (
<View>
{React.cloneElement(image, {
className: '',
css: css`
margin: 0;
& img {
min-width: 750px;
max-height: 210px;
object-fit: contain;
}
`
})}
</View>
)}
</Flex>
</section>
);
Expand All @@ -70,4 +70,4 @@ Hero.propTypes = {
image: PropTypes.func
};

export { Hero }
export { Hero };
53 changes: 12 additions & 41 deletions packages/gatsby-theme-spectrum/src/components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import './Layout.css';

import { Flex } from '@react-spectrum/layout';
import { View } from '@react-spectrum/view';
import LinkOut from '@spectrum-icons/workflow/LinkOut';
import '@spectrum-css/typography';

import { Heading1 } from './Heading1';
import { Heading2 } from './Heading2';
import { Heading3 } from './Heading3';
import { Heading4 } from './Heading4';
import { Paragraph } from './Paragraph';
import { List } from './List';
import { Code } from './Code';
Expand All @@ -32,20 +32,23 @@ import { Link } from './Link';
import { Image } from './Image';

import { Footer } from './Footer';
import { Resources } from './Resources';
import { Hero } from './Hero';
import { ContentBlock } from './ContentBlock';
import { Contributors } from './Contributors';
import { Feedback } from './Feedback';

const customComponents = {
Hero,
ContentBlock
ContentBlock,
Resources
};

const mdxComponents = {
h1: Heading1,
h2: Heading2,
h3: Heading3,
h4: Heading4,
p: Paragraph,
ul: List,
code: Code,
Expand All @@ -60,6 +63,7 @@ const filterChildren = (children) => {
const filteredChildren = [];

let heroChild;
let resourcesChild;

while (childrenArray.length) {
const child = childrenArray[0];
Expand All @@ -81,6 +85,8 @@ const filterChildren = (children) => {

if (child.props.mdxType === 'Hero') {
heroChild = childClone;
} else if (child.props.mdxType === 'Resources') {
resourcesChild = childClone;
} else {
filteredChildren.push(childClone);
}
Expand All @@ -98,12 +104,13 @@ const filterChildren = (children) => {

return {
filteredChildren,
heroChild
heroChild,
resourcesChild
};
};

export default ({ children, pageContext }) => {
const { filteredChildren, heroChild } = filterChildren(children);
const { filteredChildren, heroChild, resourcesChild } = filterChildren(children);

return (
<MDXProvider components={mdxComponents}>
Expand Down Expand Up @@ -146,43 +153,7 @@ export default ({ children, pageContext }) => {
</View>
</Flex>
</article>
{pageContext.frontmatter.resources && (
<aside
css={css`
min-width: ${layoutColumns(3, [
'var(--spectrum-global-dimension-static-size-400)',
'var(--spectrum-global-dimension-static-size-100)'
])};
margin-left: var(--spectrum-global-dimension-static-size-400);
margin-top: var(--spectrum-global-dimension-static-size-400);
`}>
<h4 className="spectrum-Heading--XS">Resources</h4>
<ul
className="spectrum-Body--M"
css={css`
list-style: none;
padding: 0;
`}>
{pageContext.frontmatter.resources.map(({ link, text }, i) => (
<li
key={i}
css={css`
margin-top: var(--spectrum-global-dimension-static-size-200);
`}>
<a href={link} target="_blank" rel="nofollow noopener noreferrer">
<span
css={css`
margin-right: var(--spectrum-global-dimension-static-size-100);
`}>
{text}
</span>
<LinkOut size="XS" />
</a>
</li>
))}
</ul>
</aside>
)}
{resourcesChild && resourcesChild}
</Flex>
</section>
<Footer />
Expand Down
71 changes: 71 additions & 0 deletions packages/gatsby-theme-spectrum/src/components/Resources.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import React from 'react';
import { css } from '@emotion/core';
import '@spectrum-css/typography';
import PropTypes from 'prop-types';
import { layoutColumns } from './utils';
import { Link } from './Link';
import LinkOut from '@spectrum-icons/workflow/LinkOut';

const Resources = ({ heading, links }) => {
return (
<aside
css={css`
min-width: ${layoutColumns(3, [
'var(--spectrum-global-dimension-static-size-400)',
'var(--spectrum-global-dimension-static-size-100)'
])};
margin-left: var(--spectrum-global-dimension-static-size-400);
margin-top: var(--spectrum-global-dimension-static-size-400);
`}>
{heading}
<ul
className="spectrum-Body--M"
css={css`
list-style: none;
padding: 0;
`}>
{React.Children.toArray(links.props.children).map((item, i) => {
const link = React.Children.toArray(item.props.children)[0];

return (
<li
key={i}
css={css`
margin-top: var(--spectrum-global-dimension-static-size-200);
`}>
<Link href={link.props.href} target="_blank" rel="nofollow noopener noreferrer" className="spectrum-Link">
<span
css={css`
display: inline-flex;
margin-right: var(--spectrum-global-dimension-static-size-100);
`}>
{link.props.children}
</span>
<LinkOut size="XS" />
</Link>
</li>
);
})}
</ul>
</aside>
);
};

Resources.propTypes = {
heading: PropTypes.func,
links: PropTypes.func
};

export { Resources };

0 comments on commit 30c86a8

Please sign in to comment.