This repository has been archived by the owner on May 20, 2024. It is now read-only.
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 #29 from dinartecc/feat-refactor-card-component
Refactor Card Component
- Loading branch information
Showing
8 changed files
with
127 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Box } from 'theme-ui' | ||
|
||
const Card = ({ children, ...props }) => { | ||
return ( | ||
<Box | ||
variant="default" | ||
{...props} | ||
__css={{ | ||
borderRadius: 'card', | ||
px: 'small', | ||
py: 'medium', | ||
textAlign: 'center', | ||
}} | ||
__themeKey="cards" | ||
> | ||
{children} | ||
</Box> | ||
) | ||
} | ||
|
||
Card.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
} | ||
|
||
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,13 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Box } from 'theme-ui' | ||
|
||
const CardContent = ({ children, ...props }) => { | ||
return <Box {...props}>{children}</Box> | ||
} | ||
|
||
CardContent.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
} | ||
|
||
export default CardContent |
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,17 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Box } from 'theme-ui' | ||
|
||
const CardFooter = ({ children, ...props }) => { | ||
return ( | ||
<Box as="footer" {...props} __css={{ mt: 'small' }}> | ||
{children} | ||
</Box> | ||
) | ||
} | ||
|
||
CardFooter.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
} | ||
|
||
export default CardFooter |
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,24 @@ | ||
import React from 'react' | ||
import { Box } from 'theme-ui' | ||
|
||
import { imagePropTypes } from '../../utils/prop-types' | ||
|
||
const CardImage = ({ image, ...props }) => { | ||
const { url, alt, dimensions } = image | ||
return ( | ||
<Box | ||
as="img" | ||
__css={{ m: '0 auto', maxWidth: 'full', mb: 'medium' }} | ||
src={url} | ||
alt={alt} | ||
width={dimensions.width} | ||
{...props} | ||
/> | ||
) | ||
} | ||
|
||
CardImage.propTypes = { | ||
image: imagePropTypes.isRequired, | ||
} | ||
|
||
export default CardImage |
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 |
---|---|---|
@@ -1,50 +1,10 @@ | ||
import React from 'react' | ||
import { Box } from 'theme-ui' | ||
import { RichText } from 'prismic-reactjs' | ||
|
||
import { structuredTextPropTypes, imagePropTypes } from '../../utils/prop-types' | ||
|
||
const Card = ({ image, title, content, ...props }) => { | ||
return ( | ||
<Box | ||
variant="default" | ||
{...props} | ||
__css={{ | ||
borderRadius: 'card', | ||
px: 'small', | ||
py: 'medium', | ||
textAlign: 'center', | ||
}} | ||
__themeKey="cards" | ||
> | ||
<Box | ||
as="img" | ||
__css={{ m: '0 auto', maxWidth: 'full', mb: 'medium' }} | ||
src={image.url} | ||
alt={image.alt} | ||
width={image.dimensions.width} | ||
/> | ||
<div> | ||
<Box as="h3" __css={{ fontSize: 'base', mb: 'small' }}> | ||
{RichText.asText(title)} | ||
</Box> | ||
<Box sx={{ fontWeight: 'lean' }}> | ||
<RichText render={content} /> | ||
</Box> | ||
</div> | ||
</Box> | ||
) | ||
} | ||
|
||
Card.defaultProps = { | ||
content: [], | ||
image: [], | ||
} | ||
|
||
Card.propTypes = { | ||
content: structuredTextPropTypes, | ||
image: imagePropTypes, | ||
title: structuredTextPropTypes.isRequired, | ||
} | ||
import Card from './Card' | ||
import CardContent from './CardContent' | ||
import CardFooter from './CardFooter' | ||
import CardImage from './CardImage' | ||
|
||
Card.Content = CardContent | ||
Card.Footer = CardFooter | ||
Card.Image = CardImage | ||
|
||
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
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 |
---|---|---|
|
@@ -28,5 +28,6 @@ | |
"text": "", | ||
"spans": [] | ||
} | ||
] | ||
], | ||
"footer": "Footer" | ||
} |
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