Add ability to pass icon as function to have ability to customize it by search item

Signed-off-by: Ilya Savich <isavich@box.com>
This commit is contained in:
Ilya Savich
2023-02-17 12:16:21 +01:00
parent 4323348512
commit 3f75b7607c
7 changed files with 29 additions and 9 deletions
+8
View File
@@ -0,0 +1,8 @@
---
'@backstage/plugin-techdocs': patch
'@backstage/plugin-catalog': patch
'@backstage/plugin-explore': patch
---
Add ability to pass icon as function to have ability
to customize it by search item
+1 -1
View File
@@ -117,7 +117,7 @@ export interface CatalogSearchResultListItemProps {
// (undocumented)
highlight?: ResultHighlight;
// (undocumented)
icon?: ReactNode;
icon?: ReactNode | ((result: IndexableDocument) => ReactNode);
// (undocumented)
rank?: number;
// (undocumented)
@@ -50,7 +50,7 @@ const useStyles = makeStyles(
* @public
*/
export interface CatalogSearchResultListItemProps {
icon?: ReactNode;
icon?: ReactNode | ((result: IndexableDocument) => ReactNode);
result?: IndexableDocument;
highlight?: ResultHighlight;
rank?: number;
@@ -69,7 +69,11 @@ export function CatalogSearchResultListItem(
return (
<div className={classes.item}>
{props.icon && <ListItemIcon>{props.icon}</ListItemIcon>}
{props.icon && (
<ListItemIcon>
{typeof props.icon === 'function' ? props.icon(result) : props.icon}
</ListItemIcon>
)}
<div className={classes.flexContainer}>
<ListItemText
className={classes.itemText}
+1 -1
View File
@@ -135,7 +135,7 @@ export interface ToolSearchResultListItemProps {
// (undocumented)
highlight?: ResultHighlight;
// (undocumented)
icon?: ReactNode;
icon?: ReactNode | ((result: IndexableDocument) => ReactNode);
// (undocumented)
rank?: number;
// (undocumented)
@@ -46,7 +46,7 @@ const useStyles = makeStyles({
* @public
*/
export interface ToolSearchResultListItemProps {
icon?: ReactNode;
icon?: ReactNode | ((result: IndexableDocument) => ReactNode);
result?: IndexableDocument;
highlight?: ResultHighlight;
rank?: number;
@@ -62,7 +62,11 @@ export function ToolSearchResultListItem(props: ToolSearchResultListItemProps) {
return (
<>
{props.icon && <ListItemIcon>{props.icon}</ListItemIcon>}
{props.icon && (
<ListItemIcon>
{typeof props.icon === 'function' ? props.icon(result) : props.icon}
</ListItemIcon>
)}
<div className={classes.flexContainer}>
<ListItemText
className={classes.itemText}
+1 -1
View File
@@ -406,7 +406,7 @@ export const TechDocsSearchResultListItem: (
// @public
export type TechDocsSearchResultListItemProps = {
icon?: ReactNode;
icon?: ReactNode | ((result: any) => ReactNode);
result?: any;
highlight?: ResultHighlight;
rank?: number;
@@ -37,7 +37,7 @@ const useStyles = makeStyles({
* @public
*/
export type TechDocsSearchResultListItemProps = {
icon?: ReactNode;
icon?: ReactNode | ((result: any) => ReactNode);
result?: any;
highlight?: ResultHighlight;
rank?: number;
@@ -151,7 +151,11 @@ export const TechDocsSearchResultListItem = (
const ListItemWrapper = ({ children }: PropsWithChildren<{}>) =>
asListItem ? (
<>
{icon && <ListItemIcon>{icon}</ListItemIcon>}
{icon && (
<ListItemIcon>
{typeof icon === 'function' ? icon(result) : icon}
</ListItemIcon>
)}
<div className={classes.flexContainer}>{children}</div>
</>
) : (