Skip to content

Commit

Permalink
Implement disabling of custom space sizes (#43216)
Browse files Browse the repository at this point in the history
  • Loading branch information
glendaviesnz authored Aug 16, 2022
1 parent a175df3 commit 92846ed
Showing 1 changed file with 32 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { useState, useMemo } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import {
Button,
RangeControl,
Expand All @@ -24,6 +25,7 @@ import { settings } from '@wordpress/icons';
* Internal dependencies
*/
import useSetting from '../use-setting';
import { store as blockEditorStore } from '../../store';
import {
LABELS,
getSliderValueFromPreset,
Expand All @@ -43,8 +45,15 @@ export default function SpacingInputControl( {
let selectListSizes = spacingSizes;
const showRangeControl = spacingSizes.length <= 8;

const disableCustomSpacingSizes = useSelect( ( select ) => {
const editorSettings = select( blockEditorStore ).getSettings();
return editorSettings?.disableCustomSpacingSizes;
} );

const [ showCustomValueControl, setShowCustomValueControl ] = useState(
value !== undefined && ! isValueSpacingPreset( value )
! disableCustomSpacingSizes &&
value !== undefined &&
! isValueSpacingPreset( value )
);

const units = useCustomUnits( {
Expand Down Expand Up @@ -171,26 +180,28 @@ export default function SpacingInputControl( {
</Text>
) }

<Button
label={
showCustomValueControl
? __( 'Use size preset' )
: __( 'Set custom size' )
}
icon={ settings }
onClick={ () => {
setShowCustomValueControl( ! showCustomValueControl );
} }
isPressed={ showCustomValueControl }
isSmall
className={ classnames( {
'components-spacing-sizes-control__custom-toggle-all':
side === 'all',
'components-spacing-sizes-control__custom-toggle-single':
side !== 'all',
} ) }
iconSize={ 24 }
/>
{ ! disableCustomSpacingSizes && (
<Button
label={
showCustomValueControl
? __( 'Use size preset' )
: __( 'Set custom size' )
}
icon={ settings }
onClick={ () => {
setShowCustomValueControl( ! showCustomValueControl );
} }
isPressed={ showCustomValueControl }
isSmall
className={ classnames( {
'components-spacing-sizes-control__custom-toggle-all':
side === 'all',
'components-spacing-sizes-control__custom-toggle-single':
side !== 'all',
} ) }
iconSize={ 24 }
/>
) }
{ showCustomValueControl && (
<>
<UnitControl
Expand Down

0 comments on commit 92846ed

Please sign in to comment.