From f2dad05e0dae20b7004d9e1033aaf8addc870eaf Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Mon, 14 Feb 2022 11:29:17 +0100 Subject: [PATCH] Category List block: add support for global style (https://github.com/woocommerce/woocommerce-blocks/pull/5516) * Product title: add support global style woocommerce/woocommerce-blocks#4965 * add specific type * Enable global style for category list block woocommerce/woocommerce-blocks#4965 Enable global style for category list block * fix import after merge * add save function * add feature flag --- .../product-elements/category-list/block.tsx | 12 ++++++++++- .../product-elements/category-list/edit.tsx | 7 +++++-- .../product-elements/category-list/index.ts | 20 +++++++++++++++++- .../product-elements/category-list/save.tsx | 21 +++++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/category-list/save.tsx diff --git a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/category-list/block.tsx b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/category-list/block.tsx index 59a4dd628fe..3fc4bbe8c44 100644 --- a/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/category-list/block.tsx +++ b/plugins/woocommerce-blocks/assets/js/atomic/blocks/product-elements/category-list/block.tsx @@ -16,6 +16,10 @@ import { HTMLAttributes } from 'react'; */ import './style.scss'; import { Attributes } from './types'; +import { + useColorProps, + useTypographyProps, +} from '../../../../hooks/style-attributes'; type Props = Attributes & HTMLAttributes< HTMLDivElement >; @@ -26,10 +30,14 @@ type Props = Attributes & HTMLAttributes< HTMLDivElement >; * @param {string} [props.className] CSS Class name for the component. * @return {*} The component. */ -const Block = ( { className }: Props ): JSX.Element | null => { +const Block = ( props: Props ): JSX.Element | null => { + const { className } = props; const { parentClassName } = useInnerBlockLayoutContext(); const { product } = useProductDataContext(); + const colorProps = useColorProps( props ); + const typographyProps = useTypographyProps( props ); + if ( isEmpty( product.categories ) ) { return null; } @@ -39,10 +47,12 @@ const Block = ( { className }: Props ): JSX.Element | null => { className={ classnames( className, 'wc-block-components-product-category-list', + colorProps.className, { [ `${ parentClassName }__product-category-list` ]: parentClassName, } ) } + style={ { ...colorProps.style, ...typographyProps.style } } > { __( 'Categories:', 'woo-gutenberg-products-block' ) }{ ' ' }