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

[Data Views] User patterns: Use excerpt as description #60549

Merged
merged 11 commits into from
Apr 23, 2024
15 changes: 15 additions & 0 deletions lib/compat/wordpress-6.6/post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Temporary compatibility shims for block APIs present in Gutenberg.
*
* @package gutenberg
*/

/**
* Adds support for excerpt to the wp_block post type.
*/
function gutenberg_add_excerpt_support_to_wp_block() {
add_post_type_support( 'wp_block', 'excerpt' );
}

add_action( 'init', 'gutenberg_add_excerpt_support_to_wp_block' );
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.6/option.php';
require __DIR__ . '/compat/wordpress-6.6/class-gutenberg-rest-templates-controller-6-6.php';
require __DIR__ . '/compat/wordpress-6.6/rest-api.php';
require __DIR__ . '/compat/wordpress-6.6/post.php';

// Experimental features.
require __DIR__ . '/experimental/block-editor-settings-mobile.php';
Expand Down
45 changes: 8 additions & 37 deletions packages/edit-site/src/components/page-patterns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,14 @@ const SYNC_FILTERS = [
];

function PreviewWrapper( { item, onClick, ariaDescribedBy, children } ) {
if ( item.type === PATTERN_TYPES.theme ) {
return children;
}
return (
<button
className="page-patterns-preview-field__button"
type="button"
onClick={ onClick }
onClick={ item.type !== PATTERN_TYPES.theme ? onClick : undefined }
aria-label={ item.title }
aria-describedby={ ariaDescribedBy }
aria-disabled={ item.type === PATTERN_TYPES.theme }
>
{ children }
</button>
Expand All @@ -138,21 +136,8 @@ function PreviewWrapper( { item, onClick, ariaDescribedBy, children } ) {
function Preview( { item, categoryId, viewType } ) {
const descriptionId = useId();
const isUserPattern = item.type === PATTERN_TYPES.user;
const isNonUserPattern = item.type === PATTERN_TYPES.theme;
const isTemplatePart = item.type === TEMPLATE_PART_POST_TYPE;
const isEmpty = ! item.blocks?.length;
// Only custom patterns or custom template parts can be renamed or deleted.
const isCustomPattern =
isUserPattern || ( isTemplatePart && item.isCustom );
const ariaDescriptions = [];
if ( isCustomPattern ) {
// User patterns don't have descriptions, but can be edited and deleted, so include some help text.
ariaDescriptions.push(
__( 'Press Enter to edit, or Delete to delete the pattern.' )
);
} else if ( item.description ) {
ariaDescriptions.push( item.description );
}

const [ backgroundColor ] = useGlobalStyle( 'color.background' );
const { onClick } = useLink( {
Expand All @@ -171,16 +156,7 @@ function Preview( { item, categoryId, viewType } ) {
<PreviewWrapper
item={ item }
onClick={ onClick }
ariaDescribedBy={
ariaDescriptions.length
? ariaDescriptions
.map(
( _, index ) =>
`${ descriptionId }-${ index }`
)
.join( ' ' )
: undefined
}
ariaDescribedBy={ item.description ? descriptionId : undefined }
>
{ isEmpty && isTemplatePart && __( 'Empty template part' ) }
{ isEmpty && ! isTemplatePart && __( 'Empty pattern' ) }
Expand All @@ -193,16 +169,11 @@ function Preview( { item, categoryId, viewType } ) {
</Async>
) }
</PreviewWrapper>
{ ! isNonUserPattern &&
ariaDescriptions.map( ( ariaDescription, index ) => (
<div
key={ index }
hidden
id={ `${ descriptionId }-${ index }` }
>
{ ariaDescription }
</div>
) ) }
{ item.description && (
<div hidden id={ descriptionId }>
{ item.description }
</div>
) }
</div>
);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/edit-site/src/components/page-patterns/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
// Windows High Contrast mode will show this outline, but not the box-shadow.
outline: 2px solid transparent;
}

&[aria-disabled="true"] {
cursor: default;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ const convertPatternPostToItem = ( patternPost, categories ) => ( {
syncStatus: patternPost.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full,
title: patternPost.title.raw,
type: patternPost.type,
description: patternPost.excerpt.raw,
patternPost,
} );

Expand Down
Loading