From f58c4f873670d5b37cee35540865cf54bd78be43 Mon Sep 17 00:00:00 2001 From: Nik Tsekouras Date: Mon, 1 Nov 2021 17:49:06 +0200 Subject: [PATCH] [Block Editor]: Add `flex-wrap` control to `flex` layout (#36003) * [Block Editor]: Add `flex-wrap` control to `flex` layout * change to ToggleControl --- lib/block-supports/layout.php | 7 +++- packages/block-editor/src/hooks/layout.scss | 1 + packages/block-editor/src/layouts/flex.js | 39 +++++++++++++++++---- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 1af4a7f842c4d0..2ea8871df102e4 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -76,6 +76,11 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support 'space-between' => 'space-between', ); + $flex_wrap_options = array( 'wrap', 'nowrap' ); + $flex_wrap = ! empty( $layout['flexWrap'] ) && in_array( $layout['flexWrap'], $flex_wrap_options, true ) ? + $layout['flexWrap'] : + 'wrap'; + $style = "$selector {"; $style .= 'display: flex;'; if ( $has_block_gap_support ) { @@ -83,7 +88,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support } else { $style .= 'gap: 0.5em;'; } - $style .= 'flex-wrap: wrap;'; + $style .= "flex-wrap: $flex_wrap;"; $style .= 'align-items: center;'; /** * Add this style only if is not empty for backwards compatibility, diff --git a/packages/block-editor/src/hooks/layout.scss b/packages/block-editor/src/hooks/layout.scss index 9d154045c5a282..653f9da7b9bda5 100644 --- a/packages/block-editor/src/hooks/layout.scss +++ b/packages/block-editor/src/hooks/layout.scss @@ -23,6 +23,7 @@ } .block-editor-hooks__flex-layout-justification-controls { + margin-bottom: $grid-unit-15; legend { margin-bottom: $grid-unit-10; } diff --git a/packages/block-editor/src/layouts/flex.js b/packages/block-editor/src/layouts/flex.js index fd8e446aa2ae00..03ed93d31a266e 100644 --- a/packages/block-editor/src/layouts/flex.js +++ b/packages/block-editor/src/layouts/flex.js @@ -8,7 +8,7 @@ import { justifyRight, justifySpaceBetween, } from '@wordpress/icons'; -import { Button } from '@wordpress/components'; +import { Button, ToggleControl } from '@wordpress/components'; /** * Internal dependencies @@ -24,6 +24,8 @@ const justifyContentMap = { 'space-between': 'space-between', }; +const flexWrapOptions = [ 'wrap', 'nowrap' ]; + export default { name: 'flex', label: __( 'Flex' ), @@ -32,10 +34,13 @@ export default { onChange, } ) { return ( - + <> + + + ); }, toolBarControls: function FlexLayoutToolbarControls( { @@ -60,7 +65,11 @@ export default { const blockGapSupport = useSetting( 'spacing.blockGap' ); const hasBlockGapStylesSupport = blockGapSupport !== null; const justifyContent = - justifyContentMap[ layout.justifyContent ] || 'flex-start'; + justifyContentMap[ layout.justifyContent ] || + justifyContentMap.left; + const flexWrap = flexWrapOptions.includes( layout.flexWrap ) + ? layout.flexWrap + : 'wrap'; return (