-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2959 from 10up/feature/2527
Support customizing the template for search results in Instant Results
- Loading branch information
Showing
6 changed files
with
303 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* WordPress dependencies. | ||
*/ | ||
import { React, WPElement } from '@wordpress/element'; | ||
import { applyFilters } from '@wordpress/hooks'; | ||
|
||
/** | ||
* Internal dependencies. | ||
*/ | ||
import StarRating from './star-rating'; | ||
import Image from './image'; | ||
|
||
/** | ||
* Search result. | ||
* | ||
* @param {object} props Component props. | ||
* @param {number} props.averageRating Average rating. | ||
* @param {string} props.date Localized date. | ||
* @param {string} props.excerpt Highlighted excerpt. | ||
* @param {string} props.priceHtml Product price HTML. | ||
* @param {object} props.thumbnail Thumbnail image attributes. | ||
* @param {string} props.title Highlighted title. | ||
* @param {string} props.type Type label. | ||
* @param {string} props.url URL. | ||
* @returns {WPElement} Component element. | ||
*/ | ||
const Result = ({ averageRating = 0, date, excerpt, priceHtml, thumbnail, title, type, url }) => { | ||
return ( | ||
<article | ||
className={`ep-search-result ${thumbnail ? 'ep-search-result--has-thumbnail' : null}`} | ||
> | ||
{thumbnail && ( | ||
<a className="ep-search-result__thumbnail" href={url}> | ||
<Image {...thumbnail} /> | ||
</a> | ||
)} | ||
|
||
<header className="ep-search-result__header"> | ||
{type ? <span className="ep-search-result__type">{type}</span> : null} | ||
|
||
<h2 className="ep-search-result__title"> | ||
{/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
<a | ||
href={url} | ||
/* eslint-disable-next-line react/no-danger */ | ||
dangerouslySetInnerHTML={{ __html: title }} | ||
/> | ||
</h2> | ||
|
||
{priceHtml ? ( | ||
<p | ||
className="price" | ||
/* eslint-disable-next-line react/no-danger */ | ||
dangerouslySetInnerHTML={{ | ||
__html: priceHtml, | ||
}} | ||
/> | ||
) : null} | ||
</header> | ||
|
||
{excerpt.length > 0 ? ( | ||
<p | ||
className="ep-search-result__description" | ||
/* eslint-disable-next-line react/no-danger */ | ||
dangerouslySetInnerHTML={{ __html: excerpt }} | ||
/> | ||
) : null} | ||
|
||
<footer className="ep-search-result__footer"> | ||
{averageRating > 0 ? <StarRating rating={averageRating} /> : null} | ||
{date} | ||
</footer> | ||
</article> | ||
); | ||
}; | ||
|
||
/** | ||
* Filter the Result component. | ||
* | ||
* @filter ep.InstantResults.Result | ||
* @since 4.4.0 | ||
* | ||
* @param {React.Component|React.FunctionComponent} Result Result component. | ||
* @returns {React.Component|React.FunctionComponent} Result component. | ||
*/ | ||
export default applyFilters('ep.InstantResults.Result', Result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.