1
1
import Button from '@/components/atoms/Button'
2
2
import Heading from '@/components/atoms/Heading'
3
+ import RichText from '@/components/atoms/RichText'
3
4
import cn from 'classnames'
5
+ import Link from 'next/link'
4
6
import PropTypes from 'prop-types'
5
7
import React from 'react'
6
8
import styles from './Card.module.css'
7
9
8
10
/**
9
11
* Render the Card component.
10
12
*
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.
21
23
*/
22
24
export default function Card ( {
23
25
body,
26
+ buttonText,
24
27
className,
25
- ctaText,
26
- ctaUrl,
27
28
image,
28
29
meta,
29
30
timestamp,
30
- title
31
+ title,
32
+ url
31
33
} ) {
32
34
return (
33
35
< div className = { cn ( styles . card , className ) } >
34
- < div className = { styles . image } >
35
- { image && image . sourceUrl && (
36
+ { image && image . sourceUrl && (
37
+ < div className = { styles . image } >
36
38
< img
37
39
draggable = "false"
38
40
src = { image . sourceUrl }
@@ -41,24 +43,33 @@ export default function Card({
41
43
height = { image . height }
42
44
width = { image . width }
43
45
/>
44
- ) }
45
- </ div >
46
+ </ div >
47
+ ) }
46
48
< div className = { styles . content } >
47
49
{ 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 > }
50
61
</ div >
51
62
< div className = { styles . footer } >
52
63
{ timestamp && (
53
64
< p className = { styles . timestamp } >
54
65
< time > { timestamp } </ time >
55
66
</ p >
56
67
) }
57
- { ctaText && ctaUrl && (
68
+ { buttonText && url && (
58
69
< Button
59
70
className = { styles . button }
60
- url = { ctaUrl }
61
- text = { ctaText }
71
+ url = { url }
72
+ text = { buttonText }
62
73
type = "secondary"
63
74
size = "md"
64
75
/>
@@ -70,9 +81,8 @@ export default function Card({
70
81
71
82
Card . propTypes = {
72
83
body : PropTypes . string ,
84
+ buttonText : PropTypes . string ,
73
85
className : PropTypes . string ,
74
- ctaText : PropTypes . string ,
75
- ctaUrl : PropTypes . string ,
76
86
headingLevel : PropTypes . oneOf ( [ 'h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' ] ) ,
77
87
image : PropTypes . shape ( {
78
88
sourceUrl : PropTypes . string ,
@@ -82,7 +92,8 @@ Card.propTypes = {
82
92
} ) ,
83
93
meta : PropTypes . string ,
84
94
title : PropTypes . string ,
85
- timestamp : PropTypes . string
95
+ timestamp : PropTypes . string ,
96
+ url : PropTypes . string
86
97
}
87
98
88
99
Card . defaultProps = {
0 commit comments