-
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.
[Block Library - Post Terms]: Add dynamic variations of custom taxono…
…mies (#39837) * [Block Library - Post Terms]: Add dynamic variations of custom taxonomies * change labels + assign icons for categories and tags * update the block variation's description
- Loading branch information
1 parent
4f7f3f9
commit 98df6c2
Showing
7 changed files
with
83 additions
and
38 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
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,27 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { postCategories, postTerms } from '@wordpress/icons'; | ||
|
||
const variationIconMap = { | ||
category: postCategories, | ||
post_tag: postTerms, | ||
}; | ||
|
||
// We add `icons` to categories and tags. The remaining ones use | ||
// the block's default icon. | ||
export default function enhanceVariations( settings, name ) { | ||
if ( name !== 'core/post-terms' ) { | ||
return settings; | ||
} | ||
const variations = settings.variations.map( ( variation ) => ( { | ||
...variation, | ||
...( variationIconMap[ variation.name ] && { | ||
icon: variationIconMap[ variation.name ], | ||
} ), | ||
} ) ); | ||
return { | ||
...settings, | ||
variations, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,20 +1,27 @@ | ||
/** | ||
* Internal dependencies | ||
* WordPress dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import edit from './edit'; | ||
import variations from './variations'; | ||
import { postCategories as icon } from '@wordpress/icons'; | ||
import { addFilter } from '@wordpress/hooks'; | ||
|
||
/** | ||
* WordPress dependencies | ||
* Internal dependencies | ||
*/ | ||
import { postTerms as icon } from '@wordpress/icons'; | ||
import metadata from './block.json'; | ||
import edit from './edit'; | ||
import enhanceVariations from './hooks'; | ||
|
||
const { name } = metadata; | ||
export { metadata, name }; | ||
|
||
export const settings = { | ||
icon, | ||
variations, | ||
edit, | ||
}; | ||
|
||
// Importing this file includes side effects. This is whitelisted in block-library/package.json under sideEffects | ||
addFilter( | ||
'blocks.registerBlockType', | ||
'core/template-part', | ||
enhanceVariations | ||
); |
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 was deleted.
Oops, something went wrong.