From 3fb7fae42db835ec2cfe23664bf5fa08f204da5f Mon Sep 17 00:00:00 2001 From: Kai Hao Date: Thu, 8 Sep 2022 15:21:24 +0800 Subject: [PATCH] Add icons for different types of suggestions --- .../components/link-control/search-item.js | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/link-control/search-item.js b/packages/block-editor/src/components/link-control/search-item.js index 62dcf6f61fd84..a4f178d8263cc 100644 --- a/packages/block-editor/src/components/link-control/search-item.js +++ b/packages/block-editor/src/components/link-control/search-item.js @@ -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 ( + + ); + } + + return null; +} export const LinkControlSearchItem = ( { itemProps, @@ -30,12 +67,7 @@ export const LinkControlSearchItem = ( { 'is-entity': ! isURL, } ) } > - { isURL && ( - - ) } +