Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix conflict
  • Loading branch information
glendaviesnz committed Apr 4, 2023
commit d5659a8e495b905ba6db4b6b4a6e1515335de505
5 changes: 4 additions & 1 deletion packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,10 @@ export { default as URLPopover } from './url-popover';
export { __experimentalImageURLInputUI } from './url-popover/image-url-input-ui';
export { default as withColorContext } from './color-palette/with-color-context';
export { default as __experimentalSpacingSizesControl } from './spacing-sizes-control';

export {
getSpacingPresetCssVar,
isValueSpacingPreset,
} from './spacing-sizes-control/utils';
/*
* Content Related Components
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function SpacingSizesControl( {
onMouseOver,
onMouseOut,
} ) {
console.log( 'values', values );
const spacingSizes = [
{ name: 0, slug: '0', size: 0 },
...( useSetting( 'spacing.spacingSizes' ) || [] ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { settings } from '@wordpress/icons';
import { usePrevious } from '@wordpress/compose';

/**
* Internal dependencies
Expand Down Expand Up @@ -71,6 +72,15 @@ export default function SpacingInputControl( {
! isValueSpacingPreset( value )
);

const previousValue = usePrevious( value );
if (
isValueSpacingPreset( previousValue ) &&
! isValueSpacingPreset( value ) &&
showCustomValueControl !== true
) {
setShowCustomValueControl( true );
}

const units = useCustomUnits( {
availableUnits: useSetting( 'spacing.units' ) || [ 'px', 'em', 'rem' ],
} );
Expand Down
52 changes: 34 additions & 18 deletions packages/block-library/src/spacer/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { InspectorControls, useSetting } from '@wordpress/block-editor';
import {
InspectorControls,
useSetting,
__experimentalSpacingSizesControl as SpacingSizesControl,
isValueSpacingPreset,
} from '@wordpress/block-editor';
import {
UnitControl,
PanelBody,
__experimentalUseCustomUnits as useCustomUnits,
__experimentalUnitControl as UnitControl,
__experimentalParseQuantityAndUnitFromRawValue as parseQuantityAndUnitFromRawValue,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
Expand All @@ -18,7 +23,6 @@ import { MIN_SPACER_SIZE } from './constants';

function DimensionInput( { label, onChange, isResizing, value = '' } ) {
const inputId = useInstanceId( UnitControl, 'block-spacer-height-input' );

// In most contexts the spacer size cannot meaningfully be set to a
// percentage, since this is relative to the parent container. This
// unit is disabled from the UI.
Expand All @@ -38,28 +42,40 @@ function DimensionInput( { label, onChange, isResizing, value = '' } ) {
} );

const handleOnChange = ( unprocessedValue ) => {
onChange( unprocessedValue );
onChange( unprocessedValue.all );
};

// Force the unit to update to `px` when the Spacer is being resized.
const [ parsedQuantity, parsedUnit ] =
parseQuantityAndUnitFromRawValue( value );
const computedValue = [
parsedQuantity,
isResizing ? 'px' : parsedUnit,
].join( '' );
const computedValue = isValueSpacingPreset( value )
? value
: [ parsedQuantity, isResizing ? 'px' : parsedUnit ].join( '' );

return (
<UnitControl
label={ label }
id={ inputId }
isResetValueOnUnitChange
min={ MIN_SPACER_SIZE }
onChange={ handleOnChange }
__unstableInputWidth={ '80px' }
value={ computedValue }
units={ units }
/>
<>
<UnitControl
label={ label }
id={ inputId }
isResetValueOnUnitChange
min={ MIN_SPACER_SIZE }
onChange={ handleOnChange }
__unstableInputWidth={ '80px' }
value={ computedValue }
units={ units }
/>
<div className="tools-panel-item-spacing">
<SpacingSizesControl
values={ { all: computedValue } }
onChange={ handleOnChange }
label={ label }
sides={ [ 'all' ] }
units={ units }
allowReset={ false }
splitOnAxis={ false }
/>
</div>
</>
);
}

Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/spacer/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useBlockProps } from '@wordpress/block-editor';
import { useBlockProps, getSpacingPresetCssVar } from '@wordpress/block-editor';
import { ResizableBox } from '@wordpress/components';
import { useState, useEffect } from '@wordpress/element';
import { View } from '@wordpress/primitives';
Expand Down Expand Up @@ -114,10 +114,12 @@ const SpacerEdit = ( {
height:
inheritedOrientation === 'horizontal'
? 24
: temporaryHeight || height || undefined,
: temporaryHeight ||
getSpacingPresetCssVar( height ) ||
undefined,
width:
inheritedOrientation === 'horizontal'
? temporaryWidth || width || undefined
? temporaryWidth || getSpacingPresetCssVar( width ) || undefined
: undefined,
// In vertical flex containers, the spacer shrinks to nothing without a minimum width.
minWidth:
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/spacer/save.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* WordPress dependencies
*/
import { useBlockProps } from '@wordpress/block-editor';
import { useBlockProps, getSpacingPresetCssVar } from '@wordpress/block-editor';

export default function save( { attributes: { height, width } } ) {
return (
<div
{ ...useBlockProps.save( {
style: {
height,
width,
height: getSpacingPresetCssVar( height ),
width: getSpacingPresetCssVar( width ),
},
'aria-hidden': true,
} ) }
Expand Down