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

Patterns: add a component to display empty pattern title #52548

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
__unstableCompositeItem as CompositeItem,
Tooltip,
__experimentalHStack as HStack,
__experimentalTruncate as Truncate,
} from '@wordpress/components';
import { useInstanceId } from '@wordpress/compose';
import { __ } from '@wordpress/i18n';
Expand All @@ -33,6 +34,17 @@ const WithToolTip = ( { showTooltip, title, children } ) => {
return <>{ children }</>;
};

function BlockPatternItemPlaceholder( { title } ) {
return (
<div className="block-editor-block-patterns-list__empty-item">
<Truncate numberOfLines={ 2 }>{ title }</Truncate>
<span className="block-editor-block-patterns-list__empty-item-text">
{ __( '(Empty pattern)' ) }
</span>
</div>
);
}

function BlockPattern( {
isDraggable,
pattern,
Expand All @@ -45,6 +57,7 @@ function BlockPattern( {
const { blocks, viewportWidth } = pattern;
const instanceId = useInstanceId( BlockPattern );
const descriptionId = `block-editor-block-patterns-list__item-description-${ instanceId }`;
const isEmpty = ! blocks?.length;

return (
<InserterDraggableBlocks
Expand Down Expand Up @@ -101,10 +114,16 @@ function BlockPattern( {
pattern.description ? descriptionId : undefined
}
>
<BlockPreview
blocks={ blocks }
viewportWidth={ viewportWidth }
/>
{ ! isEmpty ? (
<BlockPreview
Copy link
Member Author

Choose a reason for hiding this comment

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

Should we also disable the onClick on the .block-editor-block-patterns-list__item element?

If you click on a pattern with no content, a message appears — "[Your pattern] inserted" — but it inserts nothing.

blocks={ blocks }
viewportWidth={ viewportWidth }
/>
) : (
<BlockPatternItemPlaceholder
title={ pattern.title }
/>
) }

<HStack className="block-editor-patterns__pattern-details">
{ pattern.id && ! pattern.syncStatus && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@
.block-editor-block-patterns-list__item {
height: 100%;

.block-editor-block-patterns-list__empty-item {
min-height: 60px;
display: flex;
flex-flow: column;
align-items: center;
justify-content: center;
color: $gray-600;
border: 1px solid $gray-400;
padding: $grid-unit-10;
border-radius: 4px;
}

.block-editor-block-patterns-list__empty-item-text {
margin-top: $grid-unit-10;
font-size: 11px;
display: inline-block;
}

.block-editor-block-preview__container {
display: flex;
align-items: center;
Expand All @@ -31,10 +49,12 @@
flex-grow: 1;
}

&:hover .block-editor-block-patterns-list__empty-item,
&:hover .block-editor-block-preview__container {
box-shadow: 0 0 0 2px $gray-900;
}

&:focus .block-editor-block-patterns-list__empty-item,
&:focus .block-editor-block-preview__container {
@include button-style-outset__focus($gray-900);
}
Expand Down
Loading