docbrown/app/javascript/articles/components/SearchSnippet.jsx
Suzanne Aitchison dcecc8bf00
Log prop-types warnings to console in development (#14635)
* enable debug for warnings in dev env

* remove preact/devtools call no longer needed

* fix majority of proptype errors on home page

* sweep up proptype errors from listings page

* fix article form error
2021-09-01 09:27:58 +01:00

35 lines
938 B
JavaScript

import { h } from 'preact';
import { articleSnippetResultPropTypes } from '../../common-prop-types';
export const SearchSnippet = ({ highlightText }) => {
if (highlightText && highlightText.body_text.length > 0) {
const hitHighlights = highlightText.body_text;
let bodyTextSnippet = '';
if (hitHighlights[0]) {
const firstSnippetChar = hitHighlights[0];
let startingEllipsis = '';
if (firstSnippetChar.toLowerCase() !== firstSnippetChar.toUpperCase()) {
startingEllipsis = '…';
}
bodyTextSnippet = `${startingEllipsis + hitHighlights.join('...')}`;
}
if (bodyTextSnippet.length > 0) {
return (
<div className="crayons-story__snippet">
<span>{bodyTextSnippet}</span>
</div>
);
}
}
return null;
};
SearchSnippet.propTypes = {
highlightText: articleSnippetResultPropTypes,
};
SearchSnippet.displayName = 'SearchSnippet';