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

Initial prototype of simplified layout panel #49459

Closed
wants to merge 13 commits into from
2 changes: 1 addition & 1 deletion docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ Gather blocks in a layout container. ([Source](https://github.com/WordPress/gute

- **Name:** core/group
- **Category:** design
- **Supports:** align (full, wide), anchor, ariaLabel, color (background, gradients, heading, link, text), dimensions (minHeight), layout (allowSizingOnChildren), position (sticky), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align (full, wide), anchor, ariaLabel, color (background, gradients, heading, link, text), dimensions (minHeight), layout (allowSizingOnChildren, allowSwitching), position (sticky), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** allowedBlocks, tagName, templateLock

## Heading
Expand Down
6 changes: 6 additions & 0 deletions packages/block-editor/src/components/block-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,23 @@ export default function BlockEdit( props ) {
isSelected,
clientId,
attributes = {},
setAttributes,
__unstableLayoutClassNames,
} = props;

const { layout = null } = attributes;
const layoutSupport =
hasBlockSupport( name, 'layout', false ) ||
hasBlockSupport( name, '__experimentalLayout', false );
const updateLayoutType = ( newLayout ) => {
setAttributes( { layout: { ...layout, type: newLayout } } );
};
const context = {
name,
isSelected,
clientId,
layout: layoutSupport ? layout : null,
updateLayoutType,
__unstableLayoutClassNames,
};
return (
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ function BlockListBlock( {
onInsertBlocksAfter,
onMerge,
toggleSelection,
updateLayoutType,
} ) {
const {
themeSupportsLayout,
Expand Down Expand Up @@ -138,6 +139,7 @@ function BlockListBlock( {
__unstableParentLayout={
Object.keys( parentLayout ).length ? parentLayout : undefined
}
updateParentLayoutType={ updateLayoutType }
/>
);

Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ function Items( {
renderAppender,
__experimentalAppenderTagName,
layout = defaultLayout,
updateLayoutType,
} ) {
const { order, selectedBlocks, visibleBlocks } = useSelect(
( select ) => {
Expand Down Expand Up @@ -172,6 +173,7 @@ function Items( {
<BlockListBlock
rootClientId={ rootClientId }
clientId={ clientId }
updateLayoutType={ updateLayoutType }
/>
</AsyncModeProvider>
) ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,18 @@ function helpText( selfStretch, parentLayout ) {
/**
* Form to edit the child layout value.
*
* @param {Object} props Props.
* @param {Object} props.value The child layout value.
* @param {Function} props.onChange Function to update the child layout value.
* @param {Object} props.parentLayout The parent layout value.
*
* @param {Object} props Props.
* @param {Object} props.value The child layout value.
* @param {Function} props.onChange Function to update the child layout value.
* @param {Object} props.parentLayout The parent layout value.
* @param {Function} props.updateParentLayoutType Function to update the parent layout type.
* @return {WPElement} child layout edit element.
*/
export default function ChildLayoutControl( {
value: childLayout = {},
onChange,
parentLayout,
updateParentLayoutType,
} ) {
const { selfStretch, flexSize } = childLayout;

Expand All @@ -59,6 +60,9 @@ export default function ChildLayoutControl( {
help={ helpText( selfStretch, parentLayout ) }
onChange={ ( value ) => {
const newFlexSize = value !== 'fixed' ? null : flexSize;
if ( value === 'fill' ) {
updateParentLayoutType( 'flex' );
}
onChange( {
...childLayout,
selfStretch: value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function useHasChildLayout( settings ) {
} = settings?.parentLayout ?? {};

const support =
( defaultParentLayoutType === 'flex' || parentLayoutType === 'flex' ) &&
( defaultParentLayoutType || parentLayoutType ) &&
allowSizingOnChildren;

return !! settings?.layout && support;
Expand Down Expand Up @@ -206,6 +206,7 @@ export default function DimensionsPanel( {
// Special case because the layout controls are not part of the dimensions panel
// in global styles but not in block inspector.
includeLayoutControls = false,
updateParentLayoutType,
} ) {
const { dimensions, spacing } = settings;

Expand Down Expand Up @@ -633,6 +634,7 @@ export default function DimensionsPanel( {
value={ childLayout }
onChange={ setChildLayout }
parentLayout={ settings?.parentLayout }
updateParentLayoutType={ updateParentLayoutType }
/>
</VStack>
) }
Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function UncontrolledInnerBlocks( props ) {
orientation,
placeholder,
layout,
updateLayoutType,
} = props;

useNestedSettingsUpdate(
Expand Down Expand Up @@ -125,6 +126,7 @@ function UncontrolledInnerBlocks( props ) {
layout={ memoedLayout }
wrapperRef={ wrapperRef }
placeholder={ placeholder }
updateLayoutType={ updateLayoutType }
/>
</BlockContextProvider>
);
Expand Down Expand Up @@ -175,6 +177,7 @@ export function useInnerBlocksProps( props = {}, options = {} ) {
clientId,
layout = null,
__unstableLayoutClassNames: layoutClassNames = '',
updateLayoutType,
} = useBlockEditContext();
const isSmallScreen = useViewportMatch( 'medium', '<' );
const { __experimentalCaptureToolbars, hasOverlay } = useSelect(
Expand Down Expand Up @@ -222,6 +225,7 @@ export function useInnerBlocksProps( props = {}, options = {} ) {
const innerBlocksProps = {
__experimentalCaptureToolbars,
layout,
updateLayoutType,
...options,
};
const InnerBlocks =
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/hooks/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export function DimensionsPanel( props ) {
attributes,
setAttributes,
__unstableParentLayout,
updateParentLayoutType,
} = props;
const settings = useBlockSettings( name, __unstableParentLayout );
const isEnabled = useHasDimensionsPanel( settings );
Expand Down Expand Up @@ -110,6 +111,7 @@ export function DimensionsPanel( props ) {
onChange={ onChange }
defaultControls={ defaultControls }
onVisualize={ setVisualizedProperty }
updateParentLayoutType={ updateParentLayoutType }
/>
{ !! settings?.spacing?.padding && (
<PaddingVisualizer
Expand Down
Loading
Loading