diff --git a/lib/experimental-default-theme.json b/lib/experimental-default-theme.json index 1d1cfdabce390f..956452f20a64dc 100644 --- a/lib/experimental-default-theme.json +++ b/lib/experimental-default-theme.json @@ -122,6 +122,11 @@ "slug": "vivid-cyan-blue-to-vivid-purple", "value": "linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)" } + ], + "padding": [ + { "slug": "small", "value": 4 }, + { "slug": "regular", "value": 16 }, + { "slug": "large", "value": 32 } ] }, "features": { diff --git a/packages/block-editor/README.md b/packages/block-editor/README.md index 86371a46848c6b..5815ccaceab868 100644 --- a/packages/block-editor/README.md +++ b/packages/block-editor/README.md @@ -478,6 +478,7 @@ _Properties_ - _colors_ `Array`: Palette colors - _disableCustomColors_ `boolean`: Whether or not the custom colors are disabled - _fontSizes_ `Array`: Available font sizes +- _padding_ `Array`: Available padding values - _disableCustomFontSizes_ `boolean`: Whether or not the custom font sizes are disabled - _imageSizes_ `Array`: Available image sizes - _maxWidth_ `number`: Max width to constraint resizing diff --git a/packages/block-editor/src/hooks/padding.js b/packages/block-editor/src/hooks/padding.js index e042a2de83cac4..ecde2be4af7264 100644 --- a/packages/block-editor/src/hooks/padding.js +++ b/packages/block-editor/src/hooks/padding.js @@ -11,6 +11,7 @@ import { __experimentalBoxControl as BoxControl } from '@wordpress/components'; */ import { cleanEmptyObject } from './utils'; import { useCustomUnits } from '../components/unit-control'; +import { useSelect } from '@wordpress/data'; export const PADDING_SUPPORT_KEY = '__experimentalPadding'; @@ -29,6 +30,9 @@ export function PaddingEdit( props ) { } = props; const units = useCustomUnits(); + const { padding } = useSelect( ( select ) => + select( 'core/block-editor' ).getSettings() + ); if ( ! hasBlockSupport( blockName, PADDING_SUPPORT_KEY ) ) { return null; @@ -64,6 +68,7 @@ export function PaddingEdit( props ) { web: ( <> { + const nextValues = { + top: value, + right: value, + bottom: value, + left: value, + }; + onChange( nextValues ); + setValues( nextValues ); + setIsDirty( true ); + }; + const inputControlProps = { ...inputProps, onChange: handleOnChange, @@ -109,6 +136,28 @@ export default function BoxControl( { values: inputValues, }; + const presetUnit = units ? units : 'px'; + const options = [ + DEFAULT_OPTION, + ...presetValues.map( ( presetValue ) => ( { + key: presetValue.slug, + name: presetValue.name, + value: presetValue.value + presetUnit, + } ) ), + CUSTOM_OPTION, + ]; + let selectedOption = DEFAULT_OPTION; + if ( + !! inputValues?.top && + inputValues?.top === inputValues?.right && + inputValues?.top === inputValues?.bottom && + inputValues?.top === inputValues?.left + ) { + selectedOption = + options.find( ( option ) => option.value === inputValues.top ) || + CUSTOM_OPTION; + } + return (
@@ -120,6 +169,25 @@ export default function BoxControl( { { label } + + + +
+ + + + + + +