-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from comicrelief/feature/33_Card_childprops
Card with children props
- Loading branch information
Showing
10 changed files
with
214 additions
and
17 deletions.
There are no files selected for viewing
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
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,62 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import PropTypes from 'prop-types'; | ||
import Picture from '../../Atoms/Picture/Picture'; | ||
|
||
const Container = styled.div` | ||
display: flex; | ||
position: relative; | ||
flex-direction: column; | ||
justify-content: flex-end; | ||
height: 100%; | ||
background: ${({ theme, backgroundColor }) => theme.color(backgroundColor)}; | ||
`; | ||
|
||
const Image = styled.div` | ||
height: 50%; | ||
`; | ||
|
||
const Copy = styled.div` | ||
padding: 20px; | ||
height: 50%; | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: space-between; | ||
`; | ||
|
||
const Card = ({ backgroundColor, image, images, imageAltText, children }) => { | ||
return ( | ||
<Container backgroundColor={backgroundColor}> | ||
{image ? ( | ||
<Image> | ||
<Picture | ||
alt={imageAltText} | ||
image={image} | ||
images={images} | ||
objectFit="cover" | ||
width="100%" | ||
height="100%" | ||
/> | ||
</Image> | ||
) : null} | ||
<Copy>{children}</Copy> | ||
</Container> | ||
); | ||
}; | ||
|
||
Card.propTypes = { | ||
backgroundColor: PropTypes.string, | ||
image: PropTypes.string, | ||
images: PropTypes.string, | ||
imageAltText: PropTypes.string, | ||
children: PropTypes.node.isRequired | ||
}; | ||
|
||
Card.defaultProps = { | ||
backgroundColor: 'white', | ||
image: null, | ||
images: null, | ||
imageAltText: '' | ||
}; | ||
|
||
export default Card; |
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,14 @@ | ||
Card | ||
|
||
```js | ||
const data = require('../../../styleguide/data/data').default; | ||
import Text from '../../Atoms/Text/Text'; | ||
import Link from '../../Atoms/Link/Link'; | ||
|
||
<Card image={data.image} images={data.image} backgroundColor="yellow"> | ||
<Text tag="h3" color="purple" size="xl"> | ||
Title | ||
</Text> | ||
<Text tag="p">Text body copy description</Text> | ||
</Card>; | ||
``` |
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,89 @@ | ||
import React from 'react'; | ||
import 'jest-styled-components'; | ||
import renderWithTheme from '../../../hoc/shallowWithTheme'; | ||
import Card from './Card'; | ||
import data from '../../../styleguide/data/data'; | ||
|
||
it('renders correctly', () => { | ||
const tree = renderWithTheme( | ||
<Card image={data.image} images={data.image} backgroundColor="yellow"> | ||
<h2>Title</h2> | ||
<p>Description</p> | ||
</Card> | ||
).toJSON(); | ||
|
||
expect(tree).toMatchInlineSnapshot(` | ||
.c2 { | ||
display: block; | ||
width: 100%; | ||
height: 100%; | ||
object-fit: cover; | ||
} | ||
.c0 { | ||
display: -webkit-box; | ||
display: -webkit-flex; | ||
display: -ms-flexbox; | ||
display: flex; | ||
position: relative; | ||
-webkit-flex-direction: column; | ||
-ms-flex-direction: column; | ||
flex-direction: column; | ||
-webkit-box-pack: end; | ||
-webkit-justify-content: flex-end; | ||
-ms-flex-pack: end; | ||
justify-content: flex-end; | ||
height: 100%; | ||
background: #fbef51; | ||
} | ||
.c1 { | ||
height: 50%; | ||
} | ||
.c3 { | ||
padding: 20px; | ||
height: 50%; | ||
display: -webkit-box; | ||
display: -webkit-flex; | ||
display: -ms-flexbox; | ||
display: flex; | ||
-webkit-flex-direction: column; | ||
-ms-flex-direction: column; | ||
flex-direction: column; | ||
-webkit-box-pack: justify; | ||
-webkit-justify-content: space-between; | ||
-ms-flex-pack: justify; | ||
justify-content: space-between; | ||
} | ||
<div | ||
className="c0" | ||
> | ||
<div | ||
className="c1" | ||
> | ||
<img | ||
alt="" | ||
className="lazyload c2" | ||
data-sizes="auto" | ||
data-srcset="//images.ctfassets.net/zsfivwzfgl3t/Yq59XdwwQgjNOxky93K1Q/17c2d80dce99067b0b3508f33075cbe3/funding_4-3_2x.jpg?w=800&h=600&q=50 800w" | ||
height="100%" | ||
src="//images.ctfassets.net/zsfivwzfgl3t/Yq59XdwwQgjNOxky93K1Q/17c2d80dce99067b0b3508f33075cbe3/funding_4-3_2x.jpg?w=800&h=600&q=50 800w" | ||
srcSet="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" | ||
width="100%" | ||
/> | ||
</div> | ||
<div | ||
className="c3" | ||
> | ||
<h2> | ||
Title | ||
</h2> | ||
<p> | ||
Description | ||
</p> | ||
</div> | ||
</div> | ||
`); | ||
}); |
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 |
---|---|---|
|
@@ -10,6 +10,11 @@ html { | |
box-sizing: inherit; | ||
} | ||
|
||
body { | ||
margin: 0px; | ||
padding: 0px; | ||
} | ||
|
||
h1, | ||
h2, | ||
h3, | ||
|