-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(container): create container atom (#17)
- create a container component - write test for the component - create a styleguide for the component [Finishes #167169184]
- Loading branch information
Showing
8 changed files
with
354 additions
and
70 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
91 changes: 91 additions & 0 deletions
91
src/components/UI/atoms/layouts/FlexContainer/FlexContainer.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
71
src/components/UI/atoms/layouts/FlexContainer/FlexContainer.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` |
44 changes: 44 additions & 0 deletions
44
src/components/UI/atoms/layouts/FlexContainer/FlexContainer.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: white001; | ||
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 #F0F0F0; | ||
${defaultProps} | ||
`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |