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

Layout content and wide width controls: remove confusing icon and clarify labels #64891

Merged
merged 6 commits into from
Sep 3, 2024
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
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
Loading