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

Show list of patterns in template part sidebar in focus mode #47507

Closed
wants to merge 2 commits 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 @@ -6,6 +6,11 @@ import { Icon } from '@wordpress/components';
import { store as editorStore } from '@wordpress/editor';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { __, sprintf } from '@wordpress/i18n';
import {
store as blockEditorStore,
__experimentalBlockPatternsList as BlockPatternsList,
} from '@wordpress/block-editor';

/**
* Internal dependencies
Expand All @@ -14,10 +19,37 @@ import { store as editSiteStore } from '../../../store';
import TemplateActions from './template-actions';
import TemplateAreas from './template-areas';

const MaybeBlockPatterns = ( { template, blockPatterns, title } ) => {
if ( template.type !== 'wp_template_part' || blockPatterns?.length === 0 ) {
return null;
}

return (
<>
<p>
{ sprintf(
// translators: %s: Type of template part (i.e. header, footer, etc.)
__(
'Choose a pre-designed pattern to switch up the look and feel of your %s '
),
title.toLowerCase()
) }
</p>
<BlockPatternsList
blockPatterns={ blockPatterns }
shownPatterns={ blockPatterns }
onClickPattern={ ( pattern ) => {
console.log( 'pattern clicked ', pattern );
Copy link
Member Author

Choose a reason for hiding this comment

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

TODO: need to implement actually replacing the template part with the pattern's content.

} }
/>
</>
);
};
export default function TemplateCard() {
const {
info: { title, description, icon },
template,
blockPatterns,
} = useSelect( ( select ) => {
const { getEditedPostType, getEditedPostId } = select( editSiteStore );
const { getEditedEntityRecord } = select( coreStore );
Expand All @@ -30,7 +62,13 @@ export default function TemplateCard() {

const info = record ? getTemplateInfo( record ) : {};

return { info, template: record };
const patterns = record?.slug
? select( blockEditorStore ).getPatternsByBlockTypes(
`core/template-part/${ record.slug }`
)
: [];

return { info, template: record, blockPatterns: patterns };
}, [] );

if ( ! title && ! description ) {
Expand All @@ -51,6 +89,11 @@ export default function TemplateCard() {
{ decodeEntities( description ) }
</div>
<TemplateAreas />
<MaybeBlockPatterns
template={ template }
blockPatterns={ blockPatterns }
title={ title }
/>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
min-width: auto;
}
}

& .block-editor-block-patterns-list__item .block-editor-block-preview__container {
border: 1px solid $gray-300;
Copy link
Member Author

Choose a reason for hiding this comment

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

What would be a good mechanism to highlight patterns when they are not hovered/selected? I found that if the pattern has a white background it does not stand out of its own in the list.

Copy link
Member

Choose a reason for hiding this comment

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

How about the box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); that we use in other similar situations (like the color indicators).

Copy link
Contributor

Choose a reason for hiding this comment

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

We might consider making a var for that, if we're going to start using it in different places.

}
}

h3.edit-site-template-card__template-areas-title {
Expand Down