Skip to content

Commit

Permalink
Reset block spacing back to the default value rather than removing it
Browse files Browse the repository at this point in the history
  • Loading branch information
scruffian committed Dec 8, 2020
1 parent e1481dd commit dc32817
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
12 changes: 11 additions & 1 deletion packages/block-editor/src/hooks/padding.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { Platform } from '@wordpress/element';
import { getBlockSupport } from '@wordpress/blocks';
import { getBlockSupport, getBlockType } from '@wordpress/blocks';
import { __experimentalBoxControl as BoxControl } from '@wordpress/components';

/**
Expand Down Expand Up @@ -65,13 +65,23 @@ export function PaddingEdit( props ) {
} );
};

const onReset = () => {
const blockType = getBlockType( blockName );
const defaultSettings = blockType?.attributes?.style?.default;

setAttributes( {
style: cleanEmptyObject( defaultSettings ),
} );
};

return Platform.select( {
web: (
<>
<BoxControl
values={ style?.spacing?.padding }
onChange={ onChange }
onChangeShowVisualizer={ onChangeShowVisualizer }
onReset={ onReset }
label={ __( 'Padding' ) }
units={ units }
/>
Expand Down
6 changes: 6 additions & 0 deletions packages/block-library/src/verse/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
AlignmentToolbar,
useBlockProps,
} from '@wordpress/block-editor';
import { __experimentalBoxControl as BoxControl } from '@wordpress/components';
const { __Visualizer: BoxControlVisualizer } = BoxControl;

export default function VerseEdit( {
attributes,
Expand All @@ -36,6 +38,10 @@ export default function VerseEdit( {
} }
/>
</BlockControls>
<BoxControlVisualizer
values={ attributes.style?.spacing?.padding }
showValues={ attributes.style?.visualizers?.padding }
/>
<RichText
tagName="pre"
identifier="content"
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/box-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function BoxControl( {
inputProps = defaultInputProps,
onChange = noop,
onChangeShowVisualizer = noop,
onReset = noop,
label = __( 'Box Control' ),
values: valuesProp,
units,
Expand Down Expand Up @@ -94,7 +95,7 @@ export default function BoxControl( {
const handleOnReset = () => {
const initialValues = DEFAULT_VALUES;

onChange( initialValues );
onReset();
setValues( initialValues );
setIsDirty( false );
};
Expand Down

0 comments on commit dc32817

Please sign in to comment.