2018-07-23 13:19:24 +00:00
|
|
|
/** @format */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-08-20 21:18:13 +00:00
|
|
|
import Rating from './index';
|
2018-07-23 13:19:24 +00:00
|
|
|
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* Display a set of stars representing the product's average rating.
|
|
|
|
*
|
|
|
|
* @return { object } -
|
|
|
|
*/
|
2018-08-20 21:18:13 +00:00
|
|
|
const ProductRating = ( { product, ...props } ) => {
|
|
|
|
const rating = ( product && product.average_rating ) || 0;
|
|
|
|
return <Rating rating={ rating } { ...props } />;
|
|
|
|
};
|
2018-07-23 13:19:24 +00:00
|
|
|
|
|
|
|
ProductRating.propTypes = {
|
2018-08-31 17:27:21 +00:00
|
|
|
/**
|
|
|
|
* A product object containing a `average_rating`.
|
|
|
|
* See https://woocommerce.github.io/woocommerce-rest-api-docs/#products.
|
|
|
|
*/
|
2018-07-23 13:19:24 +00:00
|
|
|
product: PropTypes.object.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ProductRating;
|