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

Add reset button to Layout controls #30828

Merged
merged 1 commit into from
May 6, 2021
Merged
Show file tree
Hide file tree
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
103 changes: 62 additions & 41 deletions packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { addFilter } from '@wordpress/hooks';
import { hasBlockSupport } from '@wordpress/blocks';
import { useSelect } from '@wordpress/data';
import {
Button,
ToggleControl,
PanelBody,
__experimentalUnitControl as UnitControl,
Expand Down Expand Up @@ -82,52 +83,72 @@ function LayoutPanel( { setAttributes, attributes } ) {
/>
) }
{ ! inherit && (
<div className="block-editor-hooks__layout-controls">
<div className="block-editor-hooks__layout-controls-unit">
<UnitControl
label={ __( 'Content' ) }
labelPosition="top"
__unstableInputWidth="80px"
value={ contentSize || wideSize || '' }
onChange={ ( nextWidth ) => {
nextWidth =
0 > parseFloat( nextWidth )
? '0'
: nextWidth;
setAttributes( {
layout: {
...layout,
contentSize: nextWidth,
},
} );
} }
units={ CSS_UNITS }
/>
<Icon icon={ positionCenter } />
<>
<div className="block-editor-hooks__layout-controls">
<div className="block-editor-hooks__layout-controls-unit">
<UnitControl
label={ __( 'Content' ) }
labelPosition="top"
__unstableInputWidth="80px"
value={ contentSize || wideSize || '' }
onChange={ ( nextWidth ) => {
nextWidth =
0 > parseFloat( nextWidth )
? '0'
: nextWidth;
setAttributes( {
layout: {
...layout,
contentSize: nextWidth,
},
} );
} }
units={ CSS_UNITS }
/>
<Icon icon={ positionCenter } />
</div>
<div className="block-editor-hooks__layout-controls-unit">
<UnitControl
label={ __( 'Wide' ) }
labelPosition="top"
__unstableInputWidth="80px"
value={ wideSize || contentSize || '' }
onChange={ ( nextWidth ) => {
nextWidth =
0 > parseFloat( nextWidth )
? '0'
: nextWidth;
setAttributes( {
layout: {
...layout,
wideSize: nextWidth,
},
} );
} }
units={ CSS_UNITS }
/>
<Icon icon={ stretchWide } />
</div>
</div>
<div className="block-editor-hooks__layout-controls-unit">
<UnitControl
label={ __( 'Wide' ) }
labelPosition="top"
__unstableInputWidth="80px"
value={ wideSize || contentSize || '' }
onChange={ ( nextWidth ) => {
nextWidth =
0 > parseFloat( nextWidth )
? '0'
: nextWidth;
<div className="block-editor-hooks__layout-controls-reset">
<Button
isSecondary
isSmall
disabled={ ! contentSize && ! wideSize }
onClick={ () =>
setAttributes( {
layout: {
...layout,
wideSize: nextWidth,
contentSize: undefined,
wideSize: undefined,
inherit: false,
},
} );
} }
units={ CSS_UNITS }
/>
<Icon icon={ stretchWide } />
} )
}
>
{ __( 'Reset' ) }
</Button>
</div>
</div>
</>
) }
<p className="block-editor-hooks__layout-controls-helptext">
{ __(
Expand Down
8 changes: 7 additions & 1 deletion packages/block-editor/src/hooks/layout.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.block-editor-hooks__layout-controls {
display: flex;
margin-bottom: $grid-unit-30;
margin-bottom: $grid-unit-20;

.block-editor-hooks__layout-controls-unit {
display: flex;
Expand All @@ -12,6 +12,12 @@
}
}

.block-editor-hooks__layout-controls-reset {
display: flex;
justify-content: flex-end;
margin-bottom: $grid-unit-30;
}

.block-editor-hooks__layout-controls-helptext {
font-size: $helptext-font-size;
}