Skip to content

Commit

Permalink
feat(molecule): setup image with article row molecule
Browse files Browse the repository at this point in the history
- setup container for the atoms
- include image atom
- include text and title atom
- write test for component

[Finishes #167454777]
  • Loading branch information
Sojisoyoye committed Jul 25, 2019
1 parent 769fe87 commit 73fe5db
Show file tree
Hide file tree
Showing 18 changed files with 414 additions and 74 deletions.
132 changes: 66 additions & 66 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "king-kong-ah-frontend",
"jest": {
"roots": ["<rootDir>/src/"],
"roots": [
"<rootDir>/src/"
],
"verbose": true,
"moduleNameMapper": {
"\\.(css|less)$": "<rootDir>/src/config/assetsTransformer.js",
Expand Down
7 changes: 6 additions & 1 deletion src/components/UI/atoms/Text/Text.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';

import { fontWeights, fontSizes } from '<variables>/fonts';
import { fontWeights, fontSizes, lineHeights } from '<variables>/fonts';
import { textColors } from '<variables>/colorPalette';
import spacing from '<variables>/spacing';

Expand Down Expand Up @@ -30,6 +30,7 @@ const Text = ({
fontWeight,
padding,
content,
lineHeight,
children,
}) => (
<Text.Container
Expand All @@ -41,6 +42,7 @@ const Text = ({
content={content}
padding={padding}
fontWeight={fontWeight}
lineHeight={lineHeight}
>
{children}
</Text.Container>
Expand All @@ -62,6 +64,7 @@ Text.propTypes = {
content: PropTypes.oneOf(['true', 'false']),
padding: PropTypes.oneOf(Object.keys(spacing)),
fontWeight: PropTypes.oneOf(Object.keys(fontWeights)),
lineHeight: PropTypes.oneOf(Object.keys(lineHeights)),
};

Text.defaultProps = {
Expand All @@ -83,6 +86,7 @@ Text.Container = styled.span`
display,
textAlign,
color,
lineHeight,
theme,
}) => `
text-align: ${textAlign};
Expand All @@ -92,6 +96,7 @@ Text.Container = styled.span`
font-size: ${theme.fontSizes[fontSize]};
font-weight: ${theme.fontWeights[fontWeight]};
font-family: ${(content === 'true' && 'Inknut Antiqua') || 'roboto'};
line-height: ${theme.lineHeights[lineHeight]};
text-transform: ${textTransform};
@media ${theme.device.mobileS} {
Expand Down
5 changes: 5 additions & 0 deletions src/components/UI/atoms/Title/Title.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const Title = ({
color,
display,
paddingBottom,
content,
children,
}) => (
<Title.Container
Expand All @@ -32,6 +33,7 @@ const Title = ({
color={color}
display={display}
paddingBottom={paddingBottom}
content={content}
>
{children}
</Title.Container>
Expand All @@ -43,6 +45,7 @@ Title.propTypes = {
color: PropTypes.oneOf(Object.keys(textColors)),
display: PropTypes.oneOf(['block', 'inline', 'inline-block', 'none']),
paddingBottom: PropTypes.oneOf(Object.keys(spacing)),
content: PropTypes.oneOf(['true', 'false']),
children: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
.isRequired,
};
Expand All @@ -60,13 +63,15 @@ Title.Container = styled.span`
color,
display,
paddingBottom,
content,
theme,
}) => `
display: ${display};
text-align: ${textAlign};
color: ${theme.textColors[color]};
padding-bottom: ${theme.spacing[paddingBottom]};
font-size: ${theme.fontSizes[fontSize]};
font-family: ${(content === 'true' && 'Inknut Antiqua') || 'roboto'};
font-weight: ${theme.fontWeights.bold}
@media ${theme.device.mobileS} {
Expand Down
13 changes: 12 additions & 1 deletion src/components/UI/atoms/layouts/FlexContainer/FlexContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ import width from '<variables>/width';
*/
const FlexContainer = ({
children,
height,
margin,
padding,
paddingLeft,
display,
backgroundColor,
borderColor,
Expand All @@ -37,7 +39,9 @@ const FlexContainer = ({
}) => (
<FlexContainer.Container
margin={margin}
height={height}
padding={padding}
paddingLeft={paddingLeft}
display={display}
backgroundColor={backgroundColor}
borderColor={borderColor}
Expand All @@ -54,8 +58,10 @@ const FlexContainer = ({

FlexContainer.Container = styled.div`
${({
height,
margin,
padding,
paddingLeft,
display,
borderRadius,
boxShadow,
Expand All @@ -64,18 +70,21 @@ FlexContainer.Container = styled.div`
justifyContent,
containerWidth,
alignItems,
borderWidth,
flexDirection,
theme: {
spacing, backgroundColors, borderColors, boxShadows,
},
}) => `
height: ${height}
display: ${display};
background-color: ${backgroundColors[backgroundColor]};
margin: ${spacing[margin]};
padding: ${spacing[padding]};
padding-left: ${spacing[paddingLeft]}
border-radius: ${spacing[borderRadius]};
box-shadow: ${boxShadows[boxShadow]};
border: 1px solid ${borderColors[borderColor] || 'transparent'};
border: ${borderWidth} solid ${borderColors[borderColor] || 'transparent'};
justify-content: ${justifyContent}
flex-direction: ${flexDirection};
width: ${width[containerWidth]}
Expand All @@ -101,6 +110,7 @@ FlexContainer.propTypes = {
children: PropTypes.node,
margin: PropTypes.oneOf(Object.keys(spacing)),
padding: PropTypes.oneOf(Object.keys(spacing)),
paddingLeft: PropTypes.oneOf(Object.keys(spacing)),
backgroundColor: PropTypes.oneOf(Object.keys(backgroundColors)),
display: PropTypes.oneOf(['block', 'inline', 'flex', 'inline-block', 'none']),
borderColor: PropTypes.oneOf(Object.keys(borderColors)),
Expand All @@ -122,6 +132,7 @@ FlexContainer.propTypes = {
'space-around',
]),
flexDirection: PropTypes.oneOf(['row', 'column']),
height: PropTypes.string,
};

export default FlexContainer;
113 changes: 113 additions & 0 deletions src/components/UI/molecules/ArticleContent/ArticleContent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* eslint-disable no-use-before-define */
import React from 'react';
import PropTypes from 'prop-types';

import FlexContainer from '<atoms>/layouts/FlexContainer/FlexContainer';
import Title from '<atoms>/Title/Title';
import Text from '<atoms>/Text/Text';
import { fontSizes, lineHeights } from '<variables>/fonts';

/**
* @description - ArticleContent Component
*
* @prop {string} title - title
* @prop {string} author - author
* @prop {string} description - description
* @prop {string} titleFontSize - titleFontSize
* @prop {string} authorFontSize - authorFontSize
* @prop {string} descriptionFontSize - descriptionFontSize
*
* @return {component} ArticleContent
*/
const ArticleContent = ({
title,
author,
description,
authorLineHeight,
titleFontSize,
authorFontSize,
descriptionFontSize,
}) => {
return (
<FlexContainer
containerWidth="articleWidth"
backgroundColor="primary"
padding="xxl"
paddingLeft="xl"
>
<FlexContainer
backgroundColor="primary"
>
{title && (renderTitle(titleFontSize))}
{author && (renderAuthor(authorFontSize, authorLineHeight))}
</FlexContainer>
<FlexContainer
backgroundColor="primary"
>
{description && (renderDescription(descriptionFontSize))}
</FlexContainer>
</FlexContainer>
);

function renderTitle(size) {
return (
<Title
fontSize={size}
color="lightBrown"
content="true"
paddingBottom="zero"
>
{title}
</Title>
);
}

function renderAuthor(size, height) {
return (
<div>
<Text
fontSize={size}
color="lightBrown"
content="true"
lineHeight={height}
>
{author}
</Text>
</div>
);
}

function renderDescription(size) {
return (
<div>
<Text
fontSize={size}
color="white001"
content="true"
>
{description}
</Text>
</div>
);
}
};


ArticleContent.defaultProps = {
titleFontSize: 'xlarge',
authorFontSize: 'medx',
descriptionFontSize: 'medium',
authorLineHeight: 'zero',
};

ArticleContent.propTypes = {
title: PropTypes.string,
author: PropTypes.string,
description: PropTypes.string,
titleFontSize: PropTypes.oneOf(Object.keys(fontSizes)),
authorFontSize: PropTypes.oneOf(Object.keys(fontSizes)),
descriptionFontSize: PropTypes.oneOf(Object.keys(fontSizes)),
authorLineHeight: PropTypes.oneOf(Object.keys(lineHeights)),
};

export default ArticleContent;
19 changes: 19 additions & 0 deletions src/components/UI/molecules/ArticleContent/ArticleContent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ArticleContent Default:

```jsx
<ArticleContent
/>
```

ArticleContent with all attributes:

```jsx
<ArticleContent
title="City by the bay"
author="By : Emmy Joans"
description="This is a description of an article"
titleFontSize="medx"
authorFontSize="normal"
descriptionFontSize="normal"
/>
```
55 changes: 55 additions & 0 deletions src/components/UI/molecules/ArticleContent/ArticleContent.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint-disable max-len */
import React from 'react';
import { render, cleanup } from '<src>/helpers/testUtils';
import ArticleContent from './ArticleContent';
import '@testing-library/jest-dom/extend-expect';

afterEach(cleanup);

const setup = () => {
const utils = render(
<ArticleContent />,
);

return { ...utils };
};

describe('ArticleContent', () => {
it('should render the ArticleContent component', () => {
const { container } = setup();

expect(container).toBeTruthy();
});

it('should render the ArticleContent Component with titleFontSize', () => {
const { container } = render(<ArticleContent titleFontSize="large" />);

expect(container.lastChild).toHaveStyle(`
titleFontSize: large
`);
});

it('should render the ArticleContent Component with authorFontSize', () => {
const { container } = render(<ArticleContent authorFontSize="medium" />);

expect(container.lastChild).toHaveStyle(`
authorFontSize: medium,
`);
});

it('should render the ArticleContent Component with descriptionFontSize', () => {
const { container } = render(<ArticleContent descriptionFontSize="medium" />);

expect(container.lastChild).toHaveStyle(`
descriptionFontSize: medium,
`);
});

it('should render the ArticleContent Component with authorLineHeight', () => {
const { container } = render(<ArticleContent authorLineHeight="single" />);

expect(container.lastChild).toHaveStyle(`
authorLineHeight: single,
`);
});
});
Loading

0 comments on commit 73fe5db

Please sign in to comment.