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

Fix/flex controls bugs #47533

Merged
merged 4 commits into from
Jan 30, 2023
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 @@ -7,6 +7,7 @@ import {
justifyCenter,
justifyRight,
justifySpaceBetween,
justifyStretch,
} from '@wordpress/icons';
import { __ } from '@wordpress/i18n';

Expand All @@ -15,6 +16,7 @@ const icons = {
center: justifyCenter,
right: justifyRight,
'space-between': justifySpaceBetween,
stretch: justifyStretch,
};

function JustifyContentUI( {
Expand Down Expand Up @@ -66,6 +68,13 @@ function JustifyContentUI( {
isActive: 'space-between' === value,
onClick: () => handleClick( 'space-between' ),
},
{
name: 'stretch',
icon: justifyStretch,
title: __( 'Stretch items' ),
isActive: 'stretch' === value,
onClick: () => handleClick( 'stretch' ),
},
];

const UIComponent = isToolbar ? ToolbarGroup : ToolbarDropdownMenu;
Expand Down
35 changes: 29 additions & 6 deletions packages/block-editor/src/layouts/flex.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ function FlexLayoutJustifyContentControl( {
label: __( 'Space between items' ),
} );
} else {
// Todo: we also need an icon here.
justificationOptions.push( {
value: 'stretch',
icon: justifyStretch,
Expand Down Expand Up @@ -360,18 +359,42 @@ function FlexWrapControl( { layout, onChange } ) {
}

function OrientationControl( { layout, onChange } ) {
const { orientation = 'horizontal' } = layout;
const {
orientation = 'horizontal',
verticalAlignment,
justifyContent,
} = layout;
return (
<ToggleGroupControl
className="block-editor-hooks__flex-layout-orientation-controls"
label={ __( 'Orientation' ) }
value={ orientation }
onChange={ ( value ) =>
onChange( {
onChange={ ( value ) => {
// Make sure the vertical alignment and justification are compatible with the new orientation.
let newVerticalAlignment = verticalAlignment;
let newJustification = justifyContent;
if ( value === 'horizontal' ) {
if ( verticalAlignment === 'space-between' ) {
newVerticalAlignment = 'center';
}
if ( justifyContent === 'stretch' ) {
newJustification = 'left';
}
} else {
if ( verticalAlignment === 'stretch' ) {
newVerticalAlignment = 'top';
}
if ( justifyContent === 'space-between' ) {
newJustification = 'left';
}
}
return onChange( {
...layout,
orientation: value,
} )
}
verticalAlignment: newVerticalAlignment,
justifyContent: newJustification,
} );
} }
>
<ToggleGroupControlOptionIcon
icon={ arrowRight }
Expand Down