Skip to content

Commit 00f6ef7

Browse files
Mamadukadonnapep
authored andcommitted
Add reset button to Layout controls (#30828)
1 parent cc42d27 commit 00f6ef7

File tree

2 files changed

+69
-42
lines changed

2 files changed

+69
-42
lines changed

packages/block-editor/src/hooks/layout.js

Lines changed: 62 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { addFilter } from '@wordpress/hooks';
1313
import { hasBlockSupport } from '@wordpress/blocks';
1414
import { useSelect } from '@wordpress/data';
1515
import {
16+
Button,
1617
ToggleControl,
1718
PanelBody,
1819
__experimentalUnitControl as UnitControl,
@@ -82,52 +83,72 @@ function LayoutPanel( { setAttributes, attributes } ) {
8283
/>
8384
) }
8485
{ ! inherit && (
85-
<div className="block-editor-hooks__layout-controls">
86-
<div className="block-editor-hooks__layout-controls-unit">
87-
<UnitControl
88-
label={ __( 'Content' ) }
89-
labelPosition="top"
90-
__unstableInputWidth="80px"
91-
value={ contentSize || wideSize || '' }
92-
onChange={ ( nextWidth ) => {
93-
nextWidth =
94-
0 > parseFloat( nextWidth )
95-
? '0'
96-
: nextWidth;
97-
setAttributes( {
98-
layout: {
99-
...layout,
100-
contentSize: nextWidth,
101-
},
102-
} );
103-
} }
104-
units={ CSS_UNITS }
105-
/>
106-
<Icon icon={ positionCenter } />
86+
<>
87+
<div className="block-editor-hooks__layout-controls">
88+
<div className="block-editor-hooks__layout-controls-unit">
89+
<UnitControl
90+
label={ __( 'Content' ) }
91+
labelPosition="top"
92+
__unstableInputWidth="80px"
93+
value={ contentSize || wideSize || '' }
94+
onChange={ ( nextWidth ) => {
95+
nextWidth =
96+
0 > parseFloat( nextWidth )
97+
? '0'
98+
: nextWidth;
99+
setAttributes( {
100+
layout: {
101+
...layout,
102+
contentSize: nextWidth,
103+
},
104+
} );
105+
} }
106+
units={ CSS_UNITS }
107+
/>
108+
<Icon icon={ positionCenter } />
109+
</div>
110+
<div className="block-editor-hooks__layout-controls-unit">
111+
<UnitControl
112+
label={ __( 'Wide' ) }
113+
labelPosition="top"
114+
__unstableInputWidth="80px"
115+
value={ wideSize || contentSize || '' }
116+
onChange={ ( nextWidth ) => {
117+
nextWidth =
118+
0 > parseFloat( nextWidth )
119+
? '0'
120+
: nextWidth;
121+
setAttributes( {
122+
layout: {
123+
...layout,
124+
wideSize: nextWidth,
125+
},
126+
} );
127+
} }
128+
units={ CSS_UNITS }
129+
/>
130+
<Icon icon={ stretchWide } />
131+
</div>
107132
</div>
108-
<div className="block-editor-hooks__layout-controls-unit">
109-
<UnitControl
110-
label={ __( 'Wide' ) }
111-
labelPosition="top"
112-
__unstableInputWidth="80px"
113-
value={ wideSize || contentSize || '' }
114-
onChange={ ( nextWidth ) => {
115-
nextWidth =
116-
0 > parseFloat( nextWidth )
117-
? '0'
118-
: nextWidth;
133+
<div className="block-editor-hooks__layout-controls-reset">
134+
<Button
135+
isSecondary
136+
isSmall
137+
disabled={ ! contentSize && ! wideSize }
138+
onClick={ () =>
119139
setAttributes( {
120140
layout: {
121-
...layout,
122-
wideSize: nextWidth,
141+
contentSize: undefined,
142+
wideSize: undefined,
143+
inherit: false,
123144
},
124-
} );
125-
} }
126-
units={ CSS_UNITS }
127-
/>
128-
<Icon icon={ stretchWide } />
145+
} )
146+
}
147+
>
148+
{ __( 'Reset' ) }
149+
</Button>
129150
</div>
130-
</div>
151+
</>
131152
) }
132153
<p className="block-editor-hooks__layout-controls-helptext">
133154
{ __(

packages/block-editor/src/hooks/layout.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.block-editor-hooks__layout-controls {
22
display: flex;
3-
margin-bottom: $grid-unit-30;
3+
margin-bottom: $grid-unit-20;
44

55
.block-editor-hooks__layout-controls-unit {
66
display: flex;
@@ -12,6 +12,12 @@
1212
}
1313
}
1414

15+
.block-editor-hooks__layout-controls-reset {
16+
display: flex;
17+
justify-content: flex-end;
18+
margin-bottom: $grid-unit-30;
19+
}
20+
1521
.block-editor-hooks__layout-controls-helptext {
1622
font-size: $helptext-font-size;
1723
}

0 commit comments

Comments
 (0)