@@ -2,29 +2,39 @@ import Button from '@/components/atoms/Button'
2
2
import Container from '@/components/atoms/Container'
3
3
import cn from 'classnames'
4
4
import PropTypes from 'prop-types'
5
- import React from 'react'
5
+ import React , { useEffect } from 'react'
6
6
import styles from './MediaText.module.css'
7
7
8
8
/**
9
9
* Render the MediaText component.
10
10
*
11
11
* @param {object } props MediaText component props.
12
12
* @param {string } props.body The body text.
13
+ * @param {element } props.children The child elements.
13
14
* @param {string } props.className The className.
14
15
* @param {object } props.cta The cta object with text and url strings.
15
16
* @param {object } props.image The image object with url and alt text.
16
17
* @param {boolean } props.mediaLeft Whether to show media on the left of the text.
17
18
* @param {string } props.title The title.
18
- * @return {Element } The MediaText component.
19
+ * @return {Element } The MediaText component.
19
20
*/
20
21
export default function MediaText ( {
21
22
body,
23
+ children,
22
24
className,
23
25
cta,
24
26
image,
25
27
mediaLeft,
26
28
title
27
29
} ) {
30
+ useEffect ( ( ) => {
31
+ if ( ( children && title ) || ( children && body ) || ( children && cta ) ) {
32
+ console . warn (
33
+ 'The title, body and cta props are ignored when using children.'
34
+ )
35
+ }
36
+ } )
37
+
28
38
return (
29
39
< Container >
30
40
< section
@@ -35,17 +45,23 @@ export default function MediaText({
35
45
) }
36
46
>
37
47
< div className = { styles . text } >
38
- < h1 className = { styles . title } > { title } </ h1 >
39
- { body && < p className = { styles . body } > { body } </ p > }
40
- { cta && (
41
- < Button
42
- className = { styles . button }
43
- url = { cta . url ? cta . url : null }
44
- text = { cta . text ? cta . text : null }
45
- icon = { cta . icon ? cta . icon : null }
46
- type = "primary"
47
- size = "md"
48
- />
48
+ { children ? (
49
+ children
50
+ ) : (
51
+ < >
52
+ { title && < h1 className = { styles . title } > { title } </ h1 > }
53
+ { body && < p className = { styles . body } > { body } </ p > }
54
+ { cta && (
55
+ < Button
56
+ className = { styles . button }
57
+ url = { cta . url ? cta . url : null }
58
+ text = { cta . text ? cta . text : null }
59
+ icon = { cta . icon ? cta . icon : null }
60
+ type = "primary"
61
+ size = "md"
62
+ />
63
+ ) }
64
+ </ >
49
65
) }
50
66
</ div >
51
67
< div className = { styles . media } >
@@ -63,6 +79,7 @@ export default function MediaText({
63
79
MediaText . propTypes = {
64
80
body : PropTypes . string ,
65
81
className : PropTypes . string ,
82
+ children : PropTypes . element ,
66
83
cta : PropTypes . shape ( {
67
84
text : PropTypes . string ,
68
85
url : PropTypes . string ,
0 commit comments