Skip to content

Commit

Permalink
Add icons for different types of suggestions in LinkControl (#43970)
Browse files Browse the repository at this point in the history
* Add icons for different types of suggestions

* Use a map
  • Loading branch information
kevin940726 authored Sep 12, 2022
1 parent 9e08674 commit 504ff67
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions packages/block-editor/src/components/link-control/search-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,44 @@ import classnames from 'classnames';
import { safeDecodeURI, filterURLForDisplay } from '@wordpress/url';
import { __ } from '@wordpress/i18n';
import { Button, TextHighlight } from '@wordpress/components';
import { Icon, globe } from '@wordpress/icons';
import {
Icon,
globe,
page,
tag,
postList,
category,
file,
} from '@wordpress/icons';

const ICONS_MAP = {
post: postList,
page,
post_tag: tag,
category,
attachment: file,
};

function SearchItemIcon( { isURL, suggestion } ) {
let icon = null;

if ( isURL ) {
icon = globe;
} else if ( suggestion.type in ICONS_MAP ) {
icon = ICONS_MAP[ suggestion.type ];
}

if ( icon ) {
return (
<Icon
className="block-editor-link-control__search-item-icon"
icon={ icon }
/>
);
}

return null;
}

export const LinkControlSearchItem = ( {
itemProps,
Expand All @@ -30,12 +67,7 @@ export const LinkControlSearchItem = ( {
'is-entity': ! isURL,
} ) }
>
{ isURL && (
<Icon
className="block-editor-link-control__search-item-icon"
icon={ globe }
/>
) }
<SearchItemIcon suggestion={ suggestion } isURL={ isURL } />

<span className="block-editor-link-control__search-item-header">
<span className="block-editor-link-control__search-item-title">
Expand Down

0 comments on commit 504ff67

Please sign in to comment.