Skip to content

Commit

Permalink
Layout content and wide width controls: remove confusing icon and cla…
Browse files Browse the repository at this point in the history
…rify labels (#64891)

* Remove confusing icons.

* Used 40px input size.

* Improve content and wide widths labeling.

* Remove confusing icons from block settings constrained layout widths.

* Try icons in input prefix.

* Adjust vertical spacing.

Co-authored-by: afercia <[email protected]>
Co-authored-by: mirka <[email protected]>
Co-authored-by: ciampo <[email protected]>
Co-authored-by: t-hamano <[email protected]>
Co-authored-by: tyxla <[email protected]>
Co-authored-by: jameskoster <[email protected]>
Co-authored-by: richtabor <[email protected]>
Co-authored-by: MaggieCabrera <[email protected]>
  • Loading branch information
9 people authored Sep 3, 2024
1 parent 30258b5 commit 6058323
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import {
__experimentalToolsPanel as ToolsPanel,
__experimentalToolsPanelItem as ToolsPanelItem,
__experimentalBoxControl as BoxControl,
__experimentalHStack as HStack,
__experimentalUnitControl as UnitControl,
__experimentalUseCustomUnits as useCustomUnits,
__experimentalView as View,
__experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,
} from '@wordpress/components';
import { Icon, positionCenter, stretchWide } from '@wordpress/icons';
import { Icon, alignNone, stretchWide } from '@wordpress/icons';
import { useCallback, useState, Platform } from '@wordpress/element';

/**
Expand Down Expand Up @@ -252,7 +251,7 @@ export default function DimensionsPanel( {
const minimumMargin = -Infinity;
const [ minMarginValue, setMinMarginValue ] = useState( minimumMargin );

// Content Size
// Content Width
const showContentSizeControl =
useHasContentSize( settings ) && includeLayoutControls;
const contentSizeValue = decodeValue( inheritedValue?.layout?.contentSize );
Expand All @@ -268,7 +267,7 @@ export default function DimensionsPanel( {
const hasUserSetContentSizeValue = () => !! value?.layout?.contentSize;
const resetContentSizeValue = () => setContentSizeValue( undefined );

// Wide Size
// Wide Width
const showWideSizeControl =
useHasWideSize( settings ) && includeLayoutControls;
const wideSizeValue = decodeValue( inheritedValue?.layout?.wideSize );
Expand Down Expand Up @@ -464,8 +463,7 @@ export default function DimensionsPanel( {
) }
{ showContentSizeControl && (
<ToolsPanelItem
className="single-column"
label={ __( 'Content size' ) }
label={ __( 'Content width' ) }
hasValue={ hasUserSetContentSizeValue }
onDeselect={ resetContentSizeValue }
isShownByDefault={
Expand All @@ -474,53 +472,48 @@ export default function DimensionsPanel( {
}
panelId={ panelId }
>
<HStack alignment="flex-end" justify="flex-start">
<UnitControl
// TODO: Switch to `true` (40px size) if possible (https://github.com/WordPress/gutenberg/pull/64520#discussion_r1717314262)
__next40pxDefaultSize={ false }
label={ __( 'Content' ) }
labelPosition="top"
__unstableInputWidth="80px"
value={ contentSizeValue || '' }
onChange={ ( nextContentSize ) => {
setContentSizeValue( nextContentSize );
} }
units={ units }
/>
<View>
<Icon icon={ positionCenter } />
</View>
</HStack>
<UnitControl
__next40pxDefaultSize
label={ __( 'Content width' ) }
labelPosition="top"
value={ contentSizeValue || '' }
onChange={ ( nextContentSize ) => {
setContentSizeValue( nextContentSize );
} }
units={ units }
prefix={
<InputControlPrefixWrapper variant="icon">
<Icon icon={ alignNone } />
</InputControlPrefixWrapper>
}
/>
</ToolsPanelItem>
) }
{ showWideSizeControl && (
<ToolsPanelItem
className="single-column"
label={ __( 'Wide size' ) }
label={ __( 'Wide width' ) }
hasValue={ hasUserSetWideSizeValue }
onDeselect={ resetWideSizeValue }
isShownByDefault={
defaultControls.wideSize ?? DEFAULT_CONTROLS.wideSize
}
panelId={ panelId }
>
<HStack alignment="flex-end" justify="flex-start">
<UnitControl
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
label={ __( 'Wide' ) }
labelPosition="top"
__unstableInputWidth="80px"
value={ wideSizeValue || '' }
onChange={ ( nextWideSize ) => {
setWideSizeValue( nextWideSize );
} }
units={ units }
/>
<View>
<Icon icon={ stretchWide } />
</View>
</HStack>
<UnitControl
__next40pxDefaultSize
label={ __( 'Wide width' ) }
labelPosition="top"
value={ wideSizeValue || '' }
onChange={ ( nextWideSize ) => {
setWideSizeValue( nextWideSize );
} }
units={ units }
prefix={
<InputControlPrefixWrapper variant="icon">
<Icon icon={ stretchWide } />
</InputControlPrefixWrapper>
}
/>
</ToolsPanelItem>
) }
{ showPaddingControl && (
Expand Down
14 changes: 3 additions & 11 deletions packages/block-editor/src/hooks/layout.scss
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
.block-editor-hooks__layout-controls {
.block-editor-hooks__layout-controls-units {
display: flex;
margin-bottom: $grid-unit-10;

.block-editor-hooks__layout-controls-unit {
display: flex;
margin-right: $grid-unit-30;

svg {
margin: auto 0 $grid-unit-05 $grid-unit-10;
}
}
flex-direction: column;
gap: $grid-unit-20;
}

.block-editor-block-inspector .block-editor-hooks__layout-controls-unit-input {
Expand Down
101 changes: 50 additions & 51 deletions packages/block-editor/src/layouts/constrained.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import {
__experimentalUnitControl as UnitControl,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
__experimentalInputControlPrefixWrapper as InputControlPrefixWrapper,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import {
Icon,
positionCenter,
alignNone,
stretchWide,
justifyLeft,
justifyCenter,
Expand Down Expand Up @@ -71,61 +72,59 @@ export default {
return (
<>
{ allowCustomContentAndWideSize && (
<>
<div className="block-editor-hooks__layout-controls">
<div className="block-editor-hooks__layout-controls-unit">
<UnitControl
// TODO: Switch to `true` (40px size) if possible (https://github.com/WordPress/gutenberg/pull/64520#discussion_r1717314262)
__next40pxDefaultSize={ false }
className="block-editor-hooks__layout-controls-unit-input"
label={ __( 'Content' ) }
labelPosition="top"
__unstableInputWidth="80px"
value={ contentSize || wideSize || '' }
onChange={ ( nextWidth ) => {
nextWidth =
0 > parseFloat( nextWidth )
? '0'
: nextWidth;
onChange( {
...layout,
contentSize: nextWidth,
} );
} }
units={ units }
/>
<Icon icon={ positionCenter } />
</div>
<div className="block-editor-hooks__layout-controls-unit">
<UnitControl
// TODO: Switch to `true` (40px size) if possible
__next40pxDefaultSize={ false }
className="block-editor-hooks__layout-controls-unit-input"
label={ __( 'Wide' ) }
labelPosition="top"
__unstableInputWidth="80px"
value={ wideSize || contentSize || '' }
onChange={ ( nextWidth ) => {
nextWidth =
0 > parseFloat( nextWidth )
? '0'
: nextWidth;
onChange( {
...layout,
wideSize: nextWidth,
} );
} }
units={ units }
/>
<Icon icon={ stretchWide } />
</div>
</div>
<div className="block-editor-hooks__layout-controls-units">
<UnitControl
__next40pxDefaultSize
className="block-editor-hooks__layout-controls-unit-input"
label={ __( 'Content width' ) }
labelPosition="top"
value={ contentSize || wideSize || '' }
onChange={ ( nextWidth ) => {
nextWidth =
0 > parseFloat( nextWidth )
? '0'
: nextWidth;
onChange( {
...layout,
contentSize: nextWidth,
} );
} }
units={ units }
prefix={
<InputControlPrefixWrapper variant="icon">
<Icon icon={ alignNone } />
</InputControlPrefixWrapper>
}
/>
<UnitControl
__next40pxDefaultSize
className="block-editor-hooks__layout-controls-unit-input"
label={ __( 'Wide width' ) }
labelPosition="top"
value={ wideSize || contentSize || '' }
onChange={ ( nextWidth ) => {
nextWidth =
0 > parseFloat( nextWidth )
? '0'
: nextWidth;
onChange( {
...layout,
wideSize: nextWidth,
} );
} }
units={ units }
prefix={
<InputControlPrefixWrapper variant="icon">
<Icon icon={ stretchWide } />
</InputControlPrefixWrapper>
}
/>
<p className="block-editor-hooks__layout-controls-helptext">
{ __(
'Customize the width for all elements that are assigned to the center or wide columns.'
) }
</p>
</>
</div>
) }
{ allowJustification && (
<ToggleGroupControl
Expand Down

0 comments on commit 6058323

Please sign in to comment.