Skip to content

Commit

Permalink
Support passing an array of attribute keys to block variation isActive
Browse files Browse the repository at this point in the history
Instead of a callback, you may pass an array of attributes which are
checked against the block to see if this variation is active.

WordPress/gutenberg#30913
  • Loading branch information
lipemat committed May 19, 2021
1 parent 5b12357 commit 6750167
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions wordpress__blocks/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ declare module '@wordpress/blocks' {
}
}
};

/**
* Shape and retrieval type for block data.
*
Expand All @@ -48,7 +49,6 @@ declare module '@wordpress/blocks' {
}
}


export type BlockEditProps<Attr> = {
className: string;
setAttributes: ( newValue: {
Expand All @@ -58,6 +58,11 @@ declare module '@wordpress/blocks' {
isSelected: boolean
}

/**
* Block Variation shape.
*
* @link https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/
*/
export type BlockVariation<Attr = Object> = {
name: string;
title: string;
Expand All @@ -70,7 +75,7 @@ declare module '@wordpress/blocks' {
example?: BlockExample<Attr>;
scope?: Array<'block' | 'inserter' | 'transform'>;
keywords?: string[];
isActive?: ( attr: BlockAttributes<Attr>, variation: BlockAttributes<Attr> ) => boolean;
isActive?: ( ( attr: BlockAttributes<Attr>, variation: BlockAttributes<Attr> ) => boolean ) | Array<keyof Attr>;
}

export type BlockExample<Attr = Object> = {
Expand Down Expand Up @@ -233,7 +238,7 @@ declare module '@wordpress/blocks' {
/**
* Registers a new block variation for an existing block type.
*
* @link https://make.wordpress.org/core/2020/02/27/introduce-block-variations-api/
* @link https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/
*
* @param blockName - Name of the block (example: “core/columns”).
* @param variation - Object describing a block variation.
Expand Down

0 comments on commit 6750167

Please sign in to comment.