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

Add Color Panel #10062

Merged
merged 20 commits into from
Jul 21, 2023
Merged

Add Color Panel #10062

merged 20 commits into from
Jul 21, 2023

Conversation

nerrad
Copy link
Contributor

@nerrad nerrad commented Jun 30, 2023

Fixes #10030

In this PR I created a new ColorPanel component for implementing custom GB color panels in any blocks where we want to have full control over the labels and named custom colors. As a part of the PR I replaced the color panel implementation in the Mini-Cart block to demonstrate its functionality.

It still could use some more work but I ran out of time before heading away for a few weeks so am publishing this PR as a handoff.

What is complete

  • ColorPanel component supporting custom named colors (but not gradients).

You can implement the component by doing something like this (simplified JS example for now, you can see the TS implementation in the Mini-Cart block code):

import { ColorPanel } from "@woocommerce/editor-components/color-panel";
import { SomeBlock } from "../some-block";

const defaultColorItem = {
  name: undefined,
  color: undefined,
  slug: undefined,
};

export const MyBlock = ({ attributes }) => {
  // The ColorPanel will take care of setting the appropriate
  // attribute values for colorA and colorB when user selections
  // are made. However, you'll want to set a default to save having
  // to check for the existing of the object properties in your implementation.
  const { colorA = defaultColorItem, colorB = defaultColorItem } = attributes;

  // ...other block stuff

  // This is the configuration for the panel.
  // The keys will be exposed as attribute keys.
  // `label` is self-explanatory.
  // `context` is whatever you want to use to describe the context of the color.
  // It is used to generate `has-<context>-color-slug` classes.
  const colorAttributes = {
    colorA: {
      label: __("Color A", "plugin-domain"),
      context: "foreground",
    },
    colorB: {
      label: __("Color B", "plugin-domain"),
      context: "background",
    },
  };
  // Note, each constructed custom color attribute has three properties. So for
  // instance, on the `colorA` attribute, you'll have:
  // - color: a string representing the color value
  // - slug: a string representing the slug of the color. This could be undefined.
  // - class: a generated classname {has-<slug>-<context>} ... however if there
  //   is no slug, this will be undefined.
  return (
    <>
      <ColorPanel colorTypes={colorAttributes} />
      <SomeBlock style={{ color: colorA.color }} className={colorA.class} />
    </>
  );
};
  • Implemented in Mini-Cart block (both frontend and backend).

What needs done

  • Review the code - could be opportunities for cleaning up.
  • I didn't implement the class property on the constructed colors and that may be something we'll want to tweak anyways. So should be reviewed.
  • The types need to be organized better and exposed in a way that can be used in frontend facing code (if necessary).
  • Test throughly. I did my own testing of course, but I didn't cover all the bases around what happens for existing mini-block users etc.
  • Fix failing tests. Likely just need to be updated from the changes in the block.
  • I didn't add any automated tests or hook this up for Storybook.
  • Definitely a separate issue, but the lack of types for @wordpress/block-editor and other WP core packages is pretty annoying and mostly due to our dev configuration for the packages being so out of date version wise. I suspect they haven't been fully updated yet because of the React 18 dependency change but it'd be good to try and get that done at some point.

Nice to haves for future

  • At some point we'll want to support gradients with this panel. I left it out of the initial iteration because I don't think we have any clear need for it yet.
  • I thought it'd be handy to do a useColorPanelStyles hook which would receive the same configuration object and spit out the relevant classnames that could be used for those colors. It'd reduce a lot of the boilerplate and make implementing the classes vs styles for the colors simpler.
  • The accessible colors checker would be nice to implement, but would need some additional thought around configuration because knowing which color pairings to compare for accessibility really can't be derived.

Accessibility

This is re-using WP core components so accessibility is tied to their functionality.

Other Checks

  • This PR adds/removes a feature flag & I've updated this doc.
  • This PR adds/removes an experimental interfaces and I've updated this doc.
  • I tagged two reviewers because this PR makes queries to the database or I think it might have some security impact.

Testing

Automated Tests

  • Changes in this PR are covered by Automated Tests.
    • Unit tests
    • E2E tests

User Facing Testing

This testing is utilizing the implementation in the Mini-Cart block to verify functionality

  1. Ensure you are running WP 6.3 and/or the latest Gutenberg installed
  2. Insert the Mini-Cart Block into a template.
  3. Select the block, in the settings panel for the block, turn on the "Display total price" toggle so you're able to see the color changes.
  4. Select the "Styles" panel.
  5. Set custom colors for the Icon, Price, and Product count color options. Verify they are changed in the Mini-Cart block.
  6. Save the template and then view on the frontend. Verify the Mini-Cart block has retained the custom colors.
  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Performance Impact

Changelog

Added a new ColorPanel component and implemented in the Mini-Cart block for custom color controls.

@nerrad nerrad self-assigned this Jun 30, 2023
@nerrad nerrad added type: enhancement The issue is a request for an enhancement. focus: components Work that introduces new or updates existing components. block: mini-cart Issues related to the Mini-Cart block. labels Jun 30, 2023
@nerrad nerrad requested a review from Aljullu June 30, 2023 19:23
@github-actions
Copy link
Contributor

github-actions bot commented Jun 30, 2023

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-10062.zip

Script Dependencies Report

There is no changed script dependency between this branch and trunk.

This comment was automatically generated by the ./github/compare-assets action.

TypeScript Errors Report

  • Files with errors: 470
  • Total errors: 2246

⚠️ ⚠️ This PR introduces new TS errors on 2 files:

assets/js/blocks/mini-cart/utils/test/data.ts

assets/js/editor-components/color-panel/index.tsx

comments-aggregator

@nerrad
Copy link
Contributor Author

nerrad commented Jun 30, 2023

@Aljullu - I assigned this to you for review just so it doesn't escape notice. However, feel free to reassign to someone else on the team fitting with in progress work.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 30, 2023

Size Change: +305 B (0%)

Total Size: 1.36 MB

Filename Size Change
build/active-filters-wrapper--mini-cart-contents-block/cart-button--mini-cart-contents-block/checkout-but--e791dc6c-style.js 957 B -1 B (0%)
build/active-filters.js 7.59 kB -2 B (0%)
build/all-products.js 41.8 kB -6 B (0%)
build/attribute-filter.js 13.3 kB -2 B (0%)
build/cart-blocks/cart-cross-sells-products-style.js 137 B -1 B (-1%)
build/cart-blocks/cart-express-payment-style.js 136 B -1 B (-1%)
build/cart-blocks/cart-items-style.js 229 B +1 B (0%)
build/cart-blocks/cart-order-summary-style.js 322 B +1 B (0%)
build/cart-blocks/order-summary-coupon-form-style.js 137 B +1 B (+1%)
build/cart-blocks/order-summary-subtotal-style.js 136 B -1 B (-1%)
build/cart-blocks/proceed-to-checkout-style.js 1.09 kB +1 B (0%)
build/cart.js 45.2 kB +8 B (0%)
build/checkout-blocks/actions-style.js 685 B +1 B (0%)
build/checkout-blocks/contact-information-style.js 608 B -2 B (0%)
build/checkout-blocks/order-summary-cart-items-style.js 136 B -1 B (-1%)
build/checkout-blocks/order-summary-coupon-form-style.js 137 B +1 B (+1%)
build/checkout-blocks/order-summary-style.js 320 B -1 B (0%)
build/checkout-blocks/order-summary-taxes-style.js 177 B +1 B (+1%)
build/checkout-blocks/payment-style.js 461 B -1 B (0%)
build/checkout-blocks/pickup-options-style.js 443 B -1 B (0%)
build/checkout-blocks/shipping-address-style.js 475 B -1 B (0%)
build/checkout-blocks/shipping-method-style.js 1.37 kB -2 B (0%)
build/checkout-blocks/shipping-methods-style.js 417 B -1 B (0%)
build/checkout-blocks/terms-style.js 677 B +1 B (0%)
build/checkout-blocks/totals-style.js 285 B +1 B (0%)
build/checkout.js 47.8 kB +5 B (0%)
build/customer-account.js 3.19 kB -1 B (0%)
build/featured-category.js 15.1 kB +7 B (0%)
build/featured-product.js 15.3 kB +4 B (0%)
build/handpicked-products.js 8.11 kB +4 B (0%)
build/legacy-template.js 8.93 kB -6 B (0%)
build/mini-cart-component-frontend.js 30.9 kB +38 B (0%)
build/mini-cart-contents-block/cart-button--mini-cart-contents-block/checkout-button--mini-cart-contents---358acf4e-style.js 293 B -1 B (0%)
build/mini-cart-contents-block/cart-button-style.js 388 B +1 B (0%)
build/mini-cart-contents-block/empty-cart-style.js 358 B -2 B (-1%)
build/mini-cart-contents-block/items-style.js 237 B -1 B (0%)
build/mini-cart-contents-block/products-table-style.js 5.45 kB -2 B (0%)
build/mini-cart-contents-block/shopping-button-style.js 403 B -1 B (0%)
build/mini-cart-contents-block/title-items-counter-style.js 302 B +1 B (0%)
build/mini-cart-contents-block/title-label-style.js 301 B +1 B (0%)
build/mini-cart-contents-block/title-style.js 445 B +3 B (+1%)
build/mini-cart-contents.js 17.9 kB +2 B (0%)
build/mini-cart.js 6.37 kB +274 B (+4%)
build/price-filter.js 8.58 kB -2 B (0%)
build/product-best-sellers.js 8.45 kB +1 B (0%)
build/product-category.js 9.47 kB +1 B (0%)
build/product-collection.js 13.9 kB -1 B (0%)
build/product-price.js 1.67 kB -1 B (0%)
build/product-query.js 12.9 kB -6 B (0%)
build/rating-filter.js 6.94 kB -2 B (0%)
build/reviews-by-product.js 13.4 kB -2 B (0%)
build/single-product.js 11.3 kB +3 B (0%)
build/stock-filter.js 7.64 kB -2 B (0%)
build/vendors--active-filters-wrapper--attribute-filter-wrapper--mini-cart-contents-block/cart-button--mi--d6bb29e6-style.js 606 B +2 B (0%)
build/vendors--cart-blocks/proceed-to-checkout-style.js 179 B +1 B (+1%)
build/wc-blocks-vendors.js 65.5 kB -6 B (0%)
ℹ️ View Unchanged
Filename Size
build/active-filters-frontend.js 8.7 kB
build/active-filters-rtl.css 2.02 kB
build/active-filters-wrapper-frontend.js 7.64 kB
build/active-filters-wrapper-rtl.css 1.88 kB
build/active-filters-wrapper.css 1.88 kB
build/active-filters.css 2.02 kB
build/add-to-cart-form-rtl.css 380 B
build/add-to-cart-form.css 378 B
build/all-products-frontend.js 10.1 kB
build/all-products-rtl.css 4.24 kB
build/all-products.css 4.24 kB
build/all-reviews-rtl.css 1.84 kB
build/all-reviews.css 1.84 kB
build/all-reviews.js 7.87 kB
build/attribute-filter-frontend.js 23 kB
build/attribute-filter-rtl.css 4.19 kB
build/attribute-filter-wrapper-frontend.js 7.71 kB
build/attribute-filter-wrapper-rtl.css 4.06 kB
build/attribute-filter-wrapper.css 4.06 kB
build/attribute-filter.css 4.19 kB
build/blocks-checkout.js 35.1 kB
build/breadcrumbs-rtl.css 253 B
build/breadcrumbs.css 253 B
build/breadcrumbs.js 2.14 kB
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.38 kB
build/cart-blocks/cart-accepted-payment-methods-style.js 137 B
build/cart-blocks/cart-cross-sells-frontend.js 253 B
build/cart-blocks/cart-cross-sells-products--product-price-frontend.js 2.91 kB
build/cart-blocks/cart-cross-sells-products-frontend.js 3.83 kB
build/cart-blocks/cart-cross-sells-style.js 253 B
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.17 kB
build/cart-blocks/cart-express-payment-frontend.js 719 B
build/cart-blocks/cart-items-frontend.js 301 B
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.47 kB
build/cart-blocks/cart-line-items-frontend.js 1.06 kB
build/cart-blocks/cart-line-items-style.js 137 B
build/cart-blocks/cart-order-summary-frontend.js 1.28 kB
build/cart-blocks/cart-totals-frontend.js 307 B
build/cart-blocks/cart-totals-style.js 238 B
build/cart-blocks/empty-cart-frontend.js 347 B
build/cart-blocks/empty-cart-style.js 339 B
build/cart-blocks/filled-cart-frontend.js 655 B
build/cart-blocks/filled-cart-style.js 313 B
build/cart-blocks/order-summary-coupon-form-frontend.js 1.63 kB
build/cart-blocks/order-summary-discount-frontend.js 2.12 kB
build/cart-blocks/order-summary-discount-style.js 136 B
build/cart-blocks/order-summary-fee-frontend.js 272 B
build/cart-blocks/order-summary-fee-style.js 137 B
build/cart-blocks/order-summary-heading-frontend.js 333 B
build/cart-blocks/order-summary-heading-style.js 335 B
build/cart-blocks/order-summary-shipping-frontend.js 17 kB
build/cart-blocks/order-summary-shipping-style.js 178 B
build/cart-blocks/order-summary-subtotal-frontend.js 273 B
build/cart-blocks/order-summary-taxes-frontend.js 434 B
build/cart-blocks/order-summary-taxes-style.js 177 B
build/cart-blocks/proceed-to-checkout-frontend.js 1.43 kB
build/cart-frontend.js 29.9 kB
build/cart-rtl.css 9.59 kB
build/cart.css 9.58 kB
build/catalog-sorting-rtl.css 277 B
build/catalog-sorting.css 276 B
build/catalog-sorting.js 1.71 kB
build/checkout-blocks/actions--checkout-blocks/terms-style.js 485 B
build/checkout-blocks/actions-frontend.js 1.88 kB
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.7 kB
build/checkout-blocks/billing-address-frontend.js 1.18 kB
build/checkout-blocks/billing-address-style.js 532 B
build/checkout-blocks/contact-information-frontend.js 2.04 kB
build/checkout-blocks/express-payment-frontend.js 1.13 kB
build/checkout-blocks/fields-frontend.js 318 B
build/checkout-blocks/fields-style.js 260 B
build/checkout-blocks/order-note-frontend.js 1.13 kB
build/checkout-blocks/order-summary-cart-items-frontend.js 3.75 kB
build/checkout-blocks/order-summary-coupon-form-frontend.js 1.79 kB
build/checkout-blocks/order-summary-discount-frontend.js 2.29 kB
build/checkout-blocks/order-summary-discount-style.js 137 B
build/checkout-blocks/order-summary-fee-frontend.js 275 B
build/checkout-blocks/order-summary-fee-style.js 137 B
build/checkout-blocks/order-summary-frontend.js 1.28 kB
build/checkout-blocks/order-summary-shipping-frontend.js 17 kB
build/checkout-blocks/order-summary-shipping-style.js 137 B
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-subtotal-style.js 137 B
build/checkout-blocks/order-summary-taxes-frontend.js 435 B
build/checkout-blocks/payment-frontend.js 9.28 kB
build/checkout-blocks/pickup-options-frontend.js 4.84 kB
build/checkout-blocks/shipping-address-frontend.js 1.18 kB
build/checkout-blocks/shipping-method-frontend.js 2.62 kB
build/checkout-blocks/shipping-methods-frontend.js 6.41 kB
build/checkout-blocks/terms-frontend.js 1.55 kB
build/checkout-blocks/totals-frontend.js 347 B
build/checkout-frontend.js 31.8 kB
build/checkout-rtl.css 9.22 kB
build/checkout.css 9.21 kB
build/customer-account-rtl.css 406 B
build/customer-account.css 406 B
build/featured-category-rtl.css 986 B
build/featured-category.css 987 B
build/featured-product-rtl.css 1.03 kB
build/featured-product.css 1.03 kB
build/filter-wrapper-frontend.js 14.3 kB
build/filter-wrapper-rtl.css 399 B
build/filter-wrapper.css 397 B
build/filter-wrapper.js 2.4 kB
build/legacy-template-rtl.css 258 B
build/legacy-template.css 257 B
build/mini-cart-contents-block/cart-button-frontend.js 1.73 kB
build/mini-cart-contents-block/checkout-button-frontend.js 1.81 kB
build/mini-cart-contents-block/checkout-button-style.js 470 B
build/mini-cart-contents-block/empty-cart-frontend.js 360 B
build/mini-cart-contents-block/filled-cart-frontend.js 267 B
build/mini-cart-contents-block/filled-cart-style.js 268 B
build/mini-cart-contents-block/footer-frontend.js 3.83 kB
build/mini-cart-contents-block/footer-rtl.css 419 B
build/mini-cart-contents-block/footer-style.js 2.4 kB
build/mini-cart-contents-block/footer.css 418 B
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart-contents-block/products-table--product-image--product-title-style.js 352 B
build/mini-cart-contents-block/products-table-frontend.js 582 B
build/mini-cart-contents-block/products-table-rtl.css 2.19 kB
build/mini-cart-contents-block/products-table.css 2.18 kB
build/mini-cart-contents-block/shopping-button-frontend.js 538 B
build/mini-cart-contents-block/title-frontend.js 1.9 kB
build/mini-cart-contents-block/title-items-counter-frontend.js 1.59 kB
build/mini-cart-contents-block/title-label-frontend.js 1.53 kB
build/mini-cart-contents-rtl.css 2.73 kB
build/mini-cart-contents.css 2.73 kB
build/mini-cart-frontend.js 2.85 kB
build/mini-cart-rtl.css 2.61 kB
build/mini-cart.css 2.61 kB
build/packages-style-rtl.css 3.59 kB
build/packages-style.css 3.59 kB
build/price-filter-frontend.js 14.6 kB
build/price-filter-rtl.css 2.71 kB
build/price-filter-wrapper-frontend.js 6.75 kB
build/price-filter-wrapper-rtl.css 2.56 kB
build/price-filter-wrapper.css 2.56 kB
build/price-filter.css 2.7 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-average-rating--product-button--product-image--product-price--product---1d132d69.js 272 B
build/product-add-to-cart--product-button--product-rating--product-rating-counter--product-rating-stars.js 151 B
build/product-add-to-cart--product-image--product-title.js 351 B
build/product-add-to-cart-frontend.js 8.67 kB
build/product-add-to-cart-rtl.css 1.39 kB
build/product-add-to-cart.css 1.4 kB
build/product-add-to-cart.js 8.71 kB
build/product-average-rating--product-button--product-image--product-price--product-rating--product-ratin--e23975b5.js 954 B
build/product-average-rating-frontend.js 1.72 kB
build/product-average-rating.js 397 B
build/product-button-frontend.js 4.96 kB
build/product-button-rtl.css 889 B
build/product-button.css 891 B
build/product-button.js 3.95 kB
build/product-categories-rtl.css 671 B
build/product-categories.css 670 B
build/product-categories.js 2.71 kB
build/product-details-rtl.css 413 B
build/product-details.css 410 B
build/product-gallery-large-image-rtl.css 314 B
build/product-gallery-large-image.css 313 B
build/product-gallery-large-image.js 2.01 kB
build/product-gallery.js 2.3 kB
build/product-image-frontend.js 2.72 kB
build/product-image-gallery-rtl.css 322 B
build/product-image-gallery.css 322 B
build/product-image-rtl.css 951 B
build/product-image.css 949 B
build/product-image.js 1.57 kB
build/product-new.js 8.75 kB
build/product-on-sale.js 8.76 kB
build/product-price-frontend.js 248 B
build/product-price-rtl.css 696 B
build/product-price.css 695 B
build/product-query-rtl.css 367 B
build/product-query.css 365 B
build/product-rating-counter-frontend.js 2.03 kB
build/product-rating-counter.js 687 B
build/product-rating-frontend.js 2.37 kB
build/product-rating-rtl.css 262 B
build/product-rating-stars-frontend.js 2.27 kB
build/product-rating-stars-rtl.css 914 B
build/product-rating-stars.css 916 B
build/product-rating-stars.js 937 B
build/product-rating.css 262 B
build/product-rating.js 1.04 kB
build/product-results-count-rtl.css 248 B
build/product-results-count.css 247 B
build/product-results-count.js 1.67 kB
build/product-reviews-rtl.css 474 B
build/product-reviews.css 473 B
build/product-sale-badge-frontend.js 1.81 kB
build/product-sale-badge-rtl.css 392 B
build/product-sale-badge.css 389 B
build/product-sale-badge.js 665 B
build/product-search-rtl.css 435 B
build/product-search.css 434 B
build/product-search.js 2.63 kB
build/product-sku-frontend.js 1.87 kB
build/product-sku-rtl.css 258 B
build/product-sku.css 258 B
build/product-sku.js 535 B
build/product-stock-indicator-frontend.js 2.06 kB
build/product-stock-indicator-rtl.css 250 B
build/product-stock-indicator.css 250 B
build/product-stock-indicator.js 729 B
build/product-summary-frontend.js 2.28 kB
build/product-summary-rtl.css 571 B
build/product-summary.css 572 B
build/product-summary.js 1.01 kB
build/product-tag.js 8.95 kB
build/product-template-rtl.css 439 B
build/product-template.css 437 B
build/product-template.js 3.35 kB
build/product-title-frontend.js 2.23 kB
build/product-title-rtl.css 718 B
build/product-title.css 719 B
build/product-title.js 973 B
build/product-top-rated.js 9.01 kB
build/products-by-attribute.js 9.8 kB
build/rating-filter-frontend.js 21.4 kB
build/rating-filter-rtl.css 4.25 kB
build/rating-filter-wrapper-frontend.js 6.23 kB
build/rating-filter-wrapper-rtl.css 4.11 kB
build/rating-filter-wrapper.css 4.11 kB
build/rating-filter.css 4.24 kB
build/reviews-by-category-rtl.css 1.84 kB
build/reviews-by-category.css 1.84 kB
build/reviews-by-category.js 12.2 kB
build/reviews-by-product-rtl.css 1.84 kB
build/reviews-by-product.css 1.84 kB
build/reviews-frontend.js 7.18 kB
build/single-product-rtl.css 399 B
build/single-product.css 397 B
build/stock-filter-frontend.js 21.6 kB
build/stock-filter-rtl.css 4.06 kB
build/stock-filter-wrapper-frontend.js 6.45 kB
build/stock-filter-wrapper-rtl.css 3.93 kB
build/stock-filter-wrapper.css 3.93 kB
build/stock-filter.css 4.06 kB
build/store-notices.js 1.69 kB
build/vendors--attribute-filter-wrapper--cart-blocks/order-summary-coupon-form--cart-blocks/order-summary--48e1e4bb-frontend.js 6.84 kB
build/vendors--attribute-filter-wrapper--cart-blocks/order-summary-shipping--checkout-blocks/billing-addr--d9f38f9d-frontend.js 4.2 kB
build/vendors--attribute-filter-wrapper-frontend.js 5.11 kB
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--3c5fe802-frontend.js 5.26 kB
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.57 kB
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--decc3dc6-frontend.js 19.4 kB
build/vendors--checkout-blocks/pickup-options--checkout-blocks/shipping-methods-frontend.js 8.25 kB
build/vendors--checkout-blocks/shipping-method-frontend.js 12.4 kB
build/vendors--checkout-blocks/shipping-method-style.js 11.7 kB
build/vendors--mini-cart-contents-block/products-table--price-filter-wrapper--product-price-style.js 5.27 kB
build/vendors--mini-cart-contents-block/products-table-style.js 3.16 kB
build/vendors--price-filter-wrapper-frontend.js 2.2 kB
build/vendors--product-add-to-cart-frontend.js 7.25 kB
build/vendors--rating-filter-wrapper-frontend.js 5.11 kB
build/vendors--stock-filter-wrapper-frontend.js 5.11 kB
build/wc-blocks-data.js 22.4 kB
build/wc-blocks-editor-style-rtl.css 6.4 kB
build/wc-blocks-editor-style.css 6.4 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 934 B
build/wc-blocks-registry.js 3.15 kB
build/wc-blocks-rtl.css 2.54 kB
build/wc-blocks-shared-context.js 1.1 kB
build/wc-blocks-shared-hocs.js 1.75 kB
build/wc-blocks.css 2.54 kB
build/wc-blocks.js 3.75 kB
build/wc-interactivity.js 10.4 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.6 kB
build/wc-shipping-method-pickup-location.js 30.4 kB

compressed-size-action

assets/js/blocks/mini-cart/edit.tsx Outdated Show resolved Hide resolved
Comment on lines 13 to +17
interface Props {
count: number;
icon?: IconType;
iconColor?: string;
productCountColor?: string;
iconColor: ColorItem | { color: undefined };
productCountColor: ColorItem | { color: undefined };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where inconsistency of types needs cleaned up. You'll notice that through these changes.

Comment on lines 23 to 24
iconColor = { color: undefined },
productCountColor = { color: undefined },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, consistency of types :). Also will need to make sure if importing types that they are exposed in a frontend build friendly location.

assets/js/blocks/mini-cart/index.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, @nerrad! I like how creating the ColorPanel component helps reduce the amount of logic that needs to live under each blocks' code. 👏

Overall it looks good, I just found that there is a JS error when selecting a custom hex color using the color picker (tested with WP 6.2 and GB 16.0.0). Can you reproduce as well?

Enregistrament.de.pantalla.des.de.2023-07-03.10-36-32.webm

I also left a couple of inline comments below.


Besides that, I also noticed that since #9647, Gutenberg is needed for the color settings to appear in the editor. In WP 6.2 with Gutenberg disabled there is no longer a way to change the color of the Mini-Cart block button. Also, in the past it was possible to change the background color, but this options has disappeared. Is that expected? cc @danieldudzic

assets/js/editor-components/color-panel/index.tsx Outdated Show resolved Hide resolved
assets/js/editor-components/color-panel/index.tsx Outdated Show resolved Hide resolved
@danieldudzic
Copy link
Contributor

Since #9647, Gutenberg is needed for the color settings to appear in the editor. In WP 6.2 with Gutenberg disabled there is no longer a way to change the color of the Mini-Cart block button.

@Aljullu I believe that's due to custom color settings being __experimental.

Also, in the past it was possible to change the background color, but this options has disappeared. Is that expected? cc @danieldudzic

The decision to remove it was based on the Mini-Cart re-design: pdnLyh-3ze-p2

@Aljullu
Copy link
Contributor

Aljullu commented Jul 3, 2023

Thanks, @danieldudzic!

@Aljullu I believe that's due to custom color settings being __experimental.

Makes sense. I'm just a bit confused if it's worth it, though. Considering most of our users are in WC core and not in WC Blocks, I feel it's a bit weird that we improve a feature but as a consequence we have to restrict it to the feature plugin, so most users won't benefit from it.

The decision to remove it was based on the Mini-Cart re-design: pdnLyh-3ze-p2

Good call. I just left a question in the thread to make sure it was intentional: pdnLyh-3ze-p2#comment-2693. 👍

@github-actions
Copy link
Contributor

This PR has been marked as stale because it has not seen any activity within the past 7 days. Our team uses this tool to help surface pull requests that have slipped through review.

If deemed still relevant, the pr can be kept active by ensuring it's up to date with the main branch and removing the stale label.

@github-actions github-actions bot added the status: stale Stale issues and PRs have had no updates for 60 days. label Jul 11, 2023
@tjcafferkey tjcafferkey assigned tjcafferkey and nerrad and unassigned nerrad Jul 12, 2023
@github-actions github-actions bot removed the status: stale Stale issues and PRs have had no updates for 60 days. label Jul 12, 2023
@tjcafferkey
Copy link
Contributor

tjcafferkey commented Jul 12, 2023

Regarding the below point:

I didn't implement the class property on the constructed colors and that may be something we'll want to tweak anyways. So should be reviewed.

From looking, this class property is generated by Gutenberg and still provided in the attributes prop (see object below) so it still exists with no further work required on our side in this PR. Unless I am misunderstanding what is meant here? I am just noting in this comment for future reference.

productCountColor: {
    "name": "Pale pink",
    "slug": "pale-pink",
    "color": "#f78da7",
    "class": "has-pale-pink-product-count-color"
}

cc @nerrad

@nerrad
Copy link
Contributor Author

nerrad commented Jul 12, 2023

Unless I am misunderstanding what is meant here? I am just noting in this comment for future reference.

I think I was referring to not having implemented the property in the block applying this API (via className).

@tjcafferkey
Copy link
Contributor

I think I was referring to not having implemented the property in the block applying this API (via className)

Ah, I understand now. I don't think this property was applied prior to this PR so I'm inclined to not include it in the block since that's how it's always been.

@tjcafferkey
Copy link
Contributor

I didn't add any automated tests

Just a note, we can't write any E2E tests around this feature since we don't run the Gutenberg plugin in our testing environment and this relies on colorGradientOptions.hasColorsOrGradients which isn't yet in Core.

@tjcafferkey
Copy link
Contributor

@Aljullu I think this is ready for another review. I've done my own review and testing. The remaining tasks that are either nice to have or can't be done at the moment can be created as follow-up issues I think.

@tjcafferkey tjcafferkey requested a review from Aljullu July 17, 2023 11:10
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is overall looking good, thanks for working on this @tjcafferkey!

I can still reproduce the issue I reported earlier with custom HTML colors. Can you reproduce it too? Besides that, I left some minor comments inline: 👇

Comment on lines 159 to 182
export const useColorPanelStyles = ( colorTypes: CustomColorsMap ) => {
const { clientId } = useBlockEditContext();
const attributes = useSelect(
( select ) => {
// @ts-ignore @wordpress/block-editor/store types not provided
const { getBlockAttributes } = select( blockEditorStore );
return getBlockAttributes( clientId ) || {};
},
[ clientId ]
);

const className: string[] = [];

Object.keys( colorTypes ).forEach( ( colorName ) => {
const attribute = attributes?.[ colorName ];
if ( attribute && attribute?.color ) {
className.push( `has-${ colorTypes[ colorName ].context }` );
}
} );

return {
className,
};
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite subjective, but posting it just in case you agree. 🙂 I would move this hook to a separate file, use-color-panel-styles.ts or something like this. I think that one export per-file makes code easier to read and to find via search.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will update this based on the outcome of this discussion below #10062 (comment)

},
};

const { className } = useColorPanelStyles( miniCartColorAttributes );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing something obvious, but what are these class names used for? If I remove them, everything seems to keep working correctly. 😕

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we use them for anything. This was to maintain the markup that was generated before this refactor. You can see here the classes being generated prior to this change. I'm unaware of any context around why they are being generated.

If you think we can remove them, it also means we can remove the hook too as that is its sole responsibility at this point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure of the reason why they exist, but I think it should be safe to remove them. They are only used in the editor component and are not saved into the block markup, so it won't cause any invalidation.

@tjcafferkey
Copy link
Contributor

I can still reproduce #10062 (review) I reported earlier with custom HTML colors.

Thanks @Aljullu not sure how I missed that but I've committed a fix and replied to your comments.

Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirming the bug with custom HEX colors is fixed, thanks!

The only last issue I noticed is that if I set custom colors in trunk, they are not visible in the editor when checking out this branch. Steps to reproduce:

  1. In trunk add the Mini-Cart block to a page and change its Price, Icon and Product Count colors.
  2. Preview the page frontend. Notice colors are applied properly.
  3. Check out this branch and reload the tabs from 1 and 2. Notice in the frontend colors are still applied correctly, but they are not in the editor.
trunk This branch
imatge imatge

Can you reproduce it too?

},
};

const { className } = useColorPanelStyles( miniCartColorAttributes );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not sure of the reason why they exist, but I think it should be safe to remove them. They are only used in the editor component and are not saved into the block markup, so it won't cause any invalidation.

@@ -47,19 +42,19 @@
"default": "hidden"
},
"priceColor": {
"type": "string"
"type": "object"
},
"priceColorValue": {
Copy link
Contributor

@tjcafferkey tjcafferkey Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoyingly with the current method of maintaining existing blocks that have custom colors we need to keep these values (priceColorValue, iconColorValue, productCountColorValue) in the block.json file.


export interface ColorPaletteOption {
name: string;
slug: string | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to string | undefined; because when you select a color from the picker this doesn't return a slug.

Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on the migration from the previous color values to the new ones, it works well and code looks good!

The only issue I noticed is that if I set the colors when in trunk and then switch to this branch, they don't appear in the editor controls:

imatge

Can you reproduce as well?

assets/js/blocks/mini-cart/edit.tsx Outdated Show resolved Hide resolved
@tjcafferkey
Copy link
Contributor

tjcafferkey commented Jul 21, 2023

The only issue I noticed is that if I set the colors when in trunk and then switch to this branch, they don't appear in the editor controls:

@Aljullu I noticed this too, in order to fix this it might make the <ColorPanel /> code a bit more complex to accommodate for this. So I guess it's a trade off. At the moment it uses useSelect to fetch the values from the store internally, so we would need to alter the components API to accept some default attributes we could pass it.

Personally at this point I don't think it's worth it because:

  1. The impact of this change is currently limited because it's in the feature plugin only and requires the Gutenberg plugin to be enabled.
  2. Current state of the feature is still very new so usage will be low.
  3. User still has the ability to select the colors again if they need to.

Let me know what you think?

Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense to me, agree with what you mention. 👍

@github-actions github-actions bot added this to the 10.8.0 milestone Jul 21, 2023
@tjcafferkey tjcafferkey merged commit 614cc57 into trunk Jul 21, 2023
31 checks passed
@tjcafferkey tjcafferkey deleted the add/color-panel-component branch July 21, 2023 09:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: mini-cart Issues related to the Mini-Cart block. focus: components Work that introduces new or updates existing components. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mini-Cart: Make custom colors compatible with theme presets and Global Styles
4 participants