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

Simplify the inserter styles and scrollable #44088

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ $z-layers: (
".edit-post-sidebar__panel-tab.is-active": 1,

// These next three share a stacking context
".block-editor-inserter__tabs .components-tab-panel__tab-content": 0, // lower scrolling content
".block-editor-inserter__tabs .components-tab-panel__tabs": 1, // higher sticky element
".block-editor-inserter__search": 1, // higher sticky element
".block-library-template-part__selection-search": 1, // higher sticky element

// These next two share a stacking context
Expand Down
71 changes: 41 additions & 30 deletions packages/block-editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -181,23 +186,28 @@ function InserterMenu(
},
} ) );

const showAsTabs = ! filterValue && ( showPatterns || hasReusableBlocks );

return (
<div className="block-editor-inserter__menu">
<div className="block-editor-inserter__main-area">
{ /* The following div is necessary to fix the sticky position of the search form. */ }
<div className="block-editor-inserter__content">
<SearchControl
className="block-editor-inserter__search"
onChange={ ( value ) => {
if ( hoveredItem ) setHoveredItem( null );
setFilterValue( value );
} }
value={ filterValue }
label={ __( 'Search for blocks and patterns' ) }
placeholder={ __( 'Search' ) }
ref={ searchRef }
/>
{ !! filterValue && (
<div
className={ classnames( 'block-editor-inserter__main-area', {
'show-as-tabs': showAsTabs,
} ) }
>
<SearchControl
className="block-editor-inserter__search"
onChange={ ( value ) => {
if ( hoveredItem ) setHoveredItem( null );
setFilterValue( value );
} }
value={ filterValue }
label={ __( 'Search for blocks and patterns' ) }
placeholder={ __( 'Search' ) }
ref={ searchRef }
/>
{ !! filterValue && (
<div className="block-editor-inserter__no-tab-container">
<InserterSearchResults
filterValue={ filterValue }
onSelect={ onSelect }
Expand All @@ -211,21 +221,22 @@ function InserterMenu(
showBlockDirectory
shouldFocusBlock={ shouldFocusBlock }
/>
) }
{ ! filterValue && ( showPatterns || hasReusableBlocks ) && (
<InserterTabs
showPatterns={ showPatterns }
showReusableBlocks={ hasReusableBlocks }
prioritizePatterns={ prioritizePatterns }
>
{ getCurrentTab }
</InserterTabs>
) }
{ ! filterValue &&
! showPatterns &&
! hasReusableBlocks &&
blocksTab }
</div>
</div>
) }
{ showAsTabs && (
<InserterTabs
showPatterns={ showPatterns }
showReusableBlocks={ hasReusableBlocks }
prioritizePatterns={ prioritizePatterns }
>
{ getCurrentTab }
</InserterTabs>
) }
{ ! filterValue && ! showAsTabs && (
<div className="block-editor-inserter__no-tab-container">
{ blocksTab }
</div>
) }
</div>
{ showInserterHelpPanel && hoveredItem && (
<InserterPreviewPanel item={ hoveredItem } />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export const patterns = [
{
categories: [ 'featured', 'text' ],
content:
'<!-- wp:heading {"align":"wide","style":{"typography":{"fontSize":"48px","lineHeight":"1.1"}}} -->\n<h2 class="alignwide" id="we-re-a-studio-in-berlin-with-an-international-practice-in-architecture-urban-planning-and-interior-design-we-believe-in-sharing-knowledge-and-promoting-dialogue-to-increase-the-creative-potential-of-collaboration" style="font-size:48px;line-height:1.1">We\'re a studio in Berlin with an international practice in architecture, urban planning and interior design. We believe in sharing knowledge and promoting dialogue to increase the creative potential of collaboration.</h2>\n<!-- /wp:heading -->',
description: 'Heading text',
keywords: [ 'large text', 'title' ],
name: 'heading',
title: 'Heading',
},
];

export const patternCategories = [
{
name: 'featured',
label: 'Featured',
},
{
name: 'text',
label: 'Text',
},
];

export const reusableBlocks = [
{
content: {
raw: '\x3C!-- wp:paragraph -->\n<p>This is reusable</p>\n\x3C!-- /wp:paragraph -->',
protected: false,
block_version: 1,
},
date: '2022-09-12T13:28:06',
date_gmt: '2022-09-12T13:28:06',
id: 70,
link: 'http://localhost:8888/?p=70',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks temporary? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is in the storybook story, it's not important, I just copied my own reusable blocks :P

modified: '2022-09-12T13:28:06',
modified_gmt: '2022-09-12T13:28:06',
password: '',
slug: 'simple-paragraph',
status: 'publish',
template: '',
title: { raw: 'Simple paragraph' },
type: 'wp_block',
},
];
90 changes: 90 additions & 0 deletions packages/block-editor/src/components/inserter/stories/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**
* Internal dependencies
*/
import BlockLibrary from '../library';
import BlockEditorProvider from '../../provider';
import { patternCategories, patterns, reusableBlocks } from './fixtures';
import Inserter from '../';

export default { title: 'BlockEditor/Inserter' };

export const libraryWithoutPatterns = () => {
const wrapperStyle = {
margin: '24px',
height: 400,
border: '1px solid #f3f3f3',
display: 'inline-block',
};
return (
<BlockEditorProvider>
<div style={ wrapperStyle }>
<BlockLibrary showInserterHelpPanel />
</div>
</BlockEditorProvider>
);
};

export const libraryWithPatterns = () => {
const wrapperStyle = {
margin: '24px',
height: 400,
border: '1px solid #f3f3f3',
display: 'inline-block',
};
return (
<BlockEditorProvider
settings={ {
__experimentalBlockPatternCategories: patternCategories,
__experimentalBlockPatterns: patterns,
} }
>
<div style={ wrapperStyle }>
<BlockLibrary showInserterHelpPanel />
</div>
</BlockEditorProvider>
);
};

export const libraryWithPatternsAndReusableBlocks = () => {
const wrapperStyle = {
margin: '24px',
height: 400,
border: '1px solid #f3f3f3',
display: 'inline-block',
};
return (
<BlockEditorProvider
settings={ {
__experimentalBlockPatternCategories: patternCategories,
__experimentalBlockPatterns: patterns,
__experimentalReusableBlocks: reusableBlocks,
} }
>
<div style={ wrapperStyle }>
<BlockLibrary showInserterHelpPanel />
</div>
</BlockEditorProvider>
);
};

export const quickInserter = () => {
const wrapperStyle = {
margin: '24px',
height: 400,
border: '1px solid #f3f3f3',
display: 'inline-block',
};
return (
<BlockEditorProvider
settings={ {
__experimentalBlockPatternCategories: patternCategories,
__experimentalBlockPatterns: patterns,
__experimentalReusableBlocks: reusableBlocks,
} }
>
<div style={ wrapperStyle }>
<Inserter __experimentalIsQuick />
</div>
</BlockEditorProvider>
);
};
48 changes: 21 additions & 27 deletions packages/block-editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ $block-inserter-tabs-height: 44px;
}
}

.block-editor-inserter__content {
.block-editor-inserter__main-area {
position: relative;
display: flex;
flex-direction: column;
height: 100%;
gap: $grid-unit-20;
width: auto;
@include break-medium {
width: $block-inserter-width;
}

&.show-as-tabs {
gap: 0;
}
}

.block-editor-inserter__popover.is-quick {
Expand Down Expand Up @@ -78,15 +90,6 @@ $block-inserter-tabs-height: 44px;
overflow: visible;
}

.block-editor-inserter__main-area {
width: auto;
overflow-y: auto;
height: 100%;
@include break-medium {
width: $block-inserter-width;
}
}

.block-editor-inserter__inline-elements {
margin-top: -1px;
}
Expand All @@ -100,11 +103,7 @@ $block-inserter-tabs-height: 44px;
}

.block-editor-inserter__search {
background: $white;
padding: $grid-unit-20 $grid-unit-20 0 $grid-unit-20;
position: sticky;
top: 0;
z-index: z-index(".block-editor-inserter__search");

.components-search-control__icon {
right: $grid-unit-10 + ($grid-unit-60 - $icon-size) * 0.5;
Expand All @@ -116,15 +115,12 @@ $block-inserter-tabs-height: 44px;
}

.block-editor-inserter__tabs {
flex-grow: 1;
display: flex;
flex-direction: column;
overflow: hidden;

.components-tab-panel__tabs {
position: sticky;
// Computed based off the search input height and paddings
top: $grid-unit-20 + $grid-unit-60;
background: $white;
z-index: z-index(".block-editor-inserter__tabs .components-tab-panel__tabs");
border-bottom: $border-width solid $gray-300;

.components-tab-panel__tabs-item {
Expand All @@ -137,12 +133,15 @@ $block-inserter-tabs-height: 44px;
display: flex;
flex-grow: 1;
flex-direction: column;
// Make a stacking context that keeps all descendents behind the sticky tabs
position: relative;
z-index: z-index(".block-editor-inserter__tabs .components-tab-panel__tab-content");
overflow-y: auto;
}
}

.block-editor-inserter__no-tab-container {
overflow-y: auto;
flex-grow: 1;
}

.block-editor-inserter__panel-header {
display: inline-flex;
align-items: center;
Expand Down Expand Up @@ -175,11 +174,6 @@ $block-inserter-tabs-height: 44px;
border: none;
}

.block-editor-inserter__block-list {
flex-grow: 1;
position: relative;
}

.block-editor-inserter__reusable-blocks-panel {
position: relative;
text-align: right;
Expand Down