From 15a81af4fedcadeccee3072c6ac0f9f2ab791788 Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Fri, 18 Mar 2022 15:18:48 +0100 Subject: [PATCH] Separate width/height constraints for horizontal or vertical configurations --- packages/block-library/src/spacer/controls.js | 24 +++++++++++++++---- .../src/spacer/controls.native.js | 19 ++++++++++++--- packages/block-library/src/spacer/edit.js | 16 +++++++------ 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/packages/block-library/src/spacer/controls.js b/packages/block-library/src/spacer/controls.js index 097fe1cd024ff..a10b6f978fe36 100644 --- a/packages/block-library/src/spacer/controls.js +++ b/packages/block-library/src/spacer/controls.js @@ -15,9 +15,21 @@ import { useState } from '@wordpress/element'; /** * Internal dependencies */ -import { MIN_SPACER_SIZE, MAX_SPACER_SIZE } from './edit'; +import { + MIN_SPACER_WIDTH, + MAX_SPACER_WIDTH, + MIN_SPACER_HEIGHT, + MAX_SPACER_HEIGHT, +} from './edit'; -function DimensionInput( { label, onChange, isResizing, value = '' } ) { +function DimensionInput( { + label, + onChange, + isResizing, + value = '', + min, + max, +} ) { const [ temporaryInput, setTemporaryInput ] = useState( null ); const inputId = useInstanceId( UnitControl, 'block-spacer-height-input' ); @@ -58,8 +70,8 @@ function DimensionInput( { label, onChange, isResizing, value = '' } ) { ) } { orientation !== 'horizontal' && ( @@ -100,6 +114,8 @@ export default function SpacerControls( { setAttributes( { height: nextHeight } ) } isResizing={ isResizing } + min={ MIN_SPACER_HEIGHT } + max={ MAX_SPACER_HEIGHT } /> ) } diff --git a/packages/block-library/src/spacer/controls.native.js b/packages/block-library/src/spacer/controls.native.js index 77d6a56da2992..869345b89103f 100644 --- a/packages/block-library/src/spacer/controls.native.js +++ b/packages/block-library/src/spacer/controls.native.js @@ -14,7 +14,12 @@ import { __ } from '@wordpress/i18n'; /** * Internal dependencies */ -import { MIN_SPACER_SIZE, MAX_SPACER_SIZE } from './edit'; +import { + MIN_SPACER_WIDTH, + MAX_SPACER_WIDTH, + MIN_SPACER_HEIGHT, + MAX_SPACER_HEIGHT, +} from './edit'; import styles from './style.scss'; const DEFAULT_VALUES = { px: 100, em: 10, rem: 10, vw: 10, vh: 25 }; @@ -67,8 +72,16 @@ function Controls( { attributes, context, setAttributes } ) { { const nextVal = Math.min( - MAX_SPACER_SIZE, + orientation === 'horizontal' + ? MAX_SPACER_WIDTH + : MAX_SPACER_HEIGHT, getCurrentSize( elt ) ); onResizeStop( `${ nextVal }px` ); @@ -122,8 +126,7 @@ const SpacerEdit = ( { if ( blockOrientation === 'horizontal' ) { return (