Skip to content

Commit

Permalink
feat(container): create container atom
Browse files Browse the repository at this point in the history
- create a container component
- write test for the component
- create a styleguide for the component

[Finishes #167169184]
  • Loading branch information
Eazybee committed Jul 11, 2019
1 parent 754ba6a commit 211c4de
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 70 deletions.
204 changes: 135 additions & 69 deletions package-lock.json

Large diffs are not rendered by default.

91 changes: 91 additions & 0 deletions src/components/UI/atoms/layouts/FlexContainer/FlexContainer.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import theme from '<variables>/mainTheme';


/**
* @description - Container Component
*
* @prop {node} children - children
* @prop {string} margin - margin
* @prop {string} padding - padding
* @prop {string} display - display
* @prop {string} backgroundColor - background color
* @prop {string} borderColor - border color
* @prop {string} borderRadius - add border radius
* @prop {string} boxShadow - boxShadow
*
* @return {component} FlexContainer
*/
const FlexContainer = ({
children,
margin,
padding,
display,
backgroundColor,
borderColor,
borderRadius,
boxShadow,
}) => (
<FlexContainer.Container
margin={margin}
padding={padding}
display={display}
backgroundColor={backgroundColor}
borderColor={borderColor}
borderRadius={borderRadius}
boxShadow={boxShadow}
>
{children}
</FlexContainer.Container>
);

FlexContainer.Container = styled.div`
${({
margin,
padding,
display,
borderRadius,
boxShadow,
backgroundColor,
borderColor,
theme: {
spacing, backgroundColors, borderColors, boxShadows,
},
}) => `
display: ${display};
background-color: ${backgroundColors[backgroundColor]};
margin: ${spacing[margin]};
padding: ${spacing[padding]};
border-radius: ${spacing[borderRadius]};
box-shadow: ${boxShadows[boxShadow]};
border: 1px solid ${borderColors[borderColor] || 'transparent'};
`}
`;

FlexContainer.defaultProps = {
display: 'flex',
backgroundColor: 'white001',
padding: 'sm',
boxShadow: 'none',
borderRadius: 'zero',
margin: 'zero',
};

const {
spacing, backgroundColors, borderColors, boxShadows,
} = theme;

FlexContainer.propTypes = {
children: PropTypes.node.isRequired,
margin: PropTypes.oneOf(Object.keys(spacing)),
padding: 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)),
borderRadius: PropTypes.oneOf(Object.keys(spacing)),
boxShadow: PropTypes.oneOf(Object.keys(boxShadows)),
};

export default FlexContainer;
71 changes: 71 additions & 0 deletions src/components/UI/atoms/layouts/FlexContainer/FlexContainer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
FlexContainer Default:

```jsx
<FlexContainer>
<span />
</FlexContainer>
```

FlexContainer with borderColor

```jsx
<FlexContainer borderColor="primary">
<span />
</FlexContainer>
```

FlexContainer with borderRadius

```jsx
<FlexContainer borderColor="primary" borderRadius='xs'>
<span />
</FlexContainer>
```

FlexContainer with articleCard boxShadow

```jsx
<FlexContainer boxShadow="articleCard">
<span />
</FlexContainer>
```

FlexContainer with section boxShadow

```jsx
<FlexContainer boxShadow="section">
<span />
</FlexContainer>
```

FlexContainer with backgroundColor

```jsx
<FlexContainer backgroundColor="primary">
<span />
</FlexContainer>
```

FlexContainer with margin

```jsx
<FlexContainer borderColor="primary" margin="md">
<span />
</FlexContainer>
```

FlexContainer with md padding

```jsx
<FlexContainer borderColor="primary" padding="md">
<span />
</FlexContainer>
```

FlexContainer with display

```jsx
<FlexContainer borderColor="primary" display="block">
<span />
</FlexContainer>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { render, cleanup } from '<src>/helpers/testUtils';
import FlexContainer from './FlexContainer';
import 'jest-dom/extend-expect';

afterEach(cleanup);

const defaultProps = `
padding: 1.6rem;
display: flex;
backgroundColor: white;
border: 1px solid tranparent;
`;

describe('FlexContainer', () => {
it('should render the FlexContainer component', () => {
const { container } = render(<FlexContainer><span/></FlexContainer>);

expect(container.lastElementChild.innerHTML).toBe('<span></span>');
expect(container.firstChild).toHaveStyle(defaultProps);
});

it('should render with box-radius', () => {
const { container } = render(
<FlexContainer borderRadius='xs'><span/></FlexContainer>,
);

expect(container.firstChild).toHaveStyle(`
border-radius: 0.9rem;
${defaultProps}
`);
});

it('should render with box-shadow', () => {
const { container } = render(
<FlexContainer boxShadow='articleCard'><span/></FlexContainer>,
);

expect(container.firstChild).toHaveStyle(`
border-shadow: 16px 16px 32px rgba(0, 0, 0, 0.05);
${defaultProps}
`);
});
});
5 changes: 5 additions & 0 deletions src/styles/GlobalStyle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,10 @@ body {
font-family: 'Roboto', 'Inknut Antiqua', sans-serif;
font-size: 1.6rem;
}
div{
overflow: hidden;
box-sizing: border-box;
}
`;
export default GlobalStyle;
6 changes: 6 additions & 0 deletions src/styles/variables/colorPalette.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ export const textColors = {

export const backgroundColors = {
lightPink: '#F4EDED',
primary: '#690375',
white001: '#FFFFFF',
};

export const borderColors = {
primary: '#B02091',
};
7 changes: 6 additions & 1 deletion src/styles/variables/mainTheme.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import spacing from './spacing';
import { fontSizes, fontWeights } from './fonts';
import { buttonColors, textColors, backgroundColors } from './colorPalette';
import borderRadius from './border';
import width from './width';
import {
buttonColors, textColors, backgroundColors, borderColors,
} from './colorPalette';
import { boxShadows } from './shadows';

export default {
spacing,
Expand All @@ -13,4 +16,6 @@ export default {
backgroundColors,
borderRadius,
width,
borderColors,
boxShadows,
};
7 changes: 7 additions & 0 deletions src/styles/variables/shadows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const boxShadows = {
articleCard: '16px 16px 32px #F0F0F0',
section: '4px 4px 40px #C2C2C2',
none: 'none',
};

export default boxShadows;

0 comments on commit 211c4de

Please sign in to comment.