Blocks: Add rating to grid previews (https://github.com/woocommerce/woocommerce-blocks/pull/472)
* Add rating stars to the product preview * Add rating to the visibility controls
This commit is contained in:
parent
432925a090
commit
9fa9257430
|
@ -17,6 +17,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.is-hidden-rating {
|
||||||
|
.star-rating {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&.is-hidden-button {
|
&.is-hidden-button {
|
||||||
.button[data-product_sku] {
|
.button[data-product_sku] {
|
||||||
display: none !important;
|
display: none !important;
|
||||||
|
|
|
@ -179,6 +179,7 @@ class ProductsBlock extends Component {
|
||||||
'is-not-found': loaded && ! hasSelectedProducts,
|
'is-not-found': loaded && ! hasSelectedProducts,
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,7 @@ registerBlockType( 'woocommerce/handpicked-products', {
|
||||||
default: {
|
default: {
|
||||||
title: true,
|
title: true,
|
||||||
price: true,
|
price: true,
|
||||||
|
rating: true,
|
||||||
button: true,
|
button: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -101,6 +102,7 @@ registerBlockType( 'woocommerce/handpicked-products', {
|
||||||
{
|
{
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -131,6 +131,7 @@ class ProductBestSellersBlock extends Component {
|
||||||
'is-not-found': loaded && ! products.length,
|
'is-not-found': loaded && ! products.length,
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ registerBlockType( 'woocommerce/product-best-sellers', {
|
||||||
{
|
{
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -196,6 +196,7 @@ class ProductByCategoryBlock extends Component {
|
||||||
'is-not-found': loaded && ! products.length,
|
'is-not-found': loaded && ! products.length,
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,7 @@ registerBlockType( 'woocommerce/product-category', {
|
||||||
{
|
{
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -133,6 +133,7 @@ class ProductNewestBlock extends Component {
|
||||||
'is-not-found': loaded && ! products.length,
|
'is-not-found': loaded && ! products.length,
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ registerBlockType( 'woocommerce/product-new', {
|
||||||
{
|
{
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -145,6 +145,7 @@ class ProductOnSaleBlock extends Component {
|
||||||
'is-not-found': loaded && ! products.length,
|
'is-not-found': loaded && ! products.length,
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@ registerBlockType( 'woocommerce/product-on-sale', {
|
||||||
{
|
{
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -133,6 +133,7 @@ class ProductTopRatedBlock extends Component {
|
||||||
'is-not-found': loaded && ! products.length,
|
'is-not-found': loaded && ! products.length,
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ registerBlockType( 'woocommerce/product-top-rated', {
|
||||||
{
|
{
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -210,6 +210,7 @@ class ProductsByAttributeBlock extends Component {
|
||||||
'is-not-found': loaded && ! products.length,
|
'is-not-found': loaded && ! products.length,
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,7 @@ registerBlockType( 'woocommerce/products-by-attribute', {
|
||||||
default: {
|
default: {
|
||||||
title: true,
|
title: true,
|
||||||
price: true,
|
price: true,
|
||||||
|
rating: true,
|
||||||
button: true,
|
button: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -110,6 +111,7 @@ registerBlockType( 'woocommerce/products-by-attribute', {
|
||||||
{
|
{
|
||||||
'is-hidden-title': ! contentVisibility.title,
|
'is-hidden-title': ! contentVisibility.title,
|
||||||
'is-hidden-price': ! contentVisibility.price,
|
'is-hidden-price': ! contentVisibility.price,
|
||||||
|
'is-hidden-rating': ! contentVisibility.rating,
|
||||||
'is-hidden-button': ! contentVisibility.button,
|
'is-hidden-button': ! contentVisibility.button,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { ToggleControl } from '@wordpress/components';
|
||||||
* A combination of range controls for product grid layout settings.
|
* A combination of range controls for product grid layout settings.
|
||||||
*/
|
*/
|
||||||
const GridContentControl = ( { onChange, settings } ) => {
|
const GridContentControl = ( { onChange, settings } ) => {
|
||||||
const { button, price, title } = settings;
|
const { button, price, rating, title } = settings;
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<ToggleControl
|
<ToggleControl
|
||||||
|
@ -33,6 +33,16 @@ const GridContentControl = ( { onChange, settings } ) => {
|
||||||
checked={ price }
|
checked={ price }
|
||||||
onChange={ () => onChange( { ...settings, price: ! price } ) }
|
onChange={ () => onChange( { ...settings, price: ! price } ) }
|
||||||
/>
|
/>
|
||||||
|
<ToggleControl
|
||||||
|
label={ __( 'Product rating', 'woo-gutenberg-products-block' ) }
|
||||||
|
help={
|
||||||
|
rating ?
|
||||||
|
__( 'Product rating is visible.', 'woo-gutenberg-products-block' ) :
|
||||||
|
__( 'Product rating is hidden.', 'woo-gutenberg-products-block' )
|
||||||
|
}
|
||||||
|
checked={ rating }
|
||||||
|
onChange={ () => onChange( { ...settings, rating: ! rating } ) }
|
||||||
|
/>
|
||||||
<ToggleControl
|
<ToggleControl
|
||||||
label={ __( 'Add to Cart button', 'woo-gutenberg-products-block' ) }
|
label={ __( 'Add to Cart button', 'woo-gutenberg-products-block' ) }
|
||||||
help={
|
help={
|
||||||
|
|
|
@ -22,6 +22,12 @@ const ProductPreview = ( { product } ) => {
|
||||||
image = <img src={ placeholderImgSrc } alt="" />;
|
image = <img src={ placeholderImgSrc } alt="" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const rating = Number( product.average_rating );
|
||||||
|
let displayRating = false;
|
||||||
|
if ( rating > 0 ) {
|
||||||
|
displayRating = ( rating / 5 ) * 100;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="wc-product-preview">
|
<div className="wc-product-preview">
|
||||||
{ image }
|
{ image }
|
||||||
|
@ -33,6 +39,13 @@ const ProductPreview = ( { product } ) => {
|
||||||
className="wc-product-preview__price"
|
className="wc-product-preview__price"
|
||||||
dangerouslySetInnerHTML={ { __html: product.price_html } }
|
dangerouslySetInnerHTML={ { __html: product.price_html } }
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
{ displayRating && (
|
||||||
|
<div className="wc-product-preview__rating star-rating" role="img">
|
||||||
|
<span style={ { width: `${ displayRating }%` } } />
|
||||||
|
</div>
|
||||||
|
) }
|
||||||
|
|
||||||
<span className="wp-block-button">
|
<span className="wp-block-button">
|
||||||
<span className="wc-product-preview__add-to-cart wp-block-button__link">
|
<span className="wc-product-preview__add-to-cart wp-block-button__link">
|
||||||
{ __( 'Add to cart', 'woo-gutenberg-products-block' ) }
|
{ __( 'Add to cart', 'woo-gutenberg-products-block' ) }
|
||||||
|
|
|
@ -3,10 +3,50 @@
|
||||||
margin-bottom: $gap;
|
margin-bottom: $gap;
|
||||||
|
|
||||||
.wc-product-preview__title,
|
.wc-product-preview__title,
|
||||||
.wc-product-preview__price {
|
.wc-product-preview__price,
|
||||||
|
.wc-product-preview__rating {
|
||||||
margin-top: $gap-smallest;
|
margin-top: $gap-smallest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.star-rating {
|
||||||
|
overflow: hidden;
|
||||||
|
position: relative;
|
||||||
|
margin-left: auto;
|
||||||
|
margin-right: auto;
|
||||||
|
width: 5.3em;
|
||||||
|
height: 1.618em;
|
||||||
|
line-height: 1.618;
|
||||||
|
font-size: 1em;
|
||||||
|
font-family: star;
|
||||||
|
font-weight: 400;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: '\53\53\53\53\53';
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
position: absolute;
|
||||||
|
opacity: 0.25;
|
||||||
|
}
|
||||||
|
|
||||||
|
span {
|
||||||
|
overflow: hidden;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
position: absolute;
|
||||||
|
padding-top: 1.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
span::before {
|
||||||
|
content: '\53\53\53\53\53';
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.wp-block-button {
|
.wp-block-button {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
|
@ -44,6 +84,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.is-hidden-rating & {
|
||||||
|
.wc-product-preview__rating {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.is-hidden-button & {
|
.is-hidden-button & {
|
||||||
.wp-block-button {
|
.wp-block-button {
|
||||||
display: none;
|
display: none;
|
||||||
|
|
|
@ -48,6 +48,7 @@ export default {
|
||||||
default: {
|
default: {
|
||||||
title: true,
|
title: true,
|
||||||
price: true,
|
price: true,
|
||||||
|
rating: true,
|
||||||
button: true,
|
button: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue