From a992c64917f26113d9858b082ca847912cd1ffe4 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 12 May 2023 13:42:16 +0100 Subject: [PATCH] Experiment: Replace style hooks coming from `@wordpress/block-editor` (#9251) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Replace all style hooks with useStyleProps hook * Remove border/color/spacing hooks * Style Props Hook * Make use of `change-case` package * Tidy up block wrappers * Attribute filter does not use frontend.ts nor styles within block * Remove frontend from filter blocks and unused styleprops usage * Tidy up variable names so its clearer attributes are not required specifically from blocks * Update assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-title-label-block/block.tsx Co-authored-by: Albert Juhé Lluveras * Update assets/js/blocks/attribute-filter/block-wrapper.tsx Co-authored-by: Albert Juhé Lluveras * Update assets/js/blocks/active-filters/block-wrapper.tsx Co-authored-by: Albert Juhé Lluveras * Update assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-checkout-button-block/block.tsx Co-authored-by: Tom Cafferkey * Update assets/js/blocks/rating-filter/block-wrapper.tsx Co-authored-by: Tom Cafferkey * Update assets/js/blocks/stock-filter/block-wrapper.tsx Co-authored-by: Tom Cafferkey * Update assets/js/blocks/price-filter/block-wrapper.tsx Co-authored-by: Tom Cafferkey * Update assets/js/blocks/mini-cart/mini-cart-contents/inner-blocks/mini-cart-cart-button-block/block.tsx Co-authored-by: Tom Cafferkey * Simplify styleprop * Styleprops simplify * Fix withFeaturedItem styles * Like the original hook, flatten props and combine with parsed styles --------- Co-authored-by: Albert Juhé Lluveras Co-authored-by: Tom Cafferkey --- .../blocks/product-elements/button/block.tsx | 80 +++------ .../blocks/product-elements/button/types.ts | 6 +- .../blocks/product-elements/image/block.tsx | 26 +-- .../image/test/block.test.tsx | 8 +- .../blocks/product-elements/price/block.tsx | 28 +-- .../blocks/product-elements/rating/block.tsx | 21 +-- .../product-elements/sale-badge/block.tsx | 23 +-- .../blocks/product-elements/sku/block.tsx | 21 +-- .../stock-indicator/block.tsx | 19 +- .../blocks/product-elements/summary/block.tsx | 12 +- .../blocks/product-elements/title/block.tsx | 36 +--- .../base/components/product-price/index.tsx | 6 +- assets/js/base/hooks/index.js | 4 +- assets/js/base/hooks/use-border-props.ts | 26 --- assets/js/base/hooks/use-color-props.ts | 24 --- assets/js/base/hooks/use-spacing-props.ts | 29 ---- assets/js/base/hooks/use-style-props.ts | 74 ++++++++ assets/js/base/hooks/use-typography-props.ts | 24 +-- assets/js/base/utils/get-inline-styles.ts | 163 ++++++++++++++++++ assets/js/base/utils/index.js | 1 + .../blocks/active-filters/block-wrapper.tsx | 15 +- .../blocks/attribute-filter/block-wrapper.tsx | 15 +- assets/js/blocks/attribute-filter/block.tsx | 11 +- assets/js/blocks/attribute-filter/frontend.ts | 23 --- .../featured-items/with-featured-item.tsx | 25 +-- .../mini-cart-cart-button-block/block.tsx | 8 +- .../mini-cart-cart-button-block/edit.tsx | 1 + .../mini-cart-checkout-button-block/block.tsx | 8 +- .../block.tsx | 22 +-- .../mini-cart-title-label-block/block.tsx | 24 +-- .../js/blocks/price-filter/block-wrapper.tsx | 15 +- assets/js/blocks/price-filter/frontend.ts | 23 --- .../js/blocks/rating-filter/block-wrapper.tsx | 15 +- assets/js/blocks/rating-filter/block.tsx | 11 +- .../js/blocks/stock-filter/block-wrapper.tsx | 15 +- assets/js/blocks/stock-filter/block.tsx | 11 +- assets/js/blocks/stock-filter/frontend.ts | 23 --- package-lock.json | 49 +++++- package.json | 1 + src/BlockTypes/AttributeFilter.php | 9 + src/BlockTypes/RatingFilter.php | 8 + src/BlockTypes/StockFilter.php | 9 + 42 files changed, 471 insertions(+), 501 deletions(-) delete mode 100644 assets/js/base/hooks/use-border-props.ts delete mode 100644 assets/js/base/hooks/use-color-props.ts delete mode 100644 assets/js/base/hooks/use-spacing-props.ts create mode 100644 assets/js/base/hooks/use-style-props.ts create mode 100644 assets/js/base/utils/get-inline-styles.ts delete mode 100644 assets/js/blocks/attribute-filter/frontend.ts delete mode 100644 assets/js/blocks/price-filter/frontend.ts delete mode 100644 assets/js/blocks/stock-filter/frontend.ts diff --git a/assets/js/atomic/blocks/product-elements/button/block.tsx b/assets/js/atomic/blocks/product-elements/button/block.tsx index ddab78646fe..c3ed224b08f 100644 --- a/assets/js/atomic/blocks/product-elements/button/block.tsx +++ b/assets/js/atomic/blocks/product-elements/button/block.tsx @@ -7,12 +7,7 @@ import { useStoreEvents, useStoreAddToCart, } from '@woocommerce/base-context/hooks'; -import { - useBorderProps, - useColorProps, - useTypographyProps, - useSpacingProps, -} from '@woocommerce/base-hooks'; +import { useStyleProps } from '@woocommerce/base-hooks'; import { decodeEntities } from '@wordpress/html-entities'; import { CART_URL } from '@woocommerce/block-settings'; import { getSetting } from '@woocommerce/settings'; @@ -35,22 +30,18 @@ import type { /** * Product Button Block Component. * - * @param {Object} props Incoming props. - * @param {Object} [props.product] Product. - * @param {Object} [props.colorStyles] Object contains CSS class and CSS style for color. - * @param {Object} [props.borderStyles] Object contains CSS class and CSS style for border. - * @param {Object} [props.typographyStyles] Object contains CSS class and CSS style for typography. - * @param {Object} [props.spacingStyles] Object contains CSS style for spacing. - * @param {Object} [props.textAlign] Text alignment. + * @param {Object} props Incoming props. + * @param {Object} [props.product] Product. + * @param {Object} [props.style] Object contains CSS Styles. + * @param {string} [props.className] String contains CSS class. + * @param {Object} [props.textAlign] Text alignment. * * @return {*} The component. */ const AddToCartButton = ( { product, - colorStyles, - borderStyles, - typographyStyles, - spacingStyles, + className, + style, textAlign, }: AddToCartButtonAttributes ): JSX.Element => { const { @@ -114,14 +105,15 @@ const AddToCartButton = ( { return ( { buttonText } @@ -147,19 +132,15 @@ const AddToCartButton = ( { /** * Product Button Block Component. * - * @param {Object} props Incoming props. - * @param {Object} [props.colorStyles] Object contains CSS class and CSS style for color. - * @param {Object} [props.borderStyles] Object contains CSS class and CSS style for border. - * @param {Object} [props.typographyStyles] Object contains CSS class and CSS style for typography. - * @param {Object} [props.spacingStyles] Object contains CSS style for spacing. + * @param {Object} props Incoming props. + * @param {Object} [props.style] Object contains CSS Styles. + * @param {string} [props.className] String contains CSS class. * * @return {*} The component. */ const AddToCartButtonPlaceholder = ( { - colorStyles, - borderStyles, - typographyStyles, - spacingStyles, + className, + style, }: AddToCartButtonPlaceholderAttributes ): JSX.Element => { return (