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

Commit 95f0499

Browse files
committed
Add support for lazyblocks hero
1 parent 852863f commit 95f0499

File tree

5 files changed

+76
-24
lines changed

5 files changed

+76
-24
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import Hero from '@/components/organisms/Hero'
2+
import PropTypes from 'prop-types'
3+
4+
/**
5+
* Handle the Hero block.
6+
*
7+
* @author WebDevStudios
8+
* @param {object} props The props.
9+
* @param {object} props.attributes The attributes object.
10+
* @return {Element} The component.
11+
*/
12+
export default function BlockHero({attributes}) {
13+
attributes = {
14+
...attributes,
15+
backgroundImage: JSON.parse(decodeURIComponent(attributes.backgroundImage))
16+
}
17+
18+
return (
19+
<>
20+
{attributes ? (
21+
<Hero {...attributes} />
22+
) : (
23+
'There was a problem with attributes in BlockHero.js.'
24+
)}
25+
</>
26+
)
27+
}
28+
29+
BlockHero.propTypes = {
30+
attributes: PropTypes.object
31+
}

components/blocks/BlockHero/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from './BlockHero'

components/blocks/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
// Create default exports for each Block.
22
export {default as BlockAccordions} from './BlockAccordions'
3-
export {default as BlockQuote} from './BlockQuote'
4-
export {default as BlockPullQuote} from './BlockPullQuote'
3+
export {default as BlockButton} from './BlockButton'
4+
export {default as BlockButtons} from './BlockButtons'
5+
export {default as BlockCode} from './BlockCode'
6+
export {default as BlockHeadings} from './BlockHeadings'
7+
export {default as BlockHero} from './BlockHero'
58
export {default as BlockImage} from './BlockImage'
69
export {default as BlockImageGallery} from './BlockImageGallery'
710
export {default as BlockList} from './BlockList'
11+
export {default as BlockMediaText} from './BlockMediaText'
812
export {default as BlockNetflixCarousel} from './BlockNetflixCarousel'
913
export {default as BlockParagraph} from './BlockParagraph'
10-
export {default as BlockHeadings} from './BlockHeadings'
14+
export {default as BlockPullQuote} from './BlockPullQuote'
15+
export {default as BlockQuote} from './BlockQuote'
1116
export {default as BlockSeparator} from './BlockSeparator'
1217
export {default as BlockShortcode} from './BlockShortcode'
1318
export {default as BlockSpacer} from './BlockSpacer'
14-
export {default as BlockVideoEmbed} from './BlockVideoEmbed'
1519
export {default as BlockTable} from './BlockTable'
16-
export {default as BlockCode} from './BlockCode'
17-
export {default as BlockMediaText} from './BlockMediaText'
18-
export {default as BlockButton} from './BlockButton'
19-
export {default as BlockButtons} from './BlockButtons'
20+
export {default as BlockVideoEmbed} from './BlockVideoEmbed'

components/organisms/Hero/Hero.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Button from '@/components/atoms/Button'
2+
import cn from 'classnames'
23
import PropTypes from 'prop-types'
34
import React from 'react'
45
import tailwindConfig from '../../../tailwind.config'
@@ -8,34 +9,44 @@ import styles from './Hero.module.css'
89
* Render the Hero component.
910
*
1011
* @param {object} props Hero component props.
11-
* @param {string} props.backgroundImage The background image url.
12+
* @param {string} props.backgroundImage The background image object.
1213
* @param {string} props.body Text for the body.
13-
* @param {object} props.cta Object with text and url props for the CTA button.
14+
* @param {string} props.className The className.
15+
* @param {object} props.ctaText The cta text.
16+
* @param {object} props.ctaUrl The cta url.
1417
* @param {string} props.subtitle Text for the subtitle.
1518
* @param {string} props.title Text for the title.
1619
* @return {Element} The Hero component.
1720
*/
18-
export default function Hero({backgroundImage, body, cta, subtitle, title}) {
21+
export default function Hero({
22+
backgroundImage,
23+
body,
24+
className,
25+
ctaText,
26+
ctaUrl,
27+
subtitle,
28+
title
29+
}) {
1930
return (
2031
<section
21-
className={styles.hero}
32+
className={cn(styles.hero, className)}
2233
style={{
2334
// These css custom properties are used inside the css module file to set the card's background image, tint overlay, and fallback bg color.
24-
'--image-url': `url(${backgroundImage})`,
25-
'--image-tint-color': `${tailwindConfig.theme.colors.black}50`,
35+
'--image-url': `url(${backgroundImage.url})`,
36+
'--image-tint-color': `${tailwindConfig.theme.colors.black['DEFAULT']}50`,
2637
'--image-fallback-color': `${tailwindConfig.theme.colors.grey['darkest']}`
2738
}}
2839
>
2940
<div className={styles.content}>
3041
{subtitle && <p className={styles.subtitle}>{subtitle}</p>}
3142
<h1 className={styles.title}>{title}</h1>
3243
{body && <p className={styles.body}>{body}</p>}
33-
{cta && (
44+
{ctaText && ctaUrl && (
3445
<Button
3546
className={styles.button}
36-
url={cta.url ? cta.url : null}
37-
icon={cta.icon ? cta.icon : null}
38-
text={cta.text ? cta.text : null}
47+
url={ctaUrl}
48+
text={ctaText}
49+
icon="arrowRight"
3950
type="primary"
4051
size="md"
4152
/>
@@ -46,13 +57,14 @@ export default function Hero({backgroundImage, body, cta, subtitle, title}) {
4657
}
4758

4859
Hero.propTypes = {
49-
backgroundImage: PropTypes.string,
50-
body: PropTypes.string,
51-
cta: PropTypes.shape({
52-
icon: PropTypes.string,
53-
text: PropTypes.string,
54-
url: PropTypes.string
60+
backgroundImage: PropTypes.shape({
61+
url: PropTypes.string,
62+
alt: PropTypes.string
5563
}),
64+
body: PropTypes.string,
65+
className: PropTypes.string,
66+
ctaText: PropTypes.string,
67+
ctaUrl: PropTypes.string,
5668
subtitle: PropTypes.string,
5769
title: PropTypes.string.isRequired
5870
}

functions/displayBlock.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ export default function displayBlock(block, index) {
3434
key={index}
3535
/>
3636
)
37+
case 'lazyblock/hero':
38+
return (
39+
<Blocks.BlockHero
40+
attributes={attributes}
41+
key={index}
42+
/>
43+
)
3744
case 'core/button':
3845
return (
3946
<Blocks.BlockButton

0 commit comments

Comments
 (0)