-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add block variation matcher to display information from a found match (…
- Loading branch information
1 parent
728485d
commit 05f0e57
Showing
2 changed files
with
63 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { | ||
category as categoryIcon, | ||
page as pageIcon, | ||
postTitle as postIcon, | ||
tag as tagIcon, | ||
} from '@wordpress/icons'; | ||
const variations = [ | ||
{ | ||
name: 'link', | ||
isDefault: true, | ||
title: __( 'Link' ), | ||
description: __( 'A link to a URL.' ), | ||
attributes: {}, | ||
}, | ||
{ | ||
name: 'post', | ||
icon: postIcon, | ||
title: __( 'Post Link' ), | ||
description: __( 'A link to a post.' ), | ||
attributes: { type: 'post' }, | ||
}, | ||
{ | ||
name: 'page', | ||
icon: pageIcon, | ||
title: __( 'Page Link' ), | ||
description: __( 'A link to a page.' ), | ||
attributes: { type: 'page' }, | ||
}, | ||
{ | ||
name: 'category', | ||
icon: categoryIcon, | ||
title: __( 'Category Link' ), | ||
description: __( 'A link to a category.' ), | ||
attributes: { type: 'category' }, | ||
}, | ||
{ | ||
name: 'tag', | ||
icon: tagIcon, | ||
title: __( 'Tag Link' ), | ||
description: __( 'A link to a tag.' ), | ||
attributes: { type: 'tag' }, | ||
}, | ||
]; | ||
|
||
/** | ||
* Add `isActive` function to all `navigation link` variations, if not defined. | ||
* `isActive` function is used to find a variation match from a created | ||
* Block by providing its attributes. | ||
*/ | ||
variations.forEach( ( variation ) => { | ||
if ( variation.isActive ) return; | ||
variation.isActive = ( blockAttributes, variationAttributes ) => | ||
blockAttributes.type === variationAttributes.type; | ||
} ); | ||
|
||
export default variations; |