diff --git a/packages/block-editor/src/hooks/dimensions.scss b/packages/block-editor/src/hooks/dimensions.scss new file mode 100644 index 00000000000000..e67e16ad92295c --- /dev/null +++ b/packages/block-editor/src/hooks/dimensions.scss @@ -0,0 +1,5 @@ +.dimensions-block-support-panel { + .single-column { + grid-column: span 1; + } +} diff --git a/packages/block-editor/src/style.scss b/packages/block-editor/src/style.scss index 6cb68d820be86b..40a672fb2890be 100644 --- a/packages/block-editor/src/style.scss +++ b/packages/block-editor/src/style.scss @@ -56,6 +56,7 @@ @import "./hooks/anchor.scss"; @import "./hooks/layout.scss"; @import "./hooks/border.scss"; +@import "./hooks/dimensions.scss"; @import "./hooks/typography.scss"; @import "./components/block-toolbar/style.scss"; diff --git a/packages/block-library/src/post-featured-image/dimension-controls.js b/packages/block-library/src/post-featured-image/dimension-controls.js index d0db990f50d7dd..424001efb50db3 100644 --- a/packages/block-library/src/post-featured-image/dimension-controls.js +++ b/packages/block-library/src/post-featured-image/dimension-controls.js @@ -1,22 +1,15 @@ -/** - * External dependencies - */ -import classNames from 'classnames'; - /** * WordPress dependencies */ import { __, _x } from '@wordpress/i18n'; import { - PanelBody, __experimentalUnitControl as UnitControl, - Flex, - FlexItem, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption, __experimentalUseCustomUnits as useCustomUnits, + __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; -import { useSetting } from '@wordpress/block-editor'; +import { InspectorControls, useSetting } from '@wordpress/block-editor'; const SCALE_OPTIONS = ( <> @@ -38,6 +31,8 @@ const SCALE_OPTIONS = ( ); +const DEFAULT_SCALE = 'cover'; + const scaleHelp = { cover: __( 'Image is scaled and cropped to fill the entire space without being distorted.' @@ -51,6 +46,7 @@ const scaleHelp = { }; const DimensionControls = ( { + clientId, attributes: { width, height, scale }, setAttributes, } ) => { @@ -72,53 +68,82 @@ const DimensionControls = ( { }; const scaleLabel = _x( 'Scale', 'Image scaling options' ); return ( - - + !! height } + label={ __( 'Height' ) } + onDeselect={ () => setAttributes( { height: undefined } ) } + resetAllFilter={ () => ( { + height: undefined, + } ) } + isShownByDefault={ true } + panelId={ clientId } + > + + onDimensionChange( 'height', nextHeight ) + } + units={ units } + /> + + !! width } + label={ __( 'Width' ) } + onDeselect={ () => setAttributes( { width: undefined } ) } + resetAllFilter={ () => ( { + width: undefined, + } ) } + isShownByDefault={ true } + panelId={ clientId } > - - { - onDimensionChange( 'height', nextHeight ); - } } - units={ units } - /> - - - { - onDimensionChange( 'width', nextWidth ); - } } - units={ units } - /> - - + + onDimensionChange( 'width', nextWidth ) + } + units={ units } + /> + { !! height && ( - !! scale && scale !== DEFAULT_SCALE } label={ scaleLabel } - value={ scale } - help={ scaleHelp[ scale ] } - onChange={ ( value ) => { + onDeselect={ () => setAttributes( { - scale: value, - } ); - } } - isBlock + scale: DEFAULT_SCALE, + } ) + } + resetAllFilter={ () => ( { + scale: DEFAULT_SCALE, + } ) } + isShownByDefault={ true } + panelId={ clientId } > - { SCALE_OPTIONS } - + + setAttributes( { + scale: value, + } ) + } + isBlock + > + { SCALE_OPTIONS } + + ) } - + ); }; diff --git a/packages/block-library/src/post-featured-image/edit.js b/packages/block-library/src/post-featured-image/edit.js index 828ff26fb121b5..ca52ffcb694057 100644 --- a/packages/block-library/src/post-featured-image/edit.js +++ b/packages/block-library/src/post-featured-image/edit.js @@ -47,6 +47,7 @@ const placeholderChip = ( ); function PostFeaturedImageDisplay( { + clientId, attributes, setAttributes, context: { postId, postType, queryId }, @@ -137,11 +138,12 @@ function PostFeaturedImageDisplay( { return ( <> + -