diff --git a/components/blocks/Gutenberg/BlockMediaText/BlockMediaText.js b/components/blocks/Gutenberg/BlockMediaText/BlockMediaText.js index a1d93e35b..5b75496bc 100644 --- a/components/blocks/Gutenberg/BlockMediaText/BlockMediaText.js +++ b/components/blocks/Gutenberg/BlockMediaText/BlockMediaText.js @@ -9,19 +9,79 @@ import PropTypes from 'prop-types' * * @author WebDevStudios * @param {object} props The component properties. - * @param {object} props.media Media props. * @param {Array} props.innerBlocks The array of inner blocks to display. + * @param {object} props.media Media props. * @return {Element} The Code component. */ -export default function BlockMediaText({media, innerBlocks}) { +export default function BlockMediaText({innerBlocks, media}) { + /* eslint-disable no-unused-vars */ + const { + anchor, + backgroundColorHex, + caption, + className, + focalPoint, + gradientHex, + href, + imageFill, + isStackedOnMobile, + linkClass, + linkTarget, + mediaAlt, + mediaId, + mediaPosition, + mediaType, + mediaWidth, + mediaUrl, + rel, + sizeSlug, + style, + textColorHex, + verticalAlignment + } = media + /* eslint-enable no-unused-vars */ + + // Determine background and text colors, using stylelint-accepted const names. + const backgroundcolor = + backgroundColorHex || style?.color?.background || 'inherit' + const textcolor = textColorHex || style?.color?.text || 'inherit' + const background = gradientHex || style?.color?.gradient || 'inherit' + const gridtemplatecolumns = + mediaPosition === 'left' ? `${mediaWidth}% 1fr` : `1fr ${mediaWidth}%` + + // Create style object for button. + const mediaTextStyle = { + background: background, + backgroundColor: backgroundcolor, + color: textcolor, + gridTemplateColumns: gridtemplatecolumns + } + + const newFocalPoint = {} + + // Convert focal point values to percent. + if (imageFill) { + const x = parseFloat(focalPoint?.x || '.5') ?? 0.5 + const y = parseFloat(focalPoint?.y || '.5') ?? 0.5 + + newFocalPoint.x = `${x * 100}%` + newFocalPoint.y = `${y * 100}%` + } + return ( <> {!!media && innerBlocks?.length && ( @@ -31,27 +91,39 @@ export default function BlockMediaText({media, innerBlocks}) { } BlockMediaText.propTypes = { + innerBlocks: PropTypes.arrayOf( + PropTypes.shape({ + attributes: PropTypes.object, + name: PropTypes.string + }) + ), media: PropTypes.shape({ anchor: PropTypes.string, + backgroundColorHex: PropTypes.string, caption: PropTypes.string, className: PropTypes.string, + focalPoint: PropTypes.shape({ + x: PropTypes.string, + y: PropTypes.string + }), + gradientHex: PropTypes.string, href: PropTypes.string, - linkTarget: PropTypes.string, + imageFill: PropTypes.bool, + isStackedOnMobile: PropTypes.bool, linkClass: PropTypes.string, - rel: PropTypes.string, - sizeSlug: PropTypes.string, + linkTarget: PropTypes.string, mediaAlt: PropTypes.string, mediaId: PropTypes.number, + mediaPosition: PropTypes.string, mediaType: PropTypes.string, + mediaWidth: PropTypes.number, mediaUrl: PropTypes.string, - mediaPosition: PropTypes.string - }), - innerBlocks: PropTypes.arrayOf( - PropTypes.shape({ - name: PropTypes.string, - attributes: PropTypes.object - }) - ) + rel: PropTypes.string, + sizeSlug: PropTypes.string, + style: PropTypes.object, + textColorHex: PropTypes.string, + verticalAlignment: PropTypes.string + }) } BlockMediaText.defaultProps = { media: PropTypes.shape({ diff --git a/components/organisms/MediaText/MediaText.js b/components/organisms/MediaText/MediaText.js index ae6f10ecd..7a1fa535d 100644 --- a/components/organisms/MediaText/MediaText.js +++ b/components/organisms/MediaText/MediaText.js @@ -8,26 +8,36 @@ import styles from './MediaText.module.css' /** * Render the MediaText component. * - * @param {object} props MediaText component props. - * @param {string} props.body The body text. - * @param {Element} props.children The child elements. - * @param {string} props.className The className. - * @param {object} props.cta The cta object with text and url strings. - * @param {string} props.id Optional element ID. - * @param {object} props.image The image object with url and alt text. - * @param {boolean} props.mediaLeft Whether to show media on the left of the text. - * @param {string} props.title The title. - * @return {Element} The MediaText component. + * @param {object} props MediaText component props. + * @param {string} props.body The body text. + * @param {Element} props.children The child elements. + * @param {string} props.className The className. + * @param {object} props.cta The cta object with text and url strings. + * @param {object} props.focalPoint The focal point coordinates for the image fill setting. + * @param {string} props.id Optional element ID. + * @param {object} props.image The image object with url and alt text. + * @param {boolean} props.imageFill Whether to crop image to fill. + * @param {boolean} props.mediaLeft Whether to show media on the left of the text. + * @param {boolean} props.stackOnMobile Whether to stack media and text on mobile. + * @param {object} props.style Custom media text styles. + * @param {string} props.title The title. + * @param {string} props.verticalAlignment Vertical alignment of text. + * @return {Element} The MediaText component. */ export default function MediaText({ body, children, className, cta, + focalPoint, id, image, + imageFill, mediaLeft, - title + stackOnMobile, + style, + title, + verticalAlignment }) { useEffect(() => { if ((children && title) || (children && body) || (children && cta)) { @@ -37,14 +47,26 @@ export default function MediaText({ } }) + const imageFillStyle = !imageFill + ? null + : { + backgroundImage: `url(${image?.url || ''})`, + backgroundPosition: `${focalPoint.x} ${focalPoint.y}` + } + return ( {children ? ( @@ -66,7 +88,7 @@ export default function MediaText({ > )} - + {image && image.url && (