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
+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}