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: replace Justification/Orientation controls with ToggleGroupControl #45637

Merged
merged 1 commit into from
Nov 9, 2022
Merged
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
81 changes: 43 additions & 38 deletions packages/block-editor/src/layouts/flex.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import {
arrowRight,
arrowDown,
} from '@wordpress/icons';
import { Button, ToggleControl, Flex, FlexItem } from '@wordpress/components';
import {
Button,
ToggleControl,
Flex,
FlexItem,
__experimentalToggleGroupControl as ToggleGroupControl,
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon,
} from '@wordpress/components';

/**
* Internal dependencies
Expand Down Expand Up @@ -289,22 +296,23 @@ function FlexLayoutJustifyContentControl( {
}

return (
<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>
<ToggleGroupControl
label={ __( 'Justification' ) }
value={ justifyContent }
onChange={ onJustificationChange }
className="block-editor-hooks__flex-layout-justification-controls"
>
{ justificationOptions.map( ( { value, icon, label } ) => {
return (
<ToggleGroupControlOptionIcon
key={ value }
value={ value }
icon={ icon }
label={ label }
/>
);
} ) }
</ToggleGroupControl>
);
}

Expand All @@ -327,30 +335,27 @@ function FlexWrapControl( { layout, onChange } ) {
function OrientationControl( { layout, onChange } ) {
const { orientation = 'horizontal' } = layout;
return (
<fieldset className="block-editor-hooks__flex-layout-orientation-controls">
<legend>{ __( 'Orientation' ) }</legend>
<Button
label={ __( 'Horizontal' ) }
<ToggleGroupControl
className="block-editor-hooks__flex-layout-orientation-controls"
label={ __( 'Orientation' ) }
value={ orientation }
onChange={ ( value ) =>
onChange( {
...layout,
orientation: value,
} )
}
>
<ToggleGroupControlOptionIcon
icon={ arrowRight }
isPressed={ orientation === 'horizontal' }
onClick={ () =>
onChange( {
...layout,
orientation: 'horizontal',
} )
}
value={ 'horizontal' }
label={ __( 'Horizontal' ) }
/>
<Button
label={ __( 'Vertical' ) }
<ToggleGroupControlOptionIcon
icon={ arrowDown }
isPressed={ orientation === 'vertical' }
onClick={ () =>
onChange( {
...layout,
orientation: 'vertical',
} )
}
value={ 'vertical' }
label={ __( 'Vertical' ) }
/>
</fieldset>
</ToggleGroupControl>
);
}