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

Product Ratings: Add Global Styles font size and spacing support #5927

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions assets/js/atomic/blocks/product-elements/rating/block.js
Expand Up @@ -14,7 +14,11 @@ import { withProductDataContext } from '@woocommerce/shared-hocs';
* Internal dependencies
*/
import './style.scss';
import { useColorProps } from '../../../../hooks/style-attributes';
import {
useColorProps,
useSpacingProps,
useTypographyProps,
} from '../../../../hooks/style-attributes';

/**
* Product Rating Block Component.
Expand All @@ -24,11 +28,12 @@ import { useColorProps } from '../../../../hooks/style-attributes';
* @return {*} The component.
*/
const Block = ( props ) => {
const { className } = props;
const { parentClassName } = useInnerBlockLayoutContext();
const { product } = useProductDataContext();
const rating = getAverageRating( product );
const colorProps = useColorProps( props );
const typographyProps = useTypographyProps( props );
const spacingProps = useSpacingProps( props );

if ( ! rating ) {
return null;
Expand Down Expand Up @@ -62,14 +67,17 @@ const Block = ( props ) => {
return (
<div
className={ classnames(
className,
colorProps.className,
'wc-block-components-product-rating',
{
[ `${ parentClassName }__product-rating` ]: parentClassName,
}
) }
style={ colorProps.style }
style={ {
...colorProps.style,
...typographyProps.style,
...spacingProps.style,
} }
>
<div
className={ classnames(
Expand Down
1 change: 1 addition & 0 deletions assets/js/atomic/blocks/product-elements/rating/index.js
Expand Up @@ -18,6 +18,7 @@ import { supports } from './support';
import { Save } from './save';

const blockConfig = {
apiVersion: 2,
title,
description,
icon: { src: icon },
Expand Down
17 changes: 17 additions & 0 deletions assets/js/atomic/blocks/product-elements/rating/support.js
Expand Up @@ -3,12 +3,29 @@
*/
import { isFeaturePluginBuild } from '@woocommerce/block-settings';

/**
* Internal dependencies
*/
import { hasSpacingStyleSupport } from '../../../../utils/global-style';

export const supports = {
...( isFeaturePluginBuild() && {
color: {
text: true,
background: false,
link: false,
__experimentalSkipSerialization: true,
},
typography: {
fontSize: true,
__experimentalSkipSerialization: true,
},
...( hasSpacingStyleSupport() && {
spacing: {
margin: true,
__experimentalSkipSerialization: true,
},
} ),
__experimentalSelector: '.wc-block-components-product-rating',
} ),
};
17 changes: 14 additions & 3 deletions src/BlockTypes/ProductRating.php
Expand Up @@ -30,9 +30,20 @@ protected function get_block_type_supports() {
return array(
'color' =>
array(
'text' => true,
'background' => false,
'link' => false,
'text' => true,
'background' => false,
'link' => false,
'__experimentalSkipSerialization' => true,
),
'typography' =>
array(
'fontSize' => true,
'__experimentalSkipSerialization' => true,
),
'spacing' =>
array(
'margin' => true,
'__experimentalSkipSerialization' => true,
),
'__experimentalSelector' => '.wc-block-components-product-rating',
);
Expand Down