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

Commit 0d23d22

Browse files
committed
Adding MetaText block
1 parent c7f7474 commit 0d23d22

File tree

5 files changed

+79
-5
lines changed

5 files changed

+79
-5
lines changed

components/atoms/Code/Code.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ export default function Code({id, className, content}) {
1919
// Use the className to pass the langauge.
2020
const language = className ? className : 'javascript'
2121

22-
// Replace any `<` encoded HTML.
23-
const code = content.replace(/&lt;/g, '<')
22+
// Replace any `&lt;` and `&gt; encoded HTML.
23+
let code = content.replace(/&lt;/g, '<')
24+
code = code.replace(/&gt;/g, '>')
2425

2526
return (
2627
<>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import Image from '@/components/atoms/Image'
2+
import Blocks from '@/components/molecules/Blocks'
3+
import PropTypes from 'prop-types'
4+
5+
/**
6+
* Code Block
7+
*
8+
* The core Code block from Gutenberg.
9+
*
10+
* @author WebDevStudios
11+
* @param {string} className Optional classnames.
12+
* @param {string} anchor Optional anchor/id.
13+
* @param {string} content The content of the block.
14+
* @return {Element} The Code component.
15+
*/
16+
export default function BlockMediaText({media, innerBlocks}) {
17+
//const position = media?.mediaPosition === 'right' ? 'right' : 'left';
18+
return (
19+
<div>
20+
{!!media && (
21+
<Image
22+
alt={media?.mediaAlt}
23+
anchor={media?.anchor}
24+
caption={media?.caption}
25+
className={media?.className}
26+
id={media?.mediaId}
27+
href={media?.href}
28+
linkTarget={media?.linkTarget}
29+
linkClass={media?.linkClass}
30+
rel={media?.rel}
31+
sizeSlug={media?.sizeSlug}
32+
url={media?.mediaUrl}
33+
/>
34+
)}
35+
{!!innerBlocks?.length && <Blocks blocks={innerBlocks} />}
36+
</div>
37+
)
38+
}
39+
40+
BlockMediaText.propTypes = {
41+
media: PropTypes.shape({
42+
anchor: PropTypes.string,
43+
caption: PropTypes.string,
44+
className: PropTypes.string,
45+
href: PropTypes.string,
46+
linkTarget: PropTypes.string,
47+
linkClass: PropTypes.string,
48+
rel: PropTypes.string,
49+
sizeSlug: PropTypes.string,
50+
mediaAlt: PropTypes.string,
51+
mediaId: PropTypes.number,
52+
mediaType: PropTypes.string,
53+
mediaUrl: PropTypes.string,
54+
mediaPosition: PropTypes.string
55+
}),
56+
innerBlocks: PropTypes.arrayOf(
57+
PropTypes.shape({
58+
name: PropTypes.string,
59+
attributes: PropTypes.object
60+
})
61+
)
62+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default} from './BlockMediaText'

components/blocks/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export {default as BlockSpacer} from './BlockSpacer'
1414
export {default as BlockVideoEmbed} from './BlockVideoEmbed'
1515
export {default as BlockTable} from './BlockTable'
1616
export {default as BlockCode} from './BlockCode'
17+
export {default as BlockMediaText} from './BlockMediaText'

functions/displayBlock.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import PropTypes from 'prop-types'
77
* @author WebDevStudios
88
* @param {object} block The block data.
99
* @param {number} index A unique key required by React.
10-
* @return {Element} A block-based component.
10+
* @return {Element} A block-based component.
1111
*/
1212
export default function displayBlock(block, index) {
13-
const {attributes, name} = block
13+
const {attributes, name, innerBlocks} = block
1414

1515
// prettier-ignore
1616
switch (name) {
@@ -23,9 +23,18 @@ export default function displayBlock(block, index) {
2323
case 'core/pullquote':
2424
return <Blocks.BlockPullQuote {...attributes} key={index} />
2525
case 'core/code':
26-
return <Blocks.BlockCode {...attributes} key={index} />
26+
case 'core/preformatted':
27+
return <Blocks.BlockCode {...attributes} key={index} />
2728
// case 'core/embed':
2829
// return <Blocks.BlockVideoEmbed {...attributes} key={index} />
30+
case 'core/media-text':
31+
return (
32+
<Blocks.BlockMediaText
33+
media={attributes}
34+
innerBlocks={innerBlocks}
35+
key={index}
36+
/>
37+
)
2938
case 'core/heading':
3039
return <Blocks.BlockHeadings {...attributes} key={index} />
3140
case 'core/image':

0 commit comments

Comments
 (0)