This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Products by Rating filter block (#7048)
* Add interactivity to the Product by Rating filter block * Fix block with the latest repo changes * Product by Rating: Code tidying up * Add an experimental build gate and update block title and description * Remove redundant title and description * Add support for the CheckboxList component in the Products by Rating block * Products by Rating: Minor code clean-up * Active Filters: Fix the Clear All button for Ratings. Closes ##7172 * Products by Rating: Add misc TS fixes
- Loading branch information
1 parent
d64873e
commit e044fe6
Showing
18 changed files
with
604 additions
and
2 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
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,64 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classNames from 'classnames'; | ||
import { __, sprintf } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import './style.scss'; | ||
|
||
const Rating = ( { | ||
className, | ||
key, | ||
rating, | ||
ratedProductsCount, | ||
}: RatingProps ): JSX.Element => { | ||
const ratingClassName = classNames( | ||
'wc-block-components-product-rating', | ||
className | ||
); | ||
|
||
const starStyle = { | ||
width: ( rating / 5 ) * 100 + '%', | ||
}; | ||
|
||
const ratingText = sprintf( | ||
/* translators: %f is referring to the average rating value */ | ||
__( 'Rated %f out of 5', 'woo-gutenberg-products-block' ), | ||
rating | ||
); | ||
|
||
const ratingHTML = { | ||
__html: sprintf( | ||
/* translators: %f is referring to the rating value */ | ||
__( 'Rated %f out of 5', 'woo-gutenberg-products-block' ), | ||
sprintf( '<strong class="rating">%f</strong>', rating ) | ||
), | ||
}; | ||
|
||
return ( | ||
<div className={ ratingClassName } key={ key }> | ||
<div | ||
className={ 'wc-block-components-product-rating__stars' } | ||
role="img" | ||
aria-label={ ratingText } | ||
> | ||
<span | ||
style={ starStyle } | ||
dangerouslySetInnerHTML={ ratingHTML } | ||
/> | ||
</div> | ||
{ ratedProductsCount ? `(${ ratedProductsCount })` : null } | ||
</div> | ||
); | ||
}; | ||
interface RatingProps { | ||
className: string; | ||
key: 0 | 1 | 2 | 3 | 4 | 5; | ||
rating: 0 | 1 | 2 | 3 | 4 | 5; | ||
ratedProductsCount: number; | ||
} | ||
|
||
export default Rating; |
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,7 @@ | ||
.wc-block-components-product-rating { | ||
&__stars { | ||
display: inline-block; | ||
line-height: 1; | ||
height: 1em; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
export const blockAttributes = { | ||
heading: { | ||
type: 'string', | ||
default: __( 'Filter by rating', 'woo-gutenberg-products-block' ), | ||
}, | ||
}; |
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,34 @@ | ||
{ | ||
"name": "woocommerce/rating-filter", | ||
"version": "1.0.0", | ||
"title": "Filter by Rating", | ||
"description": "Enable customers to filter the product grid by rating.", | ||
"category": "woocommerce", | ||
"keywords": [ "WooCommerce" ], | ||
"supports": { | ||
"html": false, | ||
"multiple": false | ||
}, | ||
"example": { | ||
"attributes": { | ||
"isPreview": true | ||
} | ||
}, | ||
"attributes": { | ||
"className": { | ||
"type": "string", | ||
"default": "" | ||
}, | ||
"headingLevel": { | ||
"type": "number", | ||
"default": 3 | ||
}, | ||
"isPreview": { | ||
"type": "boolean", | ||
"default": false | ||
} | ||
}, | ||
"textdomain": "woo-gutenberg-products-block", | ||
"apiVersion": 2, | ||
"$schema": "https://schemas.wp.org/trunk/block.json" | ||
} |
Oops, something went wrong.