import { getHighlightedParts, getPropertyByPath, unescape, } from 'instantsearch.js/es/lib/utils'; import React from 'react'; import { Highlight as HighlightUiComponent } from '../ui/Highlight'; import type { PartialKeys } from '../types'; import type { HighlightProps as HighlightUiComponentProps } from '../ui/Highlight'; import type { BaseHit, Hit } from 'instantsearch.js'; export type HighlightProps> = { hit: THit; attribute: keyof THit | string[]; } & PartialKeys< Omit, 'highlightedTagName' | 'nonHighlightedTagName' | 'separator' >; export function Highlight>({ hit, attribute, highlightedTagName, nonHighlightedTagName, separator, ...props }: HighlightProps) { const property = getPropertyByPath(hit._highlightResult, attribute as string) || []; const properties = Array.isArray(property) ? property : [property]; const parts = properties.map((singleValue) => getHighlightedParts(unescape(singleValue.value || '')) ); return ( ); }