From c91060a7f1b4a6843697d2fa4cfb8372a8e0be70 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Thu, 17 Nov 2022 15:44:57 +1100 Subject: [PATCH 1/5] LayoutPanel: Update to use ToolsPanel and ToolsPanelItems --- .../src/components/block-inspector/index.js | 8 + .../inspector-controls-tabs/appearance-tab.js | 4 + .../components/inspector-controls/groups.js | 2 + .../block-editor/src/hooks/content-layout.js | 70 ++++++++ packages/block-editor/src/hooks/layout.js | 160 +++++++++-------- packages/block-editor/src/hooks/layout.scss | 6 + .../block-editor/src/layouts/constrained.js | 167 +++++++++++------- packages/block-editor/src/layouts/flex.js | 89 ++++++++-- 8 files changed, 360 insertions(+), 146 deletions(-) create mode 100644 packages/block-editor/src/hooks/content-layout.js diff --git a/packages/block-editor/src/components/block-inspector/index.js b/packages/block-editor/src/components/block-inspector/index.js index c8ed85f2fd51bc..a8c498a03567bd 100644 --- a/packages/block-editor/src/components/block-inspector/index.js +++ b/packages/block-editor/src/components/block-inspector/index.js @@ -181,6 +181,10 @@ const BlockInspector = ( { showNoBlockSelectedMessage = true } ) => { ) : ( <> + ) } + ) } + { const { getSettings } = select( blockEditorStore ); @@ -138,7 +141,7 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) { const layoutBlockSupport = getBlockSupport( blockName, - layoutBlockSupportKey, + LAYOUT_SUPPORT_KEY, {} ); const { @@ -192,67 +195,87 @@ function LayoutPanel( { setAttributes, attributes, name: blockName } ) { const onChangeLayout = ( newLayout ) => setAttributes( { layout: newLayout } ); + const defaultControls = getBlockSupport( blockName, [ + LAYOUT_SUPPORT_KEY, + '__experimentalDefaultControls', + ] ); + return ( <> - - - { showInheritToggle && ( - <> - - setAttributes( { - layout: { - type: - layoutType?.name === - 'constrained' || - hasContentSizeOrLegacySettings - ? 'default' - : 'constrained', - }, - } ) - } - help={ - layoutType?.name === 'constrained' || - hasContentSizeOrLegacySettings - ? __( - 'Nested blocks use content width with options for full and wide widths.' - ) - : __( - 'Nested blocks will fill the width of this container. Toggle to constrain.' - ) - } - /> - - ) } - - { ! inherit && allowSwitching && ( - - ) } - - { layoutType && layoutType.name !== 'default' && ( - - ) } - { constrainedType && displayControlsForLegacyLayouts && ( - + { showInheritToggle && ( + hasContentLayoutValue( props ) } + onDeselect={ () => resetContentLayout( props ) } + isShownByDefault={ true } + resetAllFilter={ ( newAttributes ) => ( { + ...newAttributes, + layout: { + ...newAttributes.layout, + type: undefined, + }, + } ) } + panelId={ clientId } + > + + setAttributes( { + layout: { + type: + layoutType?.name === + 'constrained' || + hasContentSizeOrLegacySettings + ? 'default' + : 'constrained', + }, + } ) + } + help={ + layoutType?.name === 'constrained' || + hasContentSizeOrLegacySettings + ? __( + 'Nested blocks use content width with options for full and wide widths.' + ) + : __( + 'Nested blocks will fill the width of this container. Toggle to constrain.' + ) + } /> - ) } - + + ) } + + { ! inherit && allowSwitching && ( + + ) } + + { layoutType && layoutType.name !== 'default' && ( + + ) } + { constrainedType && displayControlsForLegacyLayouts && ( + + ) } { ! inherit && layoutType && ( ( props ) => { const { name: blockName } = props; - const supportLayout = hasBlockSupport( - blockName, - layoutBlockSupportKey - ); + const supportLayout = hasBlockSupport( blockName, LAYOUT_SUPPORT_KEY ); return [ supportLayout && , @@ -341,7 +361,7 @@ export const withLayoutStyles = createHigherOrderComponent( const { name, attributes, block } = props; const hasLayoutBlockSupport = hasBlockSupport( name, - layoutBlockSupportKey + LAYOUT_SUPPORT_KEY ); const disableLayoutStyles = useSelect( ( select ) => { const { getSettings } = select( blockEditorStore ); @@ -354,7 +374,7 @@ export const withLayoutStyles = createHigherOrderComponent( const element = useContext( BlockList.__unstableElementContext ); const { layout } = attributes; const { default: defaultBlockLayout } = - getBlockSupport( name, layoutBlockSupportKey ) || {}; + getBlockSupport( name, LAYOUT_SUPPORT_KEY ) || {}; const usedLayout = layout?.inherit || layout?.contentSize || layout?.wideSize ? { ...layout, type: 'constrained' } diff --git a/packages/block-editor/src/hooks/layout.scss b/packages/block-editor/src/hooks/layout.scss index 8ac39b1dec5f41..9491e6dbe86ddf 100644 --- a/packages/block-editor/src/hooks/layout.scss +++ b/packages/block-editor/src/hooks/layout.scss @@ -1,3 +1,9 @@ +.layout-block-support-panel { + .single-column { + grid-column: span 1; + } +} + .block-editor-hooks__layout-controls { display: flex; margin-bottom: $grid-unit-10; diff --git a/packages/block-editor/src/layouts/constrained.js b/packages/block-editor/src/layouts/constrained.js index 5e3b7eab405d89..6d3bf186b3c25a 100644 --- a/packages/block-editor/src/layouts/constrained.js +++ b/packages/block-editor/src/layouts/constrained.js @@ -6,6 +6,7 @@ import { __experimentalUnitControl as UnitControl, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, + __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { @@ -30,6 +31,8 @@ export default { name: 'constrained', label: __( 'Constrained' ), inspectorControls: function DefaultLayoutInspectorControls( { + clientId, + defaultControls = {}, layout, onChange, } ) { @@ -68,69 +71,113 @@ export default { } ); return ( <> -
-
- { - nextWidth = - 0 > parseFloat( nextWidth ) - ? '0' - : nextWidth; - onChange( { - ...layout, - contentSize: nextWidth, - } ); - } } - units={ units } - /> - -
-
- { - nextWidth = - 0 > parseFloat( nextWidth ) - ? '0' - : nextWidth; - onChange( { - ...layout, - wideSize: nextWidth, - } ); - } } - units={ units } - /> - -
-
-

- { __( - 'Customize the width for all elements that are assigned to the center or wide columns.' - ) } -

- + wideSize !== undefined || contentSize !== undefined + } + label={ __( 'Content size' ) } + onDeselect={ () => + onChange( { + ...layout, + contentSize: undefined, + wideSize: undefined, + } ) + } + isShownByDefault={ + defaultControls?.contentSize || + defaultControls?.wideSize + } + resetAllFilter={ ( newAttributes ) => ( { + ...newAttributes, + layout: { + ...newAttributes?.layout, + contentSize: undefined, + wideSize: undefined, + }, + } ) } + panelId={ clientId } > - { justificationOptions.map( ( { value, icon, label } ) => { - return ( - +
+ { + nextWidth = + 0 > parseFloat( nextWidth ) + ? '0' + : nextWidth; + onChange( { + ...layout, + contentSize: nextWidth, + } ); + } } + units={ units } + /> + +
+
+ { + nextWidth = + 0 > parseFloat( nextWidth ) + ? '0' + : nextWidth; + onChange( { + ...layout, + wideSize: nextWidth, + } ); + } } + units={ units } /> - ); + +
+ +

+ { __( + 'Customize the width for all elements that are assigned to the center or wide columns.' + ) } +

+ + justifyContent !== undefined } + label={ __( 'Justification' ) } + onDeselect={ () => onJustificationChange( undefined ) } + isShownByDefault={ defaultControls?.justifyContent } + resetAllFilter={ ( newAttributes ) => ( { + ...newAttributes, + layout: { + ...newAttributes?.layout, + justifyContent: undefined, + }, } ) } -
+ panelId={ clientId } + > + + { justificationOptions.map( + ( { value, icon, label } ) => { + return ( + + ); + } + ) } + + ); }, diff --git a/packages/block-editor/src/layouts/flex.js b/packages/block-editor/src/layouts/flex.js index 948eceb6624d60..61aaab97d4b756 100644 --- a/packages/block-editor/src/layouts/flex.js +++ b/packages/block-editor/src/layouts/flex.js @@ -13,10 +13,9 @@ import { import { Button, ToggleControl, - Flex, - FlexItem, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, + __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; /** @@ -58,6 +57,8 @@ export default { name: 'flex', label: __( 'Flex' ), inspectorControls: function FlexLayoutInspectorControls( { + clientId, + defaultControls, layout = {}, onChange, layoutBlockSupport = {}, @@ -65,23 +66,79 @@ export default { const { allowOrientation = true } = layoutBlockSupport; return ( <> - - - layout?.justifyContent } + label={ __( 'Justification' ) } + onDeselect={ () => + onChange( { + ...layout, + justifyContent: undefined, + } ) + } + isShownByDefault={ defaultControls?.justifyContent } + resetAllFilter={ ( newAttributes ) => ( { + ...newAttributes, + layout: { + ...newAttributes?.layout, + justifyContent: undefined, + }, + } ) } + panelId={ clientId } + > + + + { allowOrientation && ( + layout?.orientation } + label={ __( 'Orientation' ) } + onDeselect={ () => + onChange( { + ...layout, + orientation: undefined, + } ) + } + isShownByDefault={ defaultControls?.orientation } + resetAllFilter={ ( newAttributes ) => ( { + ...newAttributes, + layout: { + ...newAttributes?.layout, + orientation: undefined, + }, + } ) } + panelId={ clientId } + > + - - - { allowOrientation && ( - - ) } - - - + + ) } + layout?.flexWrap } + label={ __( 'Wrap' ) } + onDeselect={ () => + onChange( { + ...layout, + flexWrap: undefined, + } ) + } + isShownByDefault={ defaultControls?.flexWrap } + resetAllFilter={ ( newAttributes ) => ( { + ...newAttributes, + layout: { + ...newAttributes?.layout, + flexWrap: undefined, + }, + } ) } + panelId={ clientId } + > + + ); }, From f6a4e6ed258af3097467a62929e577176a923b25 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Mon, 21 Nov 2022 17:06:43 +1100 Subject: [PATCH 2/5] Wrap layout type switcher in ToolsPanel, fix styling of content and wide controls --- .../block-editor/src/hooks/content-layout.js | 10 ++ packages/block-editor/src/hooks/layout.js | 29 +++++- packages/block-editor/src/hooks/layout.scss | 2 +- .../block-editor/src/layouts/constrained.js | 95 ++++++++++--------- 4 files changed, 84 insertions(+), 52 deletions(-) diff --git a/packages/block-editor/src/hooks/content-layout.js b/packages/block-editor/src/hooks/content-layout.js index 209227a3fe77f5..987e7e5543c500 100644 --- a/packages/block-editor/src/hooks/content-layout.js +++ b/packages/block-editor/src/hooks/content-layout.js @@ -39,6 +39,16 @@ export function hasContentLayoutValue( props ) { ); } +/** + * Checks if there is a current layout type set. + * + * @param {Object} props Block props. + * @return {boolean} Whether or not the block has a minHeight value set. + */ +export function hasLayoutTypeValue( props ) { + return props.attributes.layout?.type !== undefined; +} + /** * Resets the content layout block support attributes. * diff --git a/packages/block-editor/src/hooks/layout.js b/packages/block-editor/src/hooks/layout.js index fab83c8d6079a8..154d64b3178418 100644 --- a/packages/block-editor/src/hooks/layout.js +++ b/packages/block-editor/src/hooks/layout.js @@ -29,7 +29,11 @@ import useSetting from '../components/use-setting'; import { LayoutStyle } from '../components/block-list/layout'; import BlockList from '../components/block-list'; import { getLayoutType, getLayoutTypes } from '../layouts'; -import { hasContentLayoutValue, resetContentLayout } from './content-layout'; +import { + hasContentLayoutValue, + hasLayoutTypeValue, + resetContentLayout, +} from './content-layout'; export const LAYOUT_SUPPORT_KEY = '__experimentalLayout'; @@ -252,10 +256,25 @@ function LayoutPanel( props ) { ) } { ! inherit && allowSwitching && ( - + hasLayoutTypeValue( props ) } + onDeselect={ () => resetContentLayout( props ) } + isShownByDefault={ true } + resetAllFilter={ ( newAttributes ) => ( { + ...newAttributes, + layout: { + ...newAttributes.layout, + type: undefined, + }, + } ) } + panelId={ clientId } + > + + ) } { layoutType && layoutType.name !== 'default' && ( diff --git a/packages/block-editor/src/hooks/layout.scss b/packages/block-editor/src/hooks/layout.scss index 9491e6dbe86ddf..2327c149eecaf9 100644 --- a/packages/block-editor/src/hooks/layout.scss +++ b/packages/block-editor/src/hooks/layout.scss @@ -27,7 +27,7 @@ .block-editor-hooks__layout-controls-helptext { color: $gray-700; font-size: $helptext-font-size; - margin-bottom: $grid-unit-20; + margin-bottom: 0; } .block-editor-hooks__flex-layout-justification-controls, diff --git a/packages/block-editor/src/layouts/constrained.js b/packages/block-editor/src/layouts/constrained.js index 6d3bf186b3c25a..888a54e109de4f 100644 --- a/packages/block-editor/src/layouts/constrained.js +++ b/packages/block-editor/src/layouts/constrained.js @@ -7,6 +7,7 @@ import { __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, __experimentalToolsPanelItem as ToolsPanelItem, + __experimentalVStack as VStack, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; import { @@ -97,53 +98,55 @@ export default { } ) } panelId={ clientId } > -
-
- { - nextWidth = - 0 > parseFloat( nextWidth ) - ? '0' - : nextWidth; - onChange( { - ...layout, - contentSize: nextWidth, - } ); - } } - units={ units } - /> - + +
+
+ { + nextWidth = + 0 > parseFloat( nextWidth ) + ? '0' + : nextWidth; + onChange( { + ...layout, + contentSize: nextWidth, + } ); + } } + units={ units } + /> + +
+
+ { + nextWidth = + 0 > parseFloat( nextWidth ) + ? '0' + : nextWidth; + onChange( { + ...layout, + wideSize: nextWidth, + } ); + } } + units={ units } + /> + +
-
- { - nextWidth = - 0 > parseFloat( nextWidth ) - ? '0' - : nextWidth; - onChange( { - ...layout, - wideSize: nextWidth, - } ); - } } - units={ units } - /> - -
-
-

- { __( - 'Customize the width for all elements that are assigned to the center or wide columns.' - ) } -

+

+ { __( + 'Customize the width for all elements that are assigned to the center or wide columns.' + ) } +

+ justifyContent !== undefined } From d357a87f6e0a198c1d6fd399e60c481292f4fc41 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Tue, 22 Nov 2022 15:47:28 +1100 Subject: [PATCH 3/5] Prevent constrained justification from showing by default --- packages/block-editor/src/layouts/constrained.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/layouts/constrained.js b/packages/block-editor/src/layouts/constrained.js index 888a54e109de4f..1ce345e3cb5b41 100644 --- a/packages/block-editor/src/layouts/constrained.js +++ b/packages/block-editor/src/layouts/constrained.js @@ -37,7 +37,7 @@ export default { layout, onChange, } ) { - const { wideSize, contentSize, justifyContent = 'center' } = layout; + const { wideSize, contentSize, justifyContent } = layout; const onJustificationChange = ( value ) => { onChange( { ...layout, @@ -164,7 +164,7 @@ export default { > { justificationOptions.map( From 5d23bbede44453296818dc0e2f5fe2aa58da93e1 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Tue, 22 Nov 2022 16:06:35 +1100 Subject: [PATCH 4/5] Display justification and orientation on separate lines --- packages/block-editor/src/hooks/layout.scss | 1 - packages/block-editor/src/layouts/flex.js | 2 -- 2 files changed, 3 deletions(-) diff --git a/packages/block-editor/src/hooks/layout.scss b/packages/block-editor/src/hooks/layout.scss index 2327c149eecaf9..a8db3d65acefd7 100644 --- a/packages/block-editor/src/hooks/layout.scss +++ b/packages/block-editor/src/hooks/layout.scss @@ -32,7 +32,6 @@ .block-editor-hooks__flex-layout-justification-controls, .block-editor-hooks__flex-layout-orientation-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 61aaab97d4b756..ac61dd7c64a92a 100644 --- a/packages/block-editor/src/layouts/flex.js +++ b/packages/block-editor/src/layouts/flex.js @@ -67,7 +67,6 @@ export default { return ( <> layout?.justifyContent } label={ __( 'Justification' ) } onDeselect={ () => @@ -93,7 +92,6 @@ export default { { allowOrientation && ( layout?.orientation } label={ __( 'Orientation' ) } onDeselect={ () => From 8abc84adf90d0c5863ac7947c3b9ac8dc2f8a955 Mon Sep 17 00:00:00 2001 From: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Date: Tue, 22 Nov 2022 17:36:59 +1100 Subject: [PATCH 5/5] Try moving content layout down to the layout type, combine with contentSize and wideSize --- .../block-editor/src/hooks/content-layout.js | 80 -------- packages/block-editor/src/hooks/layout.js | 94 +-------- packages/block-editor/src/hooks/layout.scss | 1 - .../block-editor/src/layouts/constrained.js | 188 +++++++++++------- packages/block-editor/src/layouts/flow.js | 70 ++++++- 5 files changed, 191 insertions(+), 242 deletions(-) delete mode 100644 packages/block-editor/src/hooks/content-layout.js diff --git a/packages/block-editor/src/hooks/content-layout.js b/packages/block-editor/src/hooks/content-layout.js deleted file mode 100644 index 987e7e5543c500..00000000000000 --- a/packages/block-editor/src/hooks/content-layout.js +++ /dev/null @@ -1,80 +0,0 @@ -/** - * WordPress dependencies - */ -import { getBlockSupport } from '@wordpress/blocks'; - -/** - * Internal dependencies - */ -import useSetting from '../components/use-setting'; -import { LAYOUT_SUPPORT_KEY } from './layout'; -import { cleanEmptyObject } from './utils'; - -/** - * Determines if there is content layout support. - * - * @param {string|Object} blockType Block name or Block Type object. - * @return {boolean} Whether there is support. - */ -export function hasContentLayoutSupport( blockType ) { - const support = getBlockSupport( blockType, LAYOUT_SUPPORT_KEY ); - return !! ( - true === support || - ! support?.default?.type || - support?.default?.type === 'default' || - support?.default?.type === 'constrained' - ); -} - -/** - * Checks if there is a current value set for content layout. - * - * @param {Object} props Block props. - * @return {boolean} Whether or not the block has a minHeight value set. - */ -export function hasContentLayoutValue( props ) { - return ( - props.attributes.layout?.type === 'default' || - props.attributes.layout?.type === 'constrained' - ); -} - -/** - * Checks if there is a current layout type set. - * - * @param {Object} props Block props. - * @return {boolean} Whether or not the block has a minHeight value set. - */ -export function hasLayoutTypeValue( props ) { - return props.attributes.layout?.type !== undefined; -} - -/** - * Resets the content layout block support attributes. - * - * @param {Object} props Block props. - * @param {Object} props.attributes Block's attributes. - * @param {Object} props.setAttributes Function to set block's attributes. - */ -export function resetContentLayout( { attributes = {}, setAttributes } ) { - const { layout } = attributes; - - setAttributes( { - layout: cleanEmptyObject( { - ...layout, - type: undefined, - } ), - } ); -} - -/** - * Custom hook that checks if content layout controls have been disabled. - * - * @param {string} name The name of the block. - * @return {boolean} Whether content layout control is disabled. - */ -export function useIsContentLayoutDisabled( { name: blockName } = {} ) { - // TODO: Is this check valid? The following assumes on by default unless explicitly opted out. - const isDisabled = useSetting( 'layout.contentLayout' ) === false; - return ! hasContentLayoutSupport( blockName ) || isDisabled; -} diff --git a/packages/block-editor/src/hooks/layout.js b/packages/block-editor/src/hooks/layout.js index 154d64b3178418..e63fc3724cadfc 100644 --- a/packages/block-editor/src/hooks/layout.js +++ b/packages/block-editor/src/hooks/layout.js @@ -14,7 +14,6 @@ import { useSelect } from '@wordpress/data'; import { Button, ButtonGroup, - ToggleControl, __experimentalToolsPanelItem as ToolsPanelItem, } from '@wordpress/components'; import { __ } from '@wordpress/i18n'; @@ -29,11 +28,6 @@ import useSetting from '../components/use-setting'; import { LayoutStyle } from '../components/block-list/layout'; import BlockList from '../components/block-list'; import { getLayoutType, getLayoutTypes } from '../layouts'; -import { - hasContentLayoutValue, - hasLayoutTypeValue, - resetContentLayout, -} from './content-layout'; export const LAYOUT_SUPPORT_KEY = '__experimentalLayout'; @@ -137,7 +131,6 @@ function LayoutPanel( props ) { const { clientId, setAttributes, attributes, name: blockName } = props; const { layout } = attributes; - const defaultThemeLayout = useSetting( 'layout' ); const themeSupportsLayout = useSelect( ( select ) => { const { getSettings } = select( blockEditorStore ); return getSettings().supportsLayout; @@ -151,7 +144,6 @@ function LayoutPanel( props ) { const { allowSwitching, allowEditing = true, - allowInheriting = true, default: defaultBlockLayout, } = layoutBlockSupport; @@ -159,18 +151,6 @@ function LayoutPanel( props ) { return null; } - // Only show the inherit toggle if it's supported, - // a default theme layout is set (e.g. one that provides `contentSize` and/or `wideSize` values), - // and either the default / flow or the constrained layout type is in use, as the toggle switches from one to the other. - const showInheritToggle = !! ( - allowInheriting && - !! defaultThemeLayout && - ( ! layout?.type || - layout?.type === 'default' || - layout?.type === 'constrained' || - layout?.inherit ) - ); - const usedLayout = layout || defaultBlockLayout || {}; const { inherit = false, @@ -188,11 +168,12 @@ function LayoutPanel( props ) { ) { return null; } - const layoutType = getLayoutType( type ); - const constrainedType = getLayoutType( 'constrained' ); + const displayControlsForLegacyLayouts = ! usedLayout.type && ( contentSize || inherit ); - const hasContentSizeOrLegacySettings = !! inherit || !! contentSize; + const layoutType = getLayoutType( + displayControlsForLegacyLayouts ? 'constrained' : type + ); const onChangeType = ( newType ) => setAttributes( { layout: { type: newType } } ); @@ -207,59 +188,13 @@ function LayoutPanel( props ) { return ( <> - { showInheritToggle && ( - hasContentLayoutValue( props ) } - onDeselect={ () => resetContentLayout( props ) } - isShownByDefault={ true } - resetAllFilter={ ( newAttributes ) => ( { - ...newAttributes, - layout: { - ...newAttributes.layout, - type: undefined, - }, - } ) } - panelId={ clientId } - > - - setAttributes( { - layout: { - type: - layoutType?.name === - 'constrained' || - hasContentSizeOrLegacySettings - ? 'default' - : 'constrained', - }, - } ) - } - help={ - layoutType?.name === 'constrained' || - hasContentSizeOrLegacySettings - ? __( - 'Nested blocks use content width with options for full and wide widths.' - ) - : __( - 'Nested blocks will fill the width of this container. Toggle to constrain.' - ) - } - /> - - ) } - { ! inherit && allowSwitching && ( hasLayoutTypeValue( props ) } - onDeselect={ () => resetContentLayout( props ) } + hasValue={ () => layout?.type !== undefined } + onDeselect={ () => + onChangeLayout( { ...layout, type: undefined } ) + } isShownByDefault={ true } resetAllFilter={ ( newAttributes ) => ( { ...newAttributes, @@ -277,7 +212,7 @@ function LayoutPanel( props ) { ) } - { layoutType && layoutType.name !== 'default' && ( + { layoutType && ( ) } - { constrainedType && displayControlsForLegacyLayouts && ( - - ) } - { ! inherit && layoutType && ( + { layoutType && ( { onChange( { @@ -70,84 +87,105 @@ export default { 'vw', ], } ); + return ( <> - - wideSize !== undefined || contentSize !== undefined - } - label={ __( 'Content size' ) } - onDeselect={ () => - onChange( { - ...layout, - contentSize: undefined, - wideSize: undefined, - } ) - } - isShownByDefault={ - defaultControls?.contentSize || - defaultControls?.wideSize - } - resetAllFilter={ ( newAttributes ) => ( { - ...newAttributes, - layout: { - ...newAttributes?.layout, - contentSize: undefined, - wideSize: undefined, - }, - } ) } - panelId={ clientId } - > - -
-
- { - nextWidth = - 0 > parseFloat( nextWidth ) - ? '0' - : nextWidth; - onChange( { - ...layout, - contentSize: nextWidth, - } ); - } } - units={ units } - /> - -
-
- { - nextWidth = - 0 > parseFloat( nextWidth ) - ? '0' - : nextWidth; - onChange( { - ...layout, - wideSize: nextWidth, - } ); - } } - units={ units } - /> - + { showInheritToggle && ( + + !! layout?.type || + wideSize !== undefined || + contentSize !== undefined + } + onDeselect={ () => + onChange( { + ...layout, + type: undefined, + contentSize: undefined, + wideSize: undefined, + } ) + } + isShownByDefault={ + ( defaultControls?.contentLayout ?? true ) || + defaultControls?.contentSize || + defaultControls?.wideSize + } + resetAllFilter={ ( newAttributes ) => ( { + ...newAttributes, + layout: { + ...newAttributes.layout, + type: undefined, + contentSize: undefined, + wideSize: undefined, + }, + } ) } + panelId={ clientId } + > + + + onChange( { + type: 'default', + } ) + } + help={ __( + 'Nested blocks use content width with options for full and wide widths.' + ) } + /> +
+
+ { + nextWidth = + 0 > parseFloat( nextWidth ) + ? '0' + : nextWidth; + onChange( { + ...layout, + contentSize: nextWidth, + } ); + } } + units={ units } + /> + +
+
+ { + nextWidth = + 0 > parseFloat( nextWidth ) + ? '0' + : nextWidth; + onChange( { + ...layout, + wideSize: nextWidth, + } ); + } } + units={ units } + /> + +
-
-

- { __( - 'Customize the width for all elements that are assigned to the center or wide columns.' - ) } -

- - +

+ { __( + 'Customize the width for all elements that are assigned to the center or wide columns.' + ) } +

+ + + ) } justifyContent !== undefined } label={ __( 'Justification' ) } diff --git a/packages/block-editor/src/layouts/flow.js b/packages/block-editor/src/layouts/flow.js index ecc6779b9128dd..24ee501a06f971 100644 --- a/packages/block-editor/src/layouts/flow.js +++ b/packages/block-editor/src/layouts/flow.js @@ -2,6 +2,10 @@ * WordPress dependencies */ import { __ } from '@wordpress/i18n'; +import { + ToggleControl, + __experimentalToolsPanelItem as ToolsPanelItem, +} from '@wordpress/components'; /** * Internal dependencies @@ -9,12 +13,74 @@ import { __ } from '@wordpress/i18n'; import { getBlockGapCSS, getAlignmentsInfo } from './utils'; import { getGapCSSValue } from '../hooks/gap'; import { shouldSkipSerialization } from '../hooks/utils'; +import useSetting from '../components/use-setting'; export default { name: 'default', label: __( 'Flow' ), - inspectorControls: function DefaultLayoutInspectorControls() { - return null; + inspectorControls: function DefaultLayoutInspectorControls( { + clientId, + defaultControls = {}, + layout, + layoutBlockSupport, + onChange, + } ) { + const defaultThemeLayout = useSetting( 'layout' ); + const { allowInheriting = true } = layoutBlockSupport; + + // Only show the inherit toggle if it's supported, + // a default theme layout is set (e.g. one that provides `contentSize` and/or `wideSize` values), + // and either the default / flow or the constrained layout type is in use, as the toggle switches from one to the other. + const showInheritToggle = !! ( + allowInheriting && + !! defaultThemeLayout && + ( ! layout?.type || + layout?.type === 'default' || + layout?.type === 'constrained' || + layout?.inherit ) + ); + + return ( + <> + { showInheritToggle && ( + !! layout?.type } + onDeselect={ () => + onChange( { + ...layout, + type: undefined, + } ) + } + isShownByDefault={ + defaultControls?.contentLayout ?? true + } + resetAllFilter={ ( newAttributes ) => ( { + ...newAttributes, + layout: { + ...newAttributes.layout, + type: undefined, + }, + } ) } + panelId={ clientId } + > + + onChange( { + type: 'constrained', + } ) + } + help={ __( + 'Nested blocks will fill the width of this container. Toggle to constrain.' + ) } + /> + + ) } + + ); }, toolBarControls: function DefaultLayoutToolbarControls() { return null;