Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spacing presets: Implement disabling of custom space sizes #43216

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Changes from all commits
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
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