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

Commit 2bdcacf

Browse files
committed
Make example for ACF gutenberg blocks
1 parent fa1ec97 commit 2bdcacf

File tree

8 files changed

+209
-2
lines changed

8 files changed

+209
-2
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import AcfMediaText from '@/components/organisms/AcfMediaText'
2+
import PropTypes from 'prop-types'
3+
4+
/**
5+
* Handle the LzbMediaText 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 LzbBlockMediaText({attributes}) {
13+
// TODO: Query the DB for the image ID and replace the attributes.data with the correct information.
14+
attributes.data = {
15+
...attributes.data,
16+
image: {}
17+
}
18+
19+
return (
20+
<>
21+
{attributes ? (
22+
<AcfMediaText {...attributes.data} />
23+
) : (
24+
'There was a problem with attributes in AcfBlockMediaText.js.'
25+
)}
26+
</>
27+
)
28+
}
29+
30+
LzbBlockMediaText.propTypes = {
31+
attributes: PropTypes.object
32+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from './AcfBlockMediaText'

components/blocks/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
// Export the blocks.
2+
export {default as AcfBlockMediaText} from './ACF/AcfBlockMediaText'
23
export {default as BlockButton} from './Gutenberg/BlockButton'
34
export {default as BlockButtons} from './Gutenberg/BlockButtons'
45
export {default as BlockCode} from './Gutenberg/BlockCode'
56
export {default as BlockColumns} from './Gutenberg/BlockColumns'
67
export {default as BlockCover} from './Gutenberg/BlockCover'
8+
export {default as BlockEmbed} from './Gutenberg/BlockEmbed'
9+
export {default as BlockGravityForm} from './Gutenberg/BlockGravityForm'
710
export {default as BlockHeadings} from './Gutenberg/BlockHeadings'
811
export {default as BlockImage} from './Gutenberg/BlockImage'
912
export {default as BlockImageGallery} from './Gutenberg/BlockImageGallery'
@@ -16,7 +19,5 @@ export {default as BlockSeparator} from './Gutenberg/BlockSeparator'
1619
export {default as BlockShortcode} from './Gutenberg/BlockShortcode'
1720
export {default as BlockSpacer} from './Gutenberg/BlockSpacer'
1821
export {default as BlockTable} from './Gutenberg/BlockTable'
19-
export {default as BlockEmbed} from './Gutenberg/BlockEmbed'
20-
export {default as BlockGravityForm} from './Gutenberg/BlockGravityForm'
2122
export {default as LzbBlockHero} from './LazyBlocks/LzbBlockHero'
2223
export {default as LzbBlockMediaText} from './LazyBlocks/LzbBlockMediaText'
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import Button from '@/components/atoms/Button'
2+
import Container from '@/components/atoms/Container'
3+
import cn from 'classnames'
4+
import PropTypes from 'prop-types'
5+
import React from 'react'
6+
import styles from './AcfMediaText.module.css'
7+
8+
/**
9+
* Render the AcfMediaText component.
10+
*
11+
* @param {object} props AcfMediaText component props.
12+
* @param {string} props.body The body text.
13+
* @param {string} props.className The className.
14+
* @param {object} props.ctaText The cta text.
15+
* @param {object} props.ctaUrl The cta url.
16+
* @param {object} props.image The image object with url and alt text.
17+
* @param {boolean} props.mediaLeft Whether to show media on the left of the text.
18+
* @param {string} props.title The title.
19+
* @return {Element} The AcfMediaText component.
20+
*/
21+
export default function AcfMediaText({
22+
body,
23+
className,
24+
ctaText,
25+
ctaUrl,
26+
image,
27+
mediaLeft,
28+
title
29+
}) {
30+
return (
31+
<Container>
32+
<section
33+
className={cn(
34+
styles.acfMediaText,
35+
mediaLeft ? styles.mediaLeft : null,
36+
className
37+
)}
38+
>
39+
<div className={styles.text}>
40+
<>
41+
{title && <h1 className={styles.title}>{title}</h1>}
42+
{body && <p className={styles.body}>{body}</p>}
43+
{ctaText && ctaUrl && (
44+
<Button
45+
className={styles.button}
46+
url={ctaUrl}
47+
text={ctaText}
48+
type="primary"
49+
size="md"
50+
/>
51+
)}
52+
</>
53+
</div>
54+
<div className={styles.media}>
55+
{image && image.url && (
56+
<div className={styles.imageWrap}>
57+
<img src={image.url} alt={image.alt} />
58+
</div>
59+
)}
60+
</div>
61+
</section>
62+
</Container>
63+
)
64+
}
65+
66+
AcfMediaText.propTypes = {
67+
body: PropTypes.string,
68+
className: PropTypes.string,
69+
ctaText: PropTypes.string,
70+
ctaUrl: PropTypes.string,
71+
image: PropTypes.shape({
72+
url: PropTypes.string,
73+
alt: PropTypes.string
74+
}),
75+
mediaLeft: PropTypes.bool,
76+
title: PropTypes.string
77+
}
78+
79+
AcfMediaText.defaultProps = {
80+
mediaLeft: false
81+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.acfMediaText {
2+
@apply md:grid md:grid-cols-12 md:gap-16 mb-12;
3+
4+
& .text,
5+
& .media {
6+
@apply col-span-6 flex flex-col items-start justify-center;
7+
}
8+
9+
& .text {
10+
@apply items-start;
11+
12+
& .title {
13+
@apply mb-8;
14+
}
15+
16+
& .body {
17+
@apply mb-24;
18+
}
19+
}
20+
21+
& .media {
22+
& .imageWrap {
23+
@apply relative h-0 w-full rounded bg-opacity-20;
24+
25+
padding-top: 67.58%; /* Aspect ratio box - https://css-tricks.com/aspect-ratio-boxes */
26+
}
27+
28+
& img {
29+
@apply absolute top-0 left-0 w-full h-full object-cover rounded;
30+
}
31+
}
32+
33+
&.mediaLeft {
34+
& .media {
35+
grid-row-start: 1;
36+
}
37+
38+
& .text {
39+
@apply items-end;
40+
41+
& .body {
42+
@apply text-right;
43+
}
44+
}
45+
}
46+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import {Canvas, Meta, Story} from '@storybook/addon-docs/blocks'
2+
import AcfMediaText from './'
3+
4+
<Meta title="Components/Molecules/AcfMediaText" component={AcfMediaText} />
5+
6+
# Component
7+
8+
Use this to display media and text in a 50/50 layout.
9+
10+
<Canvas>
11+
<Story name="Component">
12+
<AcfMediaText
13+
title="New Designs"
14+
body="Our amazing new design is here! Get it while it's hot, it won't be hot for long... uh oh, already cooling."
15+
image={{
16+
url:
17+
'https://images.unsplash.com/photo-1610991149688-c1321006bcc1?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1110&q=60',
18+
alt: 'Some alt text'
19+
}}
20+
cta={{icon: 'arrowRight', text: 'Take a look'}}
21+
/>
22+
</Story>
23+
</Canvas>
24+
25+
## Media Left
26+
27+
Media will display on the right on large screens by default. Use the `mediaLeft` prop to display the media on the left side.
28+
29+
<Canvas>
30+
<Story name="MediaLeft">
31+
<AcfMediaText
32+
title="New Designs"
33+
body="Our amazing new design is here! Get it while it's hot, it won't be hot for long... uh oh, already cooling."
34+
image={{
35+
url:
36+
'https://images.unsplash.com/photo-1610991149688-c1321006bcc1?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=1110&q=60',
37+
alt: 'Some alt text'
38+
}}
39+
cta={{icon: 'arrowRight', text: 'Take a look'}}
40+
mediaLeft
41+
/>
42+
</Story>
43+
</Canvas>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from './AcfMediaText'

functions/displayBlock.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export default function displayBlock(block, index) {
5555
return <Blocks.LzbBlockMediaText attributes={attributes} key={index} />
5656
case 'lazyblock/hero':
5757
return <Blocks.LzbBlockHero attributes={attributes} key={index} />
58+
case 'acf/acf-media-text':
59+
return <Blocks.AcfBlockMediaText attributes={attributes} key={index} />
5860
default:
5961
return <pre key={index}>{JSON.stringify(block, null, 2)}</pre>
6062
}

0 commit comments

Comments
 (0)