Skip to content

Commit

Permalink
Block save component
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Mar 9, 2020
1 parent 34ed2a6 commit bf97c84
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/block-editor/src/components/block-list/block-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,30 @@ const elements = [
'figure',
];

const BlockSaveComponent = forwardRef(
( { children, tagName: TagName = 'div', ...props }, wrapper ) => {
return (
<TagName { ...props } ref={ wrapper }>
{ children }
</TagName>
);
}
);

const ExtendedBlockComponent = elements.reduce( ( acc, element ) => {
acc[ element ] = forwardRef( ( props, ref ) => {
return <BlockComponent { ...props } ref={ ref } tagName={ element } />;
} );
return acc;
}, BlockComponent );

ExtendedBlockComponent.Save = elements.reduce( ( acc, element ) => {
acc[ element ] = forwardRef( ( props, ref ) => {
return (
<BlockSaveComponent { ...props } ref={ ref } tagName={ element } />
);
} );
return acc;
}, BlockSaveComponent );

export const Block = ExtendedBlockComponent;
3 changes: 2 additions & 1 deletion packages/block-library/src/paragraph/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getColorClassName,
getFontSizeClass,
RichText,
__experimentalBlock as Block,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
Expand Down Expand Up @@ -51,7 +52,7 @@ export default function save( { attributes } ) {

return (
<RichText.Content
tagName="p"
tagName={ Block.Save.p }
style={ styles }
className={ className ? className : undefined }
value={ content }
Expand Down

0 comments on commit bf97c84

Please sign in to comment.