Skip to content

Commit

Permalink
Add custom post type icon, courtesy of @jasmussen
Browse files Browse the repository at this point in the history
  • Loading branch information
gwwar committed Feb 23, 2021
1 parent b13167b commit 159288d
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions packages/block-library/src/navigation-link/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@
* WordPress dependencies
*/
import { addFilter } from '@wordpress/hooks';
import { category, page, postTitle, tag } from '@wordpress/icons';

const ICON_MAP = {
import {
category,
page,
post: postTitle,
postTitle,
tag,
//TODO: add a generic CPT icon, remember to ask folks for a new icon
};
customPostType,
} from '@wordpress/icons';

function getIcon( variationName ) {
switch ( variationName ) {
case 'post':
return postTitle;
case 'page':
return page;
case 'tag':
return tag;
case 'category':
return category;
default:
return customPostType;
}
}

function enhanceNavigationLinkVariations( settings, name ) {
if ( name !== 'core/navigation-link' ) {
Expand All @@ -21,10 +34,9 @@ function enhanceNavigationLinkVariations( settings, name ) {
const variations = settings.variations.map( ( variation ) => {
return {
...variation,
...( ! variation.icon &&
ICON_MAP[ variation.name ] && {
icon: ICON_MAP[ variation.name ],
} ),
...( ! variation.icon && {
icon: getIcon( variation.name ),
} ),
...( ! variation.isActive && {
isActive: ( blockAttributes, variationAttributes ) => {
return (
Expand Down

0 comments on commit 159288d

Please sign in to comment.