Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 3be82ef

Browse files
committed
Add url support to card
1 parent f47d3a0 commit 3be82ef

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

components/molecules/Card/Card.js

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,40 @@
11
import Button from '@/components/atoms/Button'
22
import Heading from '@/components/atoms/Heading'
3+
import RichText from '@/components/atoms/RichText'
34
import cn from 'classnames'
5+
import Link from 'next/link'
46
import PropTypes from 'prop-types'
57
import React from 'react'
68
import styles from './Card.module.css'
79

810
/**
911
* Render the Card component.
1012
*
11-
* @param {object} props Card component props.
12-
* @param {string} props.body Card body text.
13-
* @param {string} props.className Optional classNames.
14-
* @param {string} props.ctaText The text for the cta button.
15-
* @param {string} props.ctaUrl The url for the cta button.
16-
* @param {object} props.image The image object.
17-
* @param {string} props.meta The card metadata string.
18-
* @param {string} props.timestamp The card timestamp.
19-
* @param {string} props.title The card title.
20-
* @return {Element} The Card component.
13+
* @param {object} props Card component props.
14+
* @param {string} props.body Card body text.
15+
* @param {string} props.buttonText The text for the cta button.
16+
* @param {string} props.className Optional classNames.
17+
* @param {object} props.image The image object.
18+
* @param {string} props.meta The card metadata string.
19+
* @param {string} props.timestamp The card timestamp.
20+
* @param {string} props.title The card title.
21+
* @param {string} props.url The url.
22+
* @return {Element} The Card component.
2123
*/
2224
export default function Card({
2325
body,
26+
buttonText,
2427
className,
25-
ctaText,
26-
ctaUrl,
2728
image,
2829
meta,
2930
timestamp,
30-
title
31+
title,
32+
url
3133
}) {
3234
return (
3335
<div className={cn(styles.card, className)}>
34-
<div className={styles.image}>
35-
{image && image.sourceUrl && (
36+
{image && image.sourceUrl && (
37+
<div className={styles.image}>
3638
<img
3739
draggable="false"
3840
src={image.sourceUrl}
@@ -41,24 +43,33 @@ export default function Card({
4143
height={image.height}
4244
width={image.width}
4345
/>
44-
)}
45-
</div>
46+
</div>
47+
)}
4648
<div className={styles.content}>
4749
{meta && <p className={styles.meta}>{meta}</p>}
48-
{title && <Heading className={styles.title}>{title}</Heading>}
49-
{body && <p className={styles.body}>{body}</p>}
50+
{title &&
51+
(url ? (
52+
<Link href={url}>
53+
<a>
54+
<Heading className={styles.title}>{title}</Heading>
55+
</a>
56+
</Link>
57+
) : (
58+
<Heading className={styles.title}>{title}</Heading>
59+
))}
60+
{body && <RichText className={styles.body}>{body}</RichText>}
5061
</div>
5162
<div className={styles.footer}>
5263
{timestamp && (
5364
<p className={styles.timestamp}>
5465
<time>{timestamp}</time>
5566
</p>
5667
)}
57-
{ctaText && ctaUrl && (
68+
{buttonText && url && (
5869
<Button
5970
className={styles.button}
60-
url={ctaUrl}
61-
text={ctaText}
71+
url={url}
72+
text={buttonText}
6273
type="secondary"
6374
size="md"
6475
/>
@@ -70,9 +81,8 @@ export default function Card({
7081

7182
Card.propTypes = {
7283
body: PropTypes.string,
84+
buttonText: PropTypes.string,
7385
className: PropTypes.string,
74-
ctaText: PropTypes.string,
75-
ctaUrl: PropTypes.string,
7686
headingLevel: PropTypes.oneOf(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']),
7787
image: PropTypes.shape({
7888
sourceUrl: PropTypes.string,
@@ -82,7 +92,8 @@ Card.propTypes = {
8292
}),
8393
meta: PropTypes.string,
8494
title: PropTypes.string,
85-
timestamp: PropTypes.string
95+
timestamp: PropTypes.string,
96+
url: PropTypes.string
8697
}
8798

8899
Card.defaultProps = {

0 commit comments

Comments
 (0)