From 051cd5485ea7f1ad4aae4cec690c9060430a9071 Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Fri, 5 Nov 2021 22:31:47 +1100 Subject: [PATCH] Try using flex layout on the Navigation block (#36169) * Try using flex layout on the Navigation block * Fix justification for overlay menu * Add deprecation and update fixtures * Fix menu position in site editor. * Don't use editor variables in front end styles. * Move overlay styles back to inner container. --- lib/block-supports/layout.php | 3 + packages/block-editor/src/layouts/flex.js | 4 + .../block-library/src/navigation/block.json | 14 +- .../src/navigation/deprecated.js | 132 ++++++++++++++- .../src/navigation/edit/index.js | 20 --- .../block-library/src/navigation/index.js | 2 - .../block-library/src/navigation/index.php | 2 - .../block-library/src/navigation/style.scss | 160 +++--------------- .../src/navigation/variations.js | 23 --- .../block-library/src/page-list/style.scss | 24 +-- .../fixtures/blocks/core__navigation.json | 1 - .../core__navigation__deprecated-1.json | 8 +- ...__navigation__deprecated-1.serialized.html | 2 +- .../core__navigation__deprecated-v4.json | 8 +- ..._navigation__deprecated-v4.serialized.html | 2 +- .../core__navigation__deprecated-v5.html | 1 + .../core__navigation__deprecated-v5.json | 19 +++ ...ore__navigation__deprecated-v5.parsed.json | 12 ++ ..._navigation__deprecated-v5.serialized.html | 1 + .../blocks/core__navigation__deprecated.json | 6 +- ...re__navigation__deprecated.serialized.html | 2 +- 21 files changed, 224 insertions(+), 222 deletions(-) delete mode 100644 packages/block-library/src/navigation/variations.js create mode 100644 test/integration/fixtures/blocks/core__navigation__deprecated-v5.html create mode 100644 test/integration/fixtures/blocks/core__navigation__deprecated-v5.json create mode 100644 test/integration/fixtures/blocks/core__navigation__deprecated-v5.parsed.json create mode 100644 test/integration/fixtures/blocks/core__navigation__deprecated-v5.serialized.html diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 841252da965229..3ba5aca6a35c6d 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -103,11 +103,14 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support */ if ( ! empty( $layout['justifyContent'] ) && array_key_exists( $layout['justifyContent'], $justify_content_options ) ) { $style .= "justify-content: {$justify_content_options[ $layout['justifyContent'] ]};"; + // --justification-setting allows children to inherit the value regardless or row or column direction. + $style .= "--justification-setting: {$justify_content_options[ $layout['justifyContent'] ]};"; } } else { $style .= 'flex-direction: column;'; if ( ! empty( $layout['justifyContent'] ) && array_key_exists( $layout['justifyContent'], $justify_content_options ) ) { $style .= "align-items: {$justify_content_options[ $layout['justifyContent'] ]};"; + $style .= "--justification-setting: {$justify_content_options[ $layout['justifyContent'] ]};"; } } $style .= '}'; diff --git a/packages/block-editor/src/layouts/flex.js b/packages/block-editor/src/layouts/flex.js index 9e687f6b7d7904..c929a67440b7a2 100644 --- a/packages/block-editor/src/layouts/flex.js +++ b/packages/block-editor/src/layouts/flex.js @@ -94,16 +94,20 @@ export default { const flexWrap = flexWrapOptions.includes( layout.flexWrap ) ? layout.flexWrap : 'wrap'; + // --justification-setting allows children to inherit the value + // regardless or row or column direction. const rowOrientation = ` flex-direction: row; align-items: center; justify-content: ${ justifyContent }; + --justification-setting: ${ justifyContent }; `; const alignItems = alignItemsMap[ layout.justifyContent ] || alignItemsMap.left; const columnOrientation = ` flex-direction: column; align-items: ${ alignItems }; + --justification-setting: ${ alignItems }; `; return (