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

Commit e1af407

Browse files
author
Greg Rickaby
authored
Merge pull request #146 from WebDevStudios/fix/media-text-gutenberg-fixes
Fix/media text gutenberg fixes
2 parents 69af453 + 6288f02 commit e1af407

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

components/organisms/MediaText/MediaText.js

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,39 @@ import Button from '@/components/atoms/Button'
22
import Container from '@/components/atoms/Container'
33
import cn from 'classnames'
44
import PropTypes from 'prop-types'
5-
import React from 'react'
5+
import React, {useEffect} from 'react'
66
import styles from './MediaText.module.css'
77

88
/**
99
* Render the MediaText component.
1010
*
1111
* @param {object} props MediaText component props.
1212
* @param {string} props.body The body text.
13+
* @param {element} props.children The child elements.
1314
* @param {string} props.className The className.
1415
* @param {object} props.cta The cta object with text and url strings.
1516
* @param {object} props.image The image object with url and alt text.
1617
* @param {boolean} props.mediaLeft Whether to show media on the left of the text.
1718
* @param {string} props.title The title.
18-
* @return {Element} The MediaText component.
19+
* @return {Element} The MediaText component.
1920
*/
2021
export default function MediaText({
2122
body,
23+
children,
2224
className,
2325
cta,
2426
image,
2527
mediaLeft,
2628
title
2729
}) {
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+
2838
return (
2939
<Container>
3040
<section
@@ -35,17 +45,23 @@ export default function MediaText({
3545
)}
3646
>
3747
<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+
</>
4965
)}
5066
</div>
5167
<div className={styles.media}>
@@ -63,6 +79,7 @@ export default function MediaText({
6379
MediaText.propTypes = {
6480
body: PropTypes.string,
6581
className: PropTypes.string,
82+
children: PropTypes.element,
6683
cta: PropTypes.shape({
6784
text: PropTypes.string,
6885
url: PropTypes.string,

components/organisms/MediaText/MediaText.stories.mdx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,25 @@ Media will display on the right on large screens by default. Use the `mediaLeft`
4141
/>
4242
</Story>
4343
</Canvas>
44+
45+
## Children
46+
47+
You can display children as an element using the `children` prop. If used, the `title`, `body`, and `cta` will not display.
48+
49+
<Canvas>
50+
<Story name="Children">
51+
<MediaText
52+
children={
53+
<div>
54+
<p>Hi I'm a child element!</p>
55+
</div>
56+
}
57+
image={{
58+
url:
59+
'https://images.unsplash.com/photo-1610991149688-c1321006bcc1?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1110&q=60',
60+
alt: 'Some alt text'
61+
}}
62+
mediaLeft
63+
/>
64+
</Story>
65+
</Canvas>

0 commit comments

Comments
 (0)