Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
Rating Product block: add support for global style #4965
Browse files Browse the repository at this point in the history
Rating Product block: add support for global style
  • Loading branch information
gigitux committed Jan 5, 2022
1 parent c5c65b4 commit 70bb739
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
9 changes: 7 additions & 2 deletions assets/js/atomic/blocks/product-elements/rating/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { withProductDataContext } from '@woocommerce/shared-hocs';
* Internal dependencies
*/
import './style.scss';
import { useColorProps } from '../../../../utils/style-attributes-utils';

/**
* Product Rating Block Component.
Expand All @@ -22,10 +23,12 @@ import './style.scss';
* @param {string} [props.className] CSS Class name for the component.
* @return {*} The component.
*/
const Block = ( { className } ) => {
const Block = ( props ) => {
const { className } = props;
const { parentClassName } = useInnerBlockLayoutContext();
const { product } = useProductDataContext();
const rating = getAverageRating( product );
const colorProps = useColorProps( props );

if ( ! rating ) {
return null;
Expand Down Expand Up @@ -59,7 +62,9 @@ const Block = ( { className } ) => {
role="img"
aria-label={ ratingText }
>
<span style={ starStyle }>{ ratingText }</span>
<span style={ { ...starStyle, ...colorProps.style } }>
{ ratingText }
</span>
</div>
</div>
);
Expand Down
4 changes: 4 additions & 0 deletions assets/js/atomic/blocks/product-elements/rating/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ import {
BLOCK_ICON as icon,
BLOCK_DESCRIPTION as description,
} from './constants';
import { supports } from './support';
import { Save } from './save';

const blockConfig = {
title,
description,
icon: { src: icon },
attributes,
supports,
edit,
save: Save,
};

registerBlockType( 'woocommerce/product-rating', {
Expand Down
21 changes: 21 additions & 0 deletions assets/js/atomic/blocks/product-elements/rating/save.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* External dependencies
*/
import { useBlockProps } from '@wordpress/block-editor';
import classnames from 'classnames';

type Props = {
attributes: Record< string, unknown > & {
className?: string;
};
};

export const Save = ( { attributes }: Props ): JSX.Element => {
return (
<div
{ ...useBlockProps.save( {
className: classnames( 'is-loading', attributes.className ),
} ) }
/>
);
};
2 changes: 1 addition & 1 deletion assets/js/atomic/blocks/product-elements/rating/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
left: 0;
right: 0;
position: absolute;
color: #000;
color: inherit;
white-space: nowrap;
}
}
Expand Down
7 changes: 7 additions & 0 deletions assets/js/atomic/blocks/product-elements/rating/support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const supports = {
color: {
text: true,
background: false,
link: false,
},
};

0 comments on commit 70bb739

Please sign in to comment.