Skip to content

Commit

Permalink
Export through useBlockWrapperProps
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Sep 25, 2020
1 parent 3f6715a commit 84aeb9e
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ENTER, BACKSPACE, DELETE } from '@wordpress/keycodes';
import { __, sprintf } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import deprecated from '@wordpress/deprecated';
import { getBlockProps } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -286,6 +287,13 @@ export function useBlockWrapperProps( props = {}, { __unstableIsHtml } = {} ) {
};
}

/**
* Call within a save function to get the props for the block wrapper.
*
* @param {Object} props Optional. Props to pass to the element.
*/
useBlockWrapperProps.save = getBlockProps;

const BlockComponent = forwardRef(
( { children, tagName: TagName = 'div', ...props }, ref ) => {
deprecated( 'wp.blockEditor.__experimentalBlock', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* WordPress dependencies
*/
import { getBlockProps } from '@wordpress/blocks';

/**
* Internal dependencies
*/
Expand All @@ -7,6 +12,8 @@ export function useBlockWrapperProps( props = {} ) {
return props;
}

useBlockWrapperProps.save = getBlockProps;

const ExtendedBlockComponent = ELEMENTS.reduce( ( acc, element ) => {
acc[ element ] = element;
return acc;
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/audio/save.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
RichText,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { autoplay, caption, loop, preload, src } = attributes;

return (
src && (
<figure { ...getBlockProps() }>
<figure { ...useBlockWrapperProps.save() }>
<audio
controls="controls"
src={ src }
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/button/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
RichText,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -34,7 +36,7 @@ export default function save( { attributes } ) {
// A title will no longer be assigned for new or updated button block links.

return (
<div { ...getBlockProps() }>
<div { ...useBlockWrapperProps.save() }>
<RichText.Content
tagName="a"
className={ buttonClasses }
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/buttons/save.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
InnerBlocks,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save() {
return (
<div { ...getBlockProps() }>
<div { ...useBlockWrapperProps.save() }>
<InnerBlocks.Content />
</div>
);
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/code/save.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
RichText,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -11,7 +13,7 @@ import { escape } from './utils';

export default function save( { attributes } ) {
return (
<pre { ...getBlockProps() }>
<pre { ...useBlockWrapperProps.save() }>
<RichText.Content
tagName="code"
value={ escape( attributes.content ) }
Expand Down
13 changes: 10 additions & 3 deletions packages/block-library/src/column/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
InnerBlocks,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { verticalAlignment, width } = attributes;
Expand All @@ -22,7 +24,12 @@ export default function save( { attributes } ) {
}

return (
<div { ...getBlockProps( { className: wrapperClasses, style } ) }>
<div
{ ...useBlockWrapperProps.save( {
className: wrapperClasses,
style,
} ) }
>
<InnerBlocks.Content />
</div>
);
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/columns/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
InnerBlocks,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { verticalAlignment } = attributes;
Expand All @@ -17,7 +19,7 @@ export default function save( { attributes } ) {
} );

return (
<div { ...getBlockProps( { className } ) }>
<div { ...useBlockWrapperProps.save( { className } ) }>
<InnerBlocks.Content />
</div>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/cover/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
InnerBlocks,
getColorClassName,
__experimentalGetGradientClass,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -96,7 +96,7 @@ export default function save( { attributes } ) {
);

return (
<div { ...getBlockProps( { className: classes, style } ) }>
<div { ...useBlockWrapperProps.save( { className: classes, style } ) }>
{ url && ( gradient || customGradient ) && dimRatio !== 0 && (
<span
aria-hidden="true"
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/group/save.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
InnerBlocks,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { tagName: Tag } = attributes;

return (
<Tag { ...getBlockProps() }>
<Tag { ...useBlockWrapperProps.save() }>
<div className="wp-block-group__inner-container">
<InnerBlocks.Content />
</div>
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/heading/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
RichText,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { align, content, level } = attributes;
Expand All @@ -18,7 +20,7 @@ export default function save( { attributes } ) {
} );

return (
<TagName { ...getBlockProps( { className } ) }>
<TagName { ...useBlockWrapperProps.save( { className } ) }>
<RichText.Content value={ content } />
</TagName>
);
Expand Down
10 changes: 6 additions & 4 deletions packages/block-library/src/image/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { isEmpty } from 'lodash';
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
RichText,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const {
Expand Down Expand Up @@ -68,14 +70,14 @@ export default function save( { attributes } ) {

if ( 'left' === align || 'right' === align || 'center' === align ) {
return (
<div { ...getBlockProps() }>
<div { ...useBlockWrapperProps.save() }>
<figure className={ classes }>{ figure }</figure>
</div>
);
}

return (
<figure { ...getBlockProps( { className: classes } ) }>
<figure { ...useBlockWrapperProps.save( { className: classes } ) }>
{ figure }
</figure>
);
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/list/save.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
RichText,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { ordered, values, type, reversed, start } = attributes;
const TagName = ordered ? 'ol' : 'ul';

return (
<TagName { ...getBlockProps( { type, reversed, start } ) }>
<TagName { ...useBlockWrapperProps.save( { type, reversed, start } ) }>
<RichText.Content value={ values } multiline="li" />
</TagName>
);
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/media-text/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { noop, isEmpty } from 'lodash';
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
InnerBlocks,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

/**
* Internal dependencies
Expand Down Expand Up @@ -89,7 +91,7 @@ export default function save( { attributes } ) {
gridTemplateColumns,
};
return (
<div { ...getBlockProps( { className, style } ) }>
<div { ...useBlockWrapperProps.save( { className, style } ) }>
<figure
className="wp-block-media-text__media"
style={ backgroundStyles }
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/paragraph/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
RichText,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { align, content, dropCap, direction } = attributes;
Expand All @@ -17,7 +19,7 @@ export default function save( { attributes } ) {
} );

return (
<p { ...getBlockProps( { className, dir: direction } ) }>
<p { ...useBlockWrapperProps.save( { className, dir: direction } ) }>
<RichText.Content value={ content } />
</p>
);
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/preformatted/save.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
RichText,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { content } = attributes;

return (
<pre { ...getBlockProps() }>
<pre { ...useBlockWrapperProps.save() }>
<RichText.Content value={ content } />
</pre>
);
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/quote/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { RichText } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
RichText,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save( { attributes } ) {
const { align, value, citation } = attributes;
Expand All @@ -17,7 +19,7 @@ export default function save( { attributes } ) {
} );

return (
<blockquote { ...getBlockProps( { className } ) }>
<blockquote { ...useBlockWrapperProps.save( { className } ) }>
<RichText.Content multiline value={ value } />
{ ! RichText.isEmpty( citation ) && (
<RichText.Content tagName="cite" value={ citation } />
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/social-links/save.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* WordPress dependencies
*/
import { InnerBlocks } from '@wordpress/block-editor';
import { getBlockProps } from '@wordpress/blocks';
import {
InnerBlocks,
__experimentalUseBlockWrapperProps as useBlockWrapperProps,
} from '@wordpress/block-editor';

export default function save() {
return (
<ul { ...getBlockProps() }>
<ul { ...useBlockWrapperProps.save() }>
<InnerBlocks.Content />
</ul>
);
Expand Down
Loading

0 comments on commit 84aeb9e

Please sign in to comment.