Skip to content

Commit

Permalink
Block Switcher Preview: Adjust the position and enable pattern previe…
Browse files Browse the repository at this point in the history
…w in mobile viewport (#63512)

Unlinked contributors: albanyacademy.

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: ntsekouras <[email protected]>
Co-authored-by: ndiego <[email protected]>
Co-authored-by: talldan <[email protected]>
Co-authored-by: annezazu <[email protected]>
Co-authored-by: richtabor <[email protected]>
  • Loading branch information
7 people authored Jul 16, 2024
1 parent 52723a8 commit fab9fbc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
import { __ } from '@wordpress/i18n';
import { useState } from '@wordpress/element';
import { useInstanceId } from '@wordpress/compose';
import { useInstanceId, useViewportMatch } from '@wordpress/compose';
import { chevronRight } from '@wordpress/icons';

import {
Expand Down Expand Up @@ -34,6 +34,7 @@ function PatternTransformationsMenu( {
} ) {
const [ showTransforms, setShowTransforms ] = useState( false );
const patterns = useTransformedPatterns( statePatterns, blocks );

if ( ! patterns.length ) {
return null;
}
Expand All @@ -60,21 +61,22 @@ function PatternTransformationsMenu( {
}

function PreviewPatternsPopover( { patterns, onSelect } ) {
const isMobile = useViewportMatch( 'medium', '<' );

return (
<div className="block-editor-block-switcher__popover__preview__parent">
<div className="block-editor-block-switcher__popover__preview__container">
<Popover
className="block-editor-block-switcher__preview__popover"
position="bottom right"
>
<div className="block-editor-block-switcher__preview is-pattern-list-preview">
<BlockPatternsList
patterns={ patterns }
onSelect={ onSelect }
/>
</div>
</Popover>
</div>
<div className="block-editor-block-switcher__popover-preview-container">
<Popover
className="block-editor-block-switcher__popover-preview"
placement={ isMobile ? 'bottom' : 'right-start' }
offset={ 16 }
>
<div className="block-editor-block-switcher__preview is-pattern-list-preview">
<BlockPatternsList
patterns={ patterns }
onSelect={ onSelect }
/>
</div>
</Popover>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,35 @@
*/
import { __ } from '@wordpress/i18n';
import { Popover } from '@wordpress/components';
import { useViewportMatch } from '@wordpress/compose';

/**
* Internal dependencies
*/
import BlockPreview from '../block-preview';

export default function PreviewBlockPopover( { blocks } ) {
const isMobile = useViewportMatch( 'medium', '<' );

if ( isMobile ) {
return null;
}

return (
<div className="block-editor-block-switcher__popover__preview__parent">
<div className="block-editor-block-switcher__popover__preview__container">
<Popover
className="block-editor-block-switcher__preview__popover"
placement="bottom-start"
focusOnMount={ false }
>
<div className="block-editor-block-switcher__preview">
<div className="block-editor-block-switcher__preview-title">
{ __( 'Preview' ) }
</div>
<BlockPreview viewportWidth={ 500 } blocks={ blocks } />
<div className="block-editor-block-switcher__popover-preview-container">
<Popover
className="block-editor-block-switcher__popover-preview"
placement="right-start"
focusOnMount={ false }
offset={ 16 }
>
<div className="block-editor-block-switcher__preview">
<div className="block-editor-block-switcher__preview-title">
{ __( 'Preview' ) }
</div>
</Popover>
</div>
<BlockPreview viewportWidth={ 500 } blocks={ blocks } />
</div>
</Popover>
</div>
);
}
25 changes: 8 additions & 17 deletions packages/block-editor/src/components/block-switcher/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,18 @@
min-width: 300px;
}

.block-editor-block-switcher__popover__preview__parent {
.block-editor-block-switcher__popover__preview__container {
position: absolute;
top: -$grid-unit-15;
left: calc(100% + #{$grid-unit-20});
}
.block-editor-block-switcher__popover-preview-container {
left: 0;
position: absolute;
top: -$border-width;
width: 100%;
bottom: 0;
pointer-events: none;
}

.block-editor-block-switcher__preview__popover {
display: none;
.block-editor-block-switcher__popover-preview {
overflow: hidden;

// Position correctly. Needs specificity.
&.components-popover {
margin-top: $grid-unit-15 - $border-width;
}

@include break-medium() {
display: block;
}

.components-popover__content {
width: 300px;
border: $border-width solid $gray-900;
Expand Down

0 comments on commit fab9fbc

Please sign in to comment.