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

Add dark colors support to Cart & Checkout controls #2981

Merged
merged 21 commits into from Aug 14, 2020

Conversation

senadir
Copy link
Member

@senadir senadir commented Aug 7, 2020

Closes #2320
Fixes #2986

This PR introduces dark styles to our controls, it adds them to:

  • Text Control Inputs.
  • Select Control.
  • Checkbox Control.
  • Radio Control.
  • Quantity Selector.
  • Textarea Control.
  • Panel title in Twentyseventeen.

Screenshots

Dark mode (in storefront)

Screen Shot 2020-08-07 at 10 57 06 AM

Screen Shot 2020-08-07 at 10 58 10 AM

Screen Shot 2020-08-07 at 10 58 10 AM

Light mode

Screen Shot 2020-08-07 at 11 00 27 AM

Screen Shot 2020-08-07 at 11 01 15 AM

Screen Shot 2020-08-07 at 11 00 03 AM

It also introduces the option to toggle this mode or not, the default value of that attribute is inherited from the theme, themes can ask GB for dark mode support by defining add_theme_support( 'dark-editor-style' ), we look for that and decide accordingly.
By default, previous blocks will stay on light mode, even if the theme has dark styles enabled, if they resave the block again, or insert it again, the new default value will be inherited from dark styles option.

Screen Shot 2020-08-07 at 11 00 14 AM

Accessibility

How to test the changes in this Pull Request:

  1. First, pull this PR and make sure nothing is broken by default, this means in light mode with normal colors, test inputs, select, radio, checkbox, quantity selectors.
  2. Switch the colors of your theme to a dark variation, you can do that in the customizer for storefront.
  3. Switch the block to use dark colors and test the inputs again, make sure nothing is broken.

Changelog

Add dark colors and background for Cart & Checkout blocks to support dark backgrounds.

@senadir senadir added focus: components Work that introduces new or updates existing components. block: cart Issues related to the cart block. block: checkout Issues related to the checkout block. focus: global styles Issues that involve styles/css/layout structure. labels Aug 7, 2020
@senadir senadir added this to the 3.2.0 milestone Aug 7, 2020
@senadir senadir requested a review from a team as a code owner August 7, 2020 10:22
@senadir senadir self-assigned this Aug 7, 2020
@senadir senadir requested review from haszari and Aljullu and removed request for a team August 7, 2020 10:22
@github-actions
Copy link
Contributor

github-actions bot commented Aug 7, 2020

Size Change: +1.95 kB (0%)

Total Size: 1.66 MB

Filename Size Change
build/active-filters-frontend.js 8.78 kB +23 B (0%)
build/active-filters.js 8.83 kB +27 B (0%)
build/all-products-frontend.js 31.2 kB +28 B (0%)
build/all-products.js 35.6 kB +27 B (0%)
build/all-reviews-legacy.js 9.41 kB +19 B (0%)
build/all-reviews.js 9.76 kB +26 B (0%)
build/atomic-block-components/add-to-cart.js 7.46 kB -4 B (0%)
build/atomic-block-components/button-frontend.js 2.02 kB -2 B (0%)
build/atomic-block-components/button.js 839 B +2 B (0%)
build/atomic-block-components/image-frontend.js 1.71 kB -2 B (0%)
build/atomic-block-components/image.js 1.15 kB -1 B
build/atomic-block-components/price-frontend.js 2.09 kB +2 B (0%)
build/atomic-block-components/price.js 2.11 kB -1 B
build/atomic-block-components/rating.js 527 B -1 B
build/atomic-block-components/tag-list.js 473 B +1 B
build/atomic-block-components/title-frontend.js 1.22 kB +2 B (0%)
build/attribute-filter-frontend.js 18.1 kB +29 B (0%)
build/attribute-filter.js 12.4 kB +25 B (0%)
build/blocks.js 3.54 kB -1 B
build/cart-frontend.js 66.6 kB +67 B (0%)
build/cart.js 35 kB +119 B (0%)
build/checkout-frontend.js 83.8 kB +61 B (0%)
build/checkout.js 40.4 kB +141 B (0%)
build/editor-legacy-rtl.css 13.6 kB -195 B (1%)
build/editor-legacy.css 13.6 kB -197 B (1%)
build/editor-rtl.css 13.9 kB -197 B (1%)
build/editor.css 13.9 kB -197 B (1%)
build/featured-category-legacy.js 7.31 kB +19 B (0%)
build/featured-category.js 7.7 kB +22 B (0%)
build/featured-product-legacy.js 9.57 kB +17 B (0%)
build/featured-product.js 9.95 kB +24 B (0%)
build/handpicked-products-legacy.js 6.96 kB +16 B (0%)
build/handpicked-products.js 7.34 kB +24 B (0%)
build/price-filter-frontend.js 14.4 kB +26 B (0%)
build/price-filter.js 10.2 kB +22 B (0%)
build/product-best-sellers-legacy.js 7.05 kB +18 B (0%)
build/product-best-sellers.js 7.42 kB +24 B (0%)
build/product-categories.js 3.23 kB +1 B
build/product-category-legacy.js 7.96 kB +18 B (0%)
build/product-category.js 8.36 kB +20 B (0%)
build/product-new-legacy.js 7.21 kB +18 B (0%)
build/product-new.js 7.58 kB +28 B (0%)
build/product-on-sale-legacy.js 7.58 kB +16 B (0%)
build/product-on-sale.js 7.97 kB +24 B (0%)
build/product-search-legacy.js 3.19 kB +18 B (0%)
build/product-search.js 3.53 kB +23 B (0%)
build/product-tag-legacy.js 6.14 kB +17 B (0%)
build/product-tag.js 6.49 kB +23 B (0%)
build/product-top-rated-legacy.js 7.18 kB +18 B (0%)
build/product-top-rated.js 7.55 kB +23 B (0%)
build/products-by-attribute-legacy.js 7.94 kB +18 B (0%)
build/products-by-attribute.js 8.29 kB +22 B (0%)
build/reviews-by-category-legacy.js 11.4 kB +17 B (0%)
build/reviews-by-category.js 11.8 kB +24 B (0%)
build/reviews-by-product-legacy.js 12.9 kB +18 B (0%)
build/reviews-by-product.js 13.3 kB +24 B (0%)
build/reviews-frontend-legacy.js 8.45 kB +19 B (0%)
build/reviews-frontend.js 9.36 kB +29 B (0%)
build/single-product-frontend.js 34 kB +31 B (0%)
build/single-product.js 10.1 kB +25 B (0%)
build/style-legacy-rtl.css 17.2 kB +364 B (2%)
build/style-legacy.css 17.2 kB +362 B (2%)
build/style-rtl.css 17.9 kB +365 B (2%)
build/style.css 17.9 kB +364 B (2%)
build/vendors.js 416 kB +10 B (0%)
ℹ️ View Unchanged
Filename Size Change
build/atomic-block-components/add-to-cart-frontend.js 8.88 kB 0 B
build/atomic-block-components/add-to-cart~atomic-block-components/button.js 3.17 kB 0 B
build/atomic-block-components/add-to-cart~atomic-block-components/image~atomic-block-components/title.js 335 B 0 B
build/atomic-block-components/category-list-frontend.js 468 B 0 B
build/atomic-block-components/category-list.js 476 B 0 B
build/atomic-block-components/rating-frontend.js 524 B 0 B
build/atomic-block-components/sale-badge-frontend.js 862 B 0 B
build/atomic-block-components/sale-badge.js 864 B 0 B
build/atomic-block-components/sku-frontend.js 389 B 0 B
build/atomic-block-components/sku.js 394 B 0 B
build/atomic-block-components/stock-indicator-frontend.js 568 B 0 B
build/atomic-block-components/stock-indicator.js 570 B 0 B
build/atomic-block-components/summary-frontend.js 918 B 0 B
build/atomic-block-components/summary.js 926 B 0 B
build/atomic-block-components/tag-list-frontend.js 466 B 0 B
build/atomic-block-components/title.js 1.06 kB 0 B
build/blocks-legacy.js 3.54 kB 0 B
build/product-categories-legacy.js 3.23 kB 0 B
build/vendors-legacy.js 367 kB 0 B
build/vendors-style-legacy-rtl.css 1.03 kB 0 B
build/vendors-style-legacy.css 1.03 kB 0 B
build/vendors-style-rtl.css 1.03 kB 0 B
build/vendors-style.css 1.03 kB 0 B
build/vendors~atomic-block-components/price-frontend.js 5.65 kB 0 B
build/wc-blocks-data.js 7.09 kB 0 B
build/wc-blocks-middleware.js 931 B 0 B
build/wc-blocks-registry.js 2.28 kB 0 B
build/wc-payment-method-bacs.js 790 B 0 B
build/wc-payment-method-cheque.js 787 B 0 B
build/wc-payment-method-cod.js 875 B 0 B
build/wc-payment-method-paypal.js 831 B 0 B
build/wc-payment-method-stripe.js 11.9 kB 0 B
build/wc-settings.js 2.14 kB 0 B
build/wc-shared-context.js 1.53 kB 0 B
build/wc-shared-hocs.js 1.66 kB 0 B

compressed-size-action

Copy link
Member

@haszari haszari left a comment

Choose a reason for hiding this comment

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

Looking good - this is a nice enhancement @senadir. I tested with customised dark-background Storefront and also with Twenty Seventeen which as a Colors > Dark option. I saw some little quirks here and there but no major blockers. Note I did my testing primarily in Safari / Firefox, and focused on the dark mode feature (not the other issues addressed in this PR).

Alongside a few code comments, I have a bunch of mostly minor feedback. Some might be better to address within this PR but much can be done as follow up. Let me know if you want me to make any follow up issues (I'll assume you're handling that).

  1. The UI & naming of the merchant/editor block option - probably good idea to loop in design and make any changes before merge. Also the block option is displayed at the top of the sidebar - I think it should be further down, it's more "advanced" than the others (e.g. address options).
  2. Consistent/clear approach to hard-coded vs colour variables. I like the idea of the colours being in variables, but I don't understand why some are variables and some are hard coded inline.
  3. No live preview in editor - maybe there's a technical blocker for this. It makes the editor option much more tricky for merchants, live preview would really help.
  4. Some form elements still white (this is probably follow up, as it's different in different themes).
  • Order notes textarea - white in Storefront, dark in Twenty Seventeen.
  • Stripe credit card fields - white in both themes I tested.

I see this PR has fixes for three issues – I can see why, since they can be somewhat tested together. However in general I'd prefer to have a PR for each issue to ensure they all get appropriate review, and if there are dependencies between PRs, then we can be explicit about that.

assets/js/base/components/checkbox-control/index.js Outdated Show resolved Hide resolved
@@ -8,6 +8,9 @@
&:focus {
outline: 2px solid $core-grey-light-600;
}
.has-dark-styles &:focus {
Copy link
Member

Choose a reason for hiding this comment

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

Is the outline width different for dark mode - if so, what's the rationale for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no design spec for this, I felt that 2px was too much, and 1px is too little for light mode, I switched back to 2px to align both styles.

assets/js/base/components/quantity-selector/style.scss Outdated Show resolved Hide resolved
assets/js/blocks/cart-checkout/cart/edit.js Outdated Show resolved Hide resolved
assets/js/blocks/cart-checkout/cart/edit.js Outdated Show resolved Hide resolved
assets/js/blocks/cart-checkout/checkout/block.js Outdated Show resolved Hide resolved
assets/js/blocks/cart-checkout/checkout/style.scss Outdated Show resolved Hide resolved
src/Assets.php Outdated Show resolved Hide resolved
@haszari
Copy link
Member

haszari commented Aug 10, 2020

Saw an issue in Twenty Seventeen with Order Summary panel headings, reported separate issue #2986

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 looking great! 😍

I think @haszari has done a good review here, so just adding my two cents of some stuff that I saw:

  • Color of text input placeholders should change in dark mode, otherwise contrast is too low:

Screenshot

  • Radio inputs are still dark in the editor:

Screenshot

I think the best way to proceed here would be to refactor radio inputs CSS completely: we shouldn't have the frontend and editor styles duplicated with different specificity. That's not blocking and can be handled in a follow-up in my opinion.

assets/js/base/components/quantity-selector/style.scss Outdated Show resolved Hide resolved
assets/js/base/components/select/style.scss Outdated Show resolved Hide resolved
assets/js/base/components/text-input/style.scss Outdated Show resolved Hide resolved
assets/js/blocks/cart-checkout/checkout/style.scss Outdated Show resolved Hide resolved
@nerrad
Copy link
Contributor

nerrad commented Aug 12, 2020

Just as a FYI (not a blocker to work being done here, but just for awareness), this came up in WordPress core-editor chat today: WordPress/gutenberg#24368

@senadir
Copy link
Member Author

senadir commented Aug 13, 2020

No live preview in editor - maybe there's a technical blocker for this. It makes the editor option much more tricky for merchants, live preview would really help.

I can't reproduce this, are you sure? cc @haszari

Some form elements still white (this is probably follow up, as it's different in different themes).

Do you mean the heading element in 2017?

@senadir
Copy link
Member Author

senadir commented Aug 13, 2020

Radio inputs are still dark in the editor

Because they're disabled. cc @Aljullu

@senadir senadir force-pushed the add/dark-theme-support-to-cart-checkout branch from 5f8baf4 to 2816f72 Compare August 13, 2020 14:09
@haszari haszari mentioned this pull request Aug 14, 2020
Copy link
Member

@haszari haszari 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 looking great and working really well, nice job @senadir !

Even with my terracotta storefront 🙌 :

Screen Shot 2020-08-14 at 1 50 03 PM

One tiny thing to possibly change - the Dark mode inputs shouldn't be the top option in the editor IMO. Shipping, address, nav options are all more important to cart/checkout – I think it's safe to put the new setting at the bottom, above the feedback panel.

Screen Shot 2020-08-14 at 1 48 28 PM

The Stripe credit card form field is still showing white, but possibly this can be handled as follow up (since it's somewhat out of our control).

Screen Shot 2020-08-14 at 1 49 29 PM

@@ -44,6 +54,8 @@
}
}

// Hack to hide the check mark in IE11
// See comment: https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/2320/#issuecomment-621936576
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment still relevant? Not a blocker :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Not much, but it wasn't added on the previous PR and stayed here during rebase, no point in deleting it and putting it back in a new PR.

assets/js/base/components/textarea/style.scss Outdated Show resolved Hide resolved
export const PAYMENT_GATEWAY_SORT_ORDER = getSetting(
'paymentGatewaySortOrder',
[]
);
Copy link
Member

Choose a reason for hiding this comment

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

Interesting that this formatting snuck through!

@@ -24,6 +25,10 @@ const blockAttributes = {
type: 'number',
default: 0,
},
hasDarkControls: {
type: 'boolean',
default: HAS_DARK_EDITOR_STYLE_SUPPORT,
Copy link
Member

Choose a reason for hiding this comment

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

This might not be a big deal .. but I'm still a bit confused about the relationship between current_theme_supports( 'dark-editor-style' ) and our new block setting.

  • dark-editor-style is an editor-focused option, informing Gutenberg that it should use dark mode to work better with the editor styles for the theme
  • hasDarkControls is a front-end, shopper experience option

I think it's probably fine to use it as the default, but since they are quite different it would be good to have a comment explaining the intention with the default.

Here's my understanding of why we're using this as the default:

  • If a theme is predominantly "dark", it's likely to want to opt-in to our dark mode for cart/checkout elements.
  • Themes that have user-defined color options (e.g. Storefront) won't get the benefit of the default, because they won't declare "dark"ness, since it's customizer dependent.

Copy link
Member Author

Choose a reason for hiding this comment

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

If a theme is predominantly "dark", it's likely to want to opt-in to our dark mode for cart/checkout elements.
Themes that have user-defined color options (e.g. Storefront) won't get the benefit of the default, because they won't declare "dark"ness, since it's customizer dependent.

Yes, we have this method to assume a theme is dark:

  • The themes supports dark-editor-style, by explicitly supporting this, most editor borders and placeholders will be white, making them illegible on white background, by this we can assume the background is dark.

A theme can also register support for custom-background, however I'm not aware if there's a standardized way of fetching that value, get_theme_support will only fetch the default value.
If we can fetch the custom-background value, we can run some calculations (like TwentyTwenty) to see if the background is dark or light, and set the default based on that.

'woo-gutenberg-products-block'
) }
help={ __(
'Inputs styled specifically for use on dark background colors.',
Copy link
Member

Choose a reason for hiding this comment

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

Nice new wording!

background-color: $input-background-dark;
border-color: $input-border-dark;
color: $input-text-dark;
}
Copy link
Member

Choose a reason for hiding this comment

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

❤️ how clean and simple all the new dark-mode rules are now - opt-in to alternative, standardised colours. 👌

@senadir senadir merged commit 2d99565 into main Aug 14, 2020
@senadir senadir deleted the add/dark-theme-support-to-cart-checkout branch August 14, 2020 11:08
@senadir senadir mentioned this pull request Aug 19, 2020
20 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: cart Issues related to the cart block. block: checkout Issues related to the checkout block. focus: components Work that introduces new or updates existing components. focus: global styles Issues that involve styles/css/layout structure.
Projects
None yet
5 participants