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
  • Loading branch information
Sojisoyoye committed Jul 24, 2019
1 parent 769fe87 commit 270f156
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 70 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
5 changes: 5 additions & 0 deletions src/components/UI/atoms/Text/Text.jsx
Original file line number Diff line number Diff line change
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.string,
};

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: ${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;
132 changes: 132 additions & 0 deletions src/components/UI/molecules/ImageText/ImageText.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/* eslint-disable no-use-before-define */
import React from 'react';
import PropTypes from 'prop-types';


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

/**
* @description - ImageText Component
*
* @prop {string} imageUrl - imageUrl
* @prop {string} title - title
* @prop {string} author - author
* @prop {string} description - description
*
* @return {component} ImageText
*/
const ImageText = ({
title,
author,
description,
imageUrl,
titleFontSize,
authorFontSize,
descriptionFontSize,
}) => {
return (
<FlexContainer
flexDirection="row"
height="75%"
padding="zero"
>
<FlexContainer
padding="zero"
containerWidth="imageWidth"
>
<Image
imageUrl={imageUrl}
width="100%"
/>
</FlexContainer>
<FlexContainer
containerWidth="articleWidth"
backgroundColor="primary"
padding="xxl"
paddingLeft="xl"
>
<FlexContainer
backgroundColor="primary"
>
{title && (renderTitle(titleFontSize))}
{author && (renderAuthor(authorFontSize))}
</FlexContainer>
<FlexContainer
backgroundColor="primary"
>
{description && (renderDescription(descriptionFontSize))}
</FlexContainer>
</FlexContainer>
</FlexContainer>
);


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

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

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

ImageText.defaultProps = {
titleFontSize: 'xlarge',
authorFontSize: 'medx',
descriptionFontSize: 'medx',
};

ImageText.propTypes = {
imageUrl: PropTypes.string,
width: PropTypes.string,
height: PropTypes.string,
display: PropTypes.oneOf(['block', 'inline', 'flex', 'inline-block', 'none']),
text: PropTypes.string,
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)),
};

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

```jsx
<ImageText
/>
```

Icon with all attributes
```jsx
import FlexContainer from '<atoms>/layouts/FlexContainer/FlexContainer';
<FlexContainer>
<ImageText
imageUrl="https://www.cubesmart.com/blog/wp-content/uploads/Brooklyn-Bridge-at-Night-1140x704.jpg"
title="City by the bay"
author="By : Emmy Joans"
description="This is a description of an article"
titleFontSize="normal"
authorFontSize="normal"
descriptionFontSize="normal"
/>
</FlexContainer>
```
41 changes: 41 additions & 0 deletions src/components/UI/molecules/ImageText/ImageText.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable max-len */
import React from 'react';
import { render, cleanup } from '<src>/helpers/testUtils';
import ImageText from './ImageText';
import '@testing-library/jest-dom/extend-expect';

afterEach(cleanup);

const setup = (props) => {
const utils = render(
<ImageText {...props}/>,
);

return { ...utils };
};

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

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

it('should render ImageText with title', () => {
const { getByText } = render(<ImageText title='City by the bay' />);

expect(getByText('City by the bay')).toBeTruthy();
});

it('should render ImageText with author', () => {
const { getByText } = render(<ImageText author='By : Emmy Joan' />);

expect(getByText('By : Emmy Joan')).toBeTruthy();
});

it('should render ImageText with description', () => {
const { getByText } = render(<ImageText description='This is a description' />);

expect(getByText('This is a description')).toBeTruthy();
});
});
2 changes: 0 additions & 2 deletions src/components/UI/molecules/SearchBar/SearchBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('Search Bar', () => {
padding: 0.9rem;
border-radius: 4.05rem;
box-shadow: none;
border: 1px solid transparent;
`);
});

Expand All @@ -52,7 +51,6 @@ describe('Search Bar', () => {
padding: 0.9rem;
border-radius: 4.05rem;
box-shadow: none;
border: 1px solid transparent;
`);
});

Expand Down
1 change: 1 addition & 0 deletions src/components/pages/Home/HomePage.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
import React from 'react';
import PageLayout from '<templates>/PageLayout/PageLayout';
import Text from '<atoms>/Text/Text';
Expand Down
1 change: 1 addition & 0 deletions src/components/templates/PageLayout/PageLayout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ PageLayout.Container = styled.div`
display: flex;
justify-content: ${justifyContent};
align-items: ${alignItems};
flex-direction: column
`}
`;

Expand Down
Loading

0 comments on commit 270f156

Please sign in to comment.