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

Update justification control in flex layout #34651

Merged
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
6 changes: 6 additions & 0 deletions packages/block-editor/src/hooks/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@
.block-editor-hooks__layout-controls-helptext {
font-size: $helptext-font-size;
}

.block-editor-hooks__flex-layout-justification-controls {
legend {
margin-bottom: $grid-unit-10;
}
}
91 changes: 53 additions & 38 deletions packages/block-editor/src/layouts/flex.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/**
* WordPress dependencies
*/
import { __, _x } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import {
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
} from '@wordpress/components';
justifyLeft,
justifyCenter,
justifyRight,
justifySpaceBetween,
} from '@wordpress/icons';
import { Button } from '@wordpress/components';

/**
* Internal dependencies
Expand Down Expand Up @@ -87,12 +90,40 @@ export default {
},
};

const justificationOptions = [
{
value: 'left',
icon: justifyLeft,
label: __( 'Justify items left' ),
},
{
value: 'center',
icon: justifyCenter,
label: __( 'Justify items center' ),
},
{
value: 'right',
icon: justifyRight,
label: __( 'Justify items right' ),
},
{
value: 'space-between',
icon: justifySpaceBetween,
label: __( 'Space between items' ),
},
];
function FlexLayoutJustifyContentControl( {
layout,
onChange,
isToolbar = false,
} ) {
const { justifyContent = 'left' } = layout;
const onJustificationChange = ( value ) => {
onChange( {
...layout,
justifyContent: value,
} );
};
if ( isToolbar ) {
return (
<JustifyContentControl
Expand All @@ -103,47 +134,31 @@ function FlexLayoutJustifyContentControl( {
'space-between',
] }
value={ justifyContent }
onChange={ ( value ) => {
onChange( {
...layout,
justifyContent: value,
} );
} }
onChange={ onJustificationChange }
popoverProps={ {
position: 'bottom right',
isAlternate: true,
} }
/>
);
}

return (
<ToggleGroupControl
label={ __( 'Justify content' ) }
value={ justifyContent }
onChange={ ( value ) => {
onChange( {
...layout,
justifyContent: value,
} );
} }
isBlock
>
<ToggleGroupControlOption
value="left"
label={ _x( 'Left', 'Justify content option' ) }
/>
<ToggleGroupControlOption
value="center"
label={ _x( 'Center', 'Justify content option' ) }
/>
<ToggleGroupControlOption
value="right"
label={ _x( 'Right', 'Justify content option' ) }
/>
<ToggleGroupControlOption
value="space-between"
label={ _x( 'Space between', 'Justify content option' ) }
/>
</ToggleGroupControl>
<fieldset className="block-editor-hooks__flex-layout-justification-controls">
<legend>{ __( 'Justification' ) }</legend>
<div>
{ justificationOptions.map( ( { value, icon, label } ) => {
return (
<Button
key={ value }
label={ label }
icon={ icon }
isPressed={ justifyContent === value }
onClick={ () => onJustificationChange( value ) }
/>
);
} ) }
</div>
</fieldset>
);
}