diff --git a/packages/block-library/src/group/block.json b/packages/block-library/src/group/block.json index 8883720bbc2aa..521a835394878 100644 --- a/packages/block-library/src/group/block.json +++ b/packages/block-library/src/group/block.json @@ -13,6 +13,22 @@ }, "customTextColor": { "type": "string" + }, + "paddingUnit": { + "type": "string", + "default": "px" + }, + "paddingSize": { + "type": "string", + "default": "" + }, + "marginUnit": { + "type": "string", + "default": "px" + }, + "marginSize": { + "type": "string", + "default": "" } } } diff --git a/packages/block-library/src/group/edit.js b/packages/block-library/src/group/edit.js index 80f496967f599..6b706f6462585 100644 --- a/packages/block-library/src/group/edit.js +++ b/packages/block-library/src/group/edit.js @@ -1,12 +1,29 @@ +/** + * External dependencies + */ +import { partialRight } from 'lodash'; +import classnames from 'classnames'; + /** * WordPress dependencies */ import { withSelect } from '@wordpress/data'; import { compose } from '@wordpress/compose'; -import { InnerBlocks, __experimentalUseColors } from '@wordpress/block-editor'; +import { + InnerBlocks, + __experimentalUseColors, + InspectorControls, +} from '@wordpress/block-editor'; import { useRef } from '@wordpress/element'; -function GroupEdit( { hasInnerBlocks, className } ) { +import { + PanelBody, + __experimentalDimensionControl as DimensionControl, +} from '@wordpress/components'; + +import { __ } from '@wordpress/i18n'; + +function GroupEdit( { hasInnerBlocks, className, attributes, setAttributes } ) { const ref = useRef(); const { TextColor, @@ -23,12 +40,60 @@ function GroupEdit( { hasInnerBlocks, className } ) { } ); + /** + * Updates the spacing attribute for a given dimension + * (and optionally a given viewport) + * + * @param {string} size a slug representing a dimension size (eg: `medium`) + * @param {string} dimensionAttr the dimension attribute for a property (eg: `paddingSize`) + * @return {void} + */ + const updateSpacing = ( size, dimensionAttr ) => { + setAttributes( { + [ dimensionAttr ]: size, + } ); + }; + + const hasPadding = !! attributes.paddingSize; + const hasMargin = !! attributes.marginSize; + + const classes = classnames( className, { + 'has-padding': hasPadding, + 'has-margin': hasMargin, + [ `padding-${ attributes.paddingSize }` ]: hasPadding, + [ `margin-${ attributes.marginSize }` ]: hasMargin, + } ); + return ( <> { InspectorControlsColorPanel } + + + + + + + -
+
{ @@ -72,6 +73,7 @@ export function DimensionControl( props ) { value={ value } onChange={ onChangeSpacingSize } options={ formatSizesAsOptions( sizes ) } + help={ help } /> ); } diff --git a/packages/components/src/dimension-control/style.scss b/packages/components/src/dimension-control/style.scss index 7f1481747dfe1..302941fb4dc4a 100644 --- a/packages/components/src/dimension-control/style.scss +++ b/packages/components/src/dimension-control/style.scss @@ -10,13 +10,20 @@ align-items: center; margin-right: 1em; margin-bottom: 0; + width: 10em; // ensure labels and fields align right .dashicon { margin-right: 0.5em; + flex-shrink: 0; } } - &.is-manual .components-base-control__label { - width: 10em; + .components-base-control__help { + display: flex; + align-items: center; + margin-top: -4px; + margin-left: auto; + margin-bottom: 0; + padding-left: 7em; } } diff --git a/packages/components/src/dimension-control/test/__snapshots__/index.test.js.snap b/packages/components/src/dimension-control/test/__snapshots__/index.test.js.snap index 45b7a137fb9c8..161bd6941fabe 100644 --- a/packages/components/src/dimension-control/test/__snapshots__/index.test.js.snap +++ b/packages/components/src/dimension-control/test/__snapshots__/index.test.js.snap @@ -3,6 +3,7 @@ exports[`DimensionControl rendering renders with custom sizes 1`] = ` @@ -36,6 +37,7 @@ exports[`DimensionControl rendering renders with custom sizes 1`] = ` exports[`DimensionControl rendering renders with defaults 1`] = ` @@ -77,6 +79,7 @@ exports[`DimensionControl rendering renders with defaults 1`] = ` exports[`DimensionControl rendering renders with icon and custom icon label 1`] = ` @@ -130,6 +133,7 @@ exports[`DimensionControl rendering renders with icon and custom icon label 1`] exports[`DimensionControl rendering renders with icon and default icon label 1`] = ` diff --git a/packages/e2e-tests/fixtures/blocks/core__group.json b/packages/e2e-tests/fixtures/blocks/core__group.json index 71d94f926dccc..f2f1df46cc1a1 100644 --- a/packages/e2e-tests/fixtures/blocks/core__group.json +++ b/packages/e2e-tests/fixtures/blocks/core__group.json @@ -5,7 +5,11 @@ "isValid": true, "attributes": { "backgroundColor": "secondary", - "align": "full" + "align": "full", + "marginSize": "", + "marginUnit": "px", + "paddingSize": "", + "paddingUnit": "px" }, "innerBlocks": [ {