diff --git a/packages/block-editor/src/components/block-pattern-setup/index.js b/packages/block-editor/src/components/block-pattern-setup/index.js index 2fa25326a5c9c9..ea20723dea3b0c 100644 --- a/packages/block-editor/src/components/block-pattern-setup/index.js +++ b/packages/block-editor/src/components/block-pattern-setup/index.js @@ -11,7 +11,7 @@ import { } from '@wordpress/components'; import { useState } from '@wordpress/element'; -import { useInstanceId } from '@wordpress/compose'; +import { useInstanceId, useResizeObserver } from '@wordpress/compose'; import { __ } from '@wordpress/i18n'; /** @@ -28,6 +28,7 @@ const SetupContent = ( { activeSlide, patterns, onBlockPatternSelect, + height, } ) => { const composite = useCompositeState(); const containerClass = 'block-editor-block-pattern-setup__container'; @@ -38,41 +39,52 @@ const SetupContent = ( { [ activeSlide + 1, 'next-slide' ], ] ); return ( -
- +
+
+
    + { patterns.map( ( pattern, index ) => ( + + ) ) } +
+
); } return ( - - { patterns.map( ( pattern ) => ( - - ) ) } - + + { patterns.map( ( pattern ) => ( + + ) ) } + +
); }; function BlockPattern( { pattern, onSelect, composite } ) { const baseClassName = 'block-editor-block-pattern-setup-list'; - const { blocks, title, description, viewportWidth = 700 } = pattern; + const { blocks, description, viewportWidth = 700 } = pattern; const descriptionId = useInstanceId( BlockPattern, `${ baseClassName }__item-description` @@ -94,9 +106,6 @@ function BlockPattern( { pattern, onSelect, composite } ) { blocks={ blocks } viewportWidth={ viewportWidth } /> -
- { title } -
{ !! description && ( @@ -107,7 +116,7 @@ function BlockPattern( { pattern, onSelect, composite } ) { ); } -function BlockPatternSlide( { className, pattern } ) { +function BlockPatternSlide( { className, pattern, minHeight } ) { const { blocks, title, description } = pattern; const descriptionId = useInstanceId( BlockPatternSlide, @@ -119,7 +128,10 @@ function BlockPatternSlide( { className, pattern } ) { aria-label={ title } aria-describedby={ description ? descriptionId : undefined } > - + { !! description && ( { description } @@ -141,6 +153,10 @@ const BlockPatternSetup = ( { const [ showBlank, setShowBlank ] = useState( false ); const { replaceBlock } = useDispatch( blockEditorStore ); const patterns = usePatternsSetup( clientId, blockName, filterPatternsFn ); + const [ + contentResizeListener, + { height: contentHeight }, + ] = useResizeObserver(); if ( ! patterns?.length || showBlank ) { return startBlankComponent; @@ -152,35 +168,44 @@ const BlockPatternSetup = ( { }; const onPatternSelectCallback = onBlockPatternSelect || onBlockPatternSelectDefault; + const onStartBlank = startBlankComponent + ? () => { + setShowBlank( true ); + } + : undefined; return ( -
- { - setActiveSlide( ( active ) => active + 1 ); - } } - handlePrevious={ () => { - setActiveSlide( ( active ) => active - 1 ); - } } - onBlockPatternSelect={ () => { - onPatternSelectCallback( patterns[ activeSlide ].blocks ); - } } - onStartBlank={ () => { - setShowBlank( true ); - } } - /> - -
+ <> + { contentResizeListener } +
+ + { + setActiveSlide( ( active ) => active + 1 ); + } } + handlePrevious={ () => { + setActiveSlide( ( active ) => active - 1 ); + } } + onBlockPatternSelect={ () => { + onPatternSelectCallback( + patterns[ activeSlide ].blocks + ); + } } + onStartBlank={ onStartBlank } + /> +
+ ); }; diff --git a/packages/block-editor/src/components/block-pattern-setup/setup-toolbar.js b/packages/block-editor/src/components/block-pattern-setup/setup-toolbar.js index 44157626ca9725..5cba76bf99ee36 100644 --- a/packages/block-editor/src/components/block-pattern-setup/setup-toolbar.js +++ b/packages/block-editor/src/components/block-pattern-setup/setup-toolbar.js @@ -17,7 +17,9 @@ import { VIEWMODES } from './constants'; const Actions = ( { onStartBlank, onBlockPatternSelect } ) => (
- + { onStartBlank && ( + + ) } diff --git a/packages/block-editor/src/components/block-pattern-setup/style.scss b/packages/block-editor/src/components/block-pattern-setup/style.scss index 17bcf3b8191d6e..f6842684644490 100644 --- a/packages/block-editor/src/components/block-pattern-setup/style.scss +++ b/packages/block-editor/src/components/block-pattern-setup/style.scss @@ -5,8 +5,6 @@ align-items: flex-start; width: 100%; border-radius: $radius-block-ui; - box-shadow: inset 0 0 0 $border-width $gray-900; - outline: 1px solid transparent; // Shown for Windows 10 High Contrast mode. // TODO change to check parent. &.view-mode-grid { @@ -15,37 +13,41 @@ } .block-editor-block-pattern-setup__container { - display: grid; - grid-template-columns: 1fr 1fr; - grid-gap: $grid-unit-20; - padding: $grid-unit-20; - max-height: 550px; - overflow: auto; - margin: 0 $border-width $border-width $border-width; - width: calc(100% - #{ $border-width * 2 }); - background: $white; + column-gap: $grid-unit-30; + display: block; + width: 100%; + padding: $grid-unit-40; + column-count: 2; + + @include break-huge() { + column-count: 3; + } .block-editor-block-preview__container, div[role="button"] { cursor: pointer; } - .block-editor-block-pattern-setup-list__item-title { - padding: $grid-unit-05; - font-size: $helptext-font-size; - text-align: center; - } + .block-editor-block-pattern-setup-list__list-item { + break-inside: avoid-column; + margin-bottom: $grid-unit-30; + + .block-editor-block-preview__container { + min-height: 100px; + border-radius: $radius-block-ui; + border: $border-width solid $gray-300; + } - .block-editor-block-preview__container { - border-radius: $radius-block-ui; - border: $border-width solid $gray-300; + .block-editor-block-preview__content { + width: 100%; + } } } } .block-editor-block-pattern-setup__toolbar { + height: $header-height; box-sizing: border-box; - position: relative; padding: $grid-unit-20; width: 100%; text-align: left; @@ -54,13 +56,12 @@ // Block UI appearance. border-radius: $radius-block-ui $radius-block-ui 0 0; background-color: $white; - box-shadow: inset 0 0 0 $border-width $gray-900; - outline: 1px solid transparent; // Shown for Windows 10 High Contrast mode. - display: flex; flex-direction: row; align-items: center; justify-content: space-between; + border-top: 1px solid $gray-300; + align-self: flex-end; .block-editor-block-pattern-setup__display-controls { display: flex; @@ -93,13 +94,12 @@ box-sizing: border-box; } .pattern-slide { - opacity: 0; position: absolute; top: 0; width: 100%; margin: auto; - padding: $grid-unit-20; - transition: transform 0.5s, opacity 0.5s, z-index 0.5s; + padding: 0; + transition: transform 0.5s, z-index 0.5s; z-index: z-index(".block-editor-block-pattern-setup .pattern-slide"); &.active-slide { @@ -125,3 +125,9 @@ } } } + +.block-editor-block-pattern-setup__carousel, +.block-editor-block-pattern-setup__grid { + width: 100%; + overflow-y: auto; +} diff --git a/packages/block-editor/src/components/block-preview/auto.js b/packages/block-editor/src/components/block-preview/auto.js index f480b83ce58e26..d2eca43010a7c0 100644 --- a/packages/block-editor/src/components/block-preview/auto.js +++ b/packages/block-editor/src/components/block-preview/auto.js @@ -19,7 +19,11 @@ let MemoizedBlockList; const MAX_HEIGHT = 2000; -function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) { +function AutoBlockPreview( { + viewportWidth, + __experimentalPadding, + __experimentalMinHeight, +} ) { const [ containerResizeListener, { width: containerWidth }, @@ -68,6 +72,7 @@ function AutoBlockPreview( { viewportWidth, __experimentalPadding } ) { contentHeight > MAX_HEIGHT ? MAX_HEIGHT * scale : undefined, + minHeight: __experimentalMinHeight, } } >