react-code-dataset / react-instantsearch /packages /react-instantsearch-dom /src /widgets /Snippet.js
| import { connectHighlight } from 'react-instantsearch-core'; | |
| import Snippet from '../components/Snippet'; | |
| /** | |
| * Renders any attribute from an hit into its highlighted snippet form when relevant. | |
| * | |
| * Read more about it in the [Highlighting results](guide/Highlighting_results.html) guide. | |
| * @name Snippet | |
| * @kind widget | |
| * @requirements To use this widget, the attribute name passed to the `attribute` prop must be | |
| * present in "Attributes to snippet" on the Algolia dashboard or configured as `attributesToSnippet` | |
| * via a set settings call to the Algolia API. | |
| * @propType {string} attribute - location of the highlighted snippet attribute in the hit (the corresponding element can be either a string or an array of strings) | |
| * @propType {object} hit - hit object containing the highlighted snippet attribute | |
| * @propType {string} [tagName='em'] - tag to be used for highlighted parts of the attribute | |
| * @propType {string} [nonHighlightedTagName='span'] - tag to be used for the parts of the hit that are not highlighted | |
| * @propType {node} [separator=',<space>'] - symbol used to separate the elements of the array in case the attribute points to an array of strings. | |
| * @themeKey ais-Snippet - the root span of the widget | |
| * @themeKey ais-Snippet-highlighted - the highlighted text | |
| * @themeKey ais-Snippet-nonHighlighted - the normal text | |
| * @example | |
| * import React from 'react'; | |
| * import algoliasearch from 'algoliasearch/lite'; | |
| * import { InstantSearch, SearchBox, Hits, Snippet } from 'react-instantsearch-dom'; | |
| * | |
| * const searchClient = algoliasearch( | |
| * 'latency', | |
| * '6be0576ff61c053d5f9a3225e2a90f76' | |
| * ); | |
| * | |
| * const Hit = ({ hit }) => ( | |
| * <div> | |
| * <Snippet attribute="description" hit={hit} /> | |
| * </div> | |
| * ); | |
| * | |
| * const App = () => ( | |
| * <InstantSearch | |
| * searchClient={searchClient} | |
| * indexName="instant_search" | |
| * > | |
| * <SearchBox defaultRefinement="adjustable" /> | |
| * <Hits hitComponent={Hit} /> | |
| * </InstantSearch> | |
| * ); | |
| */ | |
| export default connectHighlight(Snippet, { $$widgetType: 'ais.snippet' }); | |