/** * External dependencies */ import { __ } from '@wordpress/i18n'; import PropTypes from 'prop-types'; import { PLACEHOLDER_IMG_SRC, THUMBNAIL_SIZE } from '@woocommerce/settings'; /** * Internal dependencies */ import './style.scss'; /** * Display a preview for a given product. */ const ProductPreview = ( { product } ) => { let image = null; if ( product.images.length ) { image = ( ); } else { image = ( ); } const rating = Number( product.average_rating ); let displayRating = false; if ( rating > 0 ) { displayRating = ( rating / 5 ) * 100; } return (
{ image }
{ displayRating && (
) } { __( 'Add to cart', 'woo-gutenberg-products-block' ) }
); }; ProductPreview.propTypes = { /** * The product object as returned from the API. */ product: PropTypes.shape( { id: PropTypes.number, average_rating: PropTypes.oneOf( [ 'PropTypes.number', 'PropTypes.string' ] ), images: PropTypes.array, name: PropTypes.string, price_html: PropTypes.string, } ).isRequired, }; export default ProductPreview;