Created
August 31, 2021 20:32
-
-
Save kellenmace/63467ce0c7a3629f4a457766640527ca to your computer and use it in GitHub Desktop.
Gutenberg Block Component Mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const componentMap = { | |
'core/quote': QuoteBlock, | |
'core/pullquote': PullquoteBlock, | |
'core/code': CodeBlock, | |
'core/preformatted': PreformattedBlock, | |
'core/embed': EmbedBlock, | |
'core/media-text': MediaTextBlock, | |
'core/button': ButtonBlock, | |
'core/buttons': ButtonsBlock, | |
'core/columns': ColumnsBlock, | |
'core/cover': CoverBlock, | |
'core/heading': HeadingBlock, | |
'core/image': ImageBlock, | |
'core/gallery': GalleryBlock, | |
'core/table': TableBlock, | |
'core/list': ListBlock, | |
'core/paragraph': ParagraphBlock, | |
'core/separator': SeparatorBlock, | |
'core/spacer': SpacerBlock, | |
}; | |
export default function Block({ block }) { | |
const { attributes, name, innerBlocks } = block; | |
const BlockComponent = componentMap[name]; | |
if (!BlockComponent) { | |
return null; | |
} | |
if (innerBlocks) { | |
return <BlockComponent attributes={attributes} innerBlocks={innerBlocks} />; | |
} | |
return <BlockComponent {...attributes} />; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment