Skip to content

Commit

Permalink
Add icons for different types of suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Sep 8, 2022
1 parent 85b96b7 commit 3fb7fae
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';

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

if ( isURL ) {
icon = globe;
} else if ( suggestion.type === 'post' ) {
icon = postList;
} else if ( suggestion.type === 'page' ) {
icon = page;
} else if ( suggestion.type === 'post_tag' ) {
icon = tag;
} else if ( suggestion.type === 'category' ) {
icon = category;
} else if ( suggestion.type === 'attachment' ) {
icon = file;
}

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 3fb7fae

Please sign in to comment.