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
@@ -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>
</>
) : (