|
| 1 | +import React from 'react' |
| 2 | +import PropTypes from 'prop-types' |
| 3 | +import { News, Headset, Play, Clipboard } from '@tds/core-decorative-icon' |
| 4 | +import { |
| 5 | + StyledCard, |
| 6 | + StyledTextBox, |
| 7 | + StyledInfoBox, |
| 8 | + StyledType, |
| 9 | + StyledDate, |
| 10 | + StyledHeadingBox, |
| 11 | + StyledHeading, |
| 12 | + StyledDescription, |
| 13 | + StyledIconTypeBox, |
| 14 | + StyledLink, |
| 15 | + StyledIconBox, |
| 16 | + StyledImageContainer, |
| 17 | + StyledImage, |
| 18 | +} from './style' |
| 19 | + |
| 20 | +const StoryCard = ({ storyType, date, title, description, imgUrl, href }) => { |
| 21 | + const selectIcon = type => { |
| 22 | + if (type !== undefined) { |
| 23 | + const normalizedType = type.toLowerCase() |
| 24 | + if (normalizedType === 'article') { |
| 25 | + return <News size={20} /> |
| 26 | + } else if (normalizedType === 'podcast') { |
| 27 | + return <Headset size={20} /> |
| 28 | + } else if (normalizedType === 'video') { |
| 29 | + return <Play size={20} /> |
| 30 | + } else if (normalizedType === 'case study') { |
| 31 | + return <Clipboard size={20} /> |
| 32 | + } |
| 33 | + } |
| 34 | + return undefined |
| 35 | + } |
| 36 | + |
| 37 | + return ( |
| 38 | + <StyledLink href={href} title={title}> |
| 39 | + <StyledCard> |
| 40 | + <StyledTextBox> |
| 41 | + <StyledInfoBox> |
| 42 | + <StyledIconTypeBox> |
| 43 | + {selectIcon(storyType) !== undefined && ( |
| 44 | + <StyledIconBox>{selectIcon(storyType)}</StyledIconBox> |
| 45 | + )} |
| 46 | + <StyledType>{storyType}</StyledType> |
| 47 | + </StyledIconTypeBox> |
| 48 | + <StyledDate>{date}</StyledDate> |
| 49 | + </StyledInfoBox> |
| 50 | + <StyledHeadingBox> |
| 51 | + <StyledHeading>{title}</StyledHeading> |
| 52 | + </StyledHeadingBox> |
| 53 | + <StyledDescription>{description}</StyledDescription> |
| 54 | + </StyledTextBox> |
| 55 | + <StyledImageContainer> |
| 56 | + <StyledImage src={imgUrl} alt={description} width="100%" /> |
| 57 | + </StyledImageContainer> |
| 58 | + </StyledCard> |
| 59 | + </StyledLink> |
| 60 | + ) |
| 61 | +} |
| 62 | + |
| 63 | +StoryCard.propTypes = { |
| 64 | + /** |
| 65 | + * The title of the story |
| 66 | + */ |
| 67 | + title: PropTypes.string.isRequired, |
| 68 | + /** |
| 69 | + * The description of the story |
| 70 | + */ |
| 71 | + description: PropTypes.string.isRequired, |
| 72 | + /** |
| 73 | + * The URL for the image to be displayed |
| 74 | + */ |
| 75 | + imgUrl: PropTypes.string.isRequired, |
| 76 | + /** |
| 77 | + * The href for the story |
| 78 | + */ |
| 79 | + href: PropTypes.string.isRequired, |
| 80 | + /** |
| 81 | + * The type of story, if it is one of Article, Podcast or Video, an icon will render beside it. If it is something else, there will be no icon. |
| 82 | + */ |
| 83 | + storyType: PropTypes.string, |
| 84 | + /** |
| 85 | + * The date of when the story was published |
| 86 | + */ |
| 87 | + date: PropTypes.string, |
| 88 | +} |
| 89 | + |
| 90 | +StoryCard.defaultProps = { |
| 91 | + storyType: undefined, |
| 92 | + date: undefined, |
| 93 | +} |
| 94 | + |
| 95 | +export default StoryCard |
0 commit comments