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

Add hidden scope to WPBlockVariationScope #55522

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
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 @@ -26,12 +26,17 @@ function VariationsButtons( {
selectedValue,
variations,
} ) {
// Filters out the hidden scope transforms, which do not render in the block card.
const filteredVariations = variations.filter(
( variation ) => ! variation.scope.includes( 'hidden' )
);

return (
<fieldset className={ className }>
<VisuallyHidden as="legend">
{ __( 'Transform to variation' ) }
</VisuallyHidden>
{ variations.map( ( variation ) => (
{ filteredVariations.map( ( variation ) => (
<Button
key={ variation.name }
icon={ <BlockIcon icon={ variation.icon } showColors /> }
Expand Down Expand Up @@ -60,7 +65,12 @@ function VariationsDropdown( {
selectedValue,
variations,
} ) {
const selectOptions = variations.map(
// Filters out the hidden scope transforms, which do not render in the block card.
const filteredVariations = variations.filter(
( variation ) => ! variation.scope.includes( 'hidden' )
);

const selectOptions = filteredVariations.map(
( { name, title, description } ) => ( {
value: name,
label: title,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/post-date/variations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const variations = [
title: __( 'Modified Date' ),
description: __( "Display a post's last updated date." ),
attributes: { displayType: 'modified' },
scope: [ 'block', 'inserter' ],
scope: [ 'block', 'inserter', 'transform', 'hidden' ],
isActive: ( blockAttributes ) =>
blockAttributes.displayType === 'modified',
icon: postDate,
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { unlock } from '../lock-unlock';
/**
* Named block variation scopes.
*
* @typedef {'block'|'inserter'|'transform'} WPBlockVariationScope
* @typedef {'block'|'inserter'|'transform'|'hidden'} WPBlockVariationScope
*/

/**
Expand Down
Loading