-
Notifications
You must be signed in to change notification settings - Fork 68
feat: colors' css variables and action hook for mobile toggle #1875
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
laurelfulford
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing this PR with Automattic/newspack-plugin#1754, it's functionally correct -- the button does appear and displays on both desktop and mobile.
I did notice some visual issues (with alignment, spacing, and contrast), but I don't think finalizing that kind of stuff is the purpose of this PR 🙂 Based on that assumption, I've marked this PR as approved.
Please let me know if I have that wrong, and I can do a more thorough visual review!
I'm also happy to spin up an issue for addressing the styles down the road -- just let me know, thanks @miguelpeixe!
|
Thank you, @laurelfulford! I've pushed another change on 31034ad to introduce global CSS variables for the theme's colors. This will help reader activation and other projects to more easily integrate with the theme's UI. If you can give it a test, it should display the correct applied colors as variables on DevTools: |
|
Thanks @miguelpeixe! This works as described, but I have some feedback about the approach: I'm probably overthinking this one, but I think it might be easier in the long run to handle any theme-related styles for the reader activation stuff in the theme, rather than the plugin. This is because when we release a new theme, things like the primary and secondary colour settings or header colour settings won't exist as they do now -- they'll either be provided by Global Styles, or come from a block setting, rather than a universal spot we can pass like this. If all of this colour code is in the theme, at least there's nothing to override/untangle when this functionality is used with a different theme. (There's no reason not to use variables though!) In a similar vein, we might be able to make the theme styles more general -- like make sure anything in the header is picking up the correct colours without having to know the classes -- to help reduce the amount of activation-specific CSS we need! If we do go ahead with this approach, it might be helpful to pass the contrasting colours as well. These colours are either black or white, depending on what would contrast against one of the custom colours -- so one example would be if the header colour is very light, its contrasting colour would be black, and would be used for the header text; if the header colour is very dark, that colour would be white. Also, it's an extreme edge case, but the colour styles are only added to a site when something has been customized -- so if you're using the default colours, default ad colours and default mobile CTA colours, these variables won't be available. This won't affect any "real" sites, but it could affect demos/our own sites -- it might be worth adding some defaults in one of the theme's Sass files. Just let me know if you have questions any of this! |
|
Thank you for your feedback on the approach!
If the new theme is going to provide variables such as
Good call! I'll update to include these variants.
I didn't realize that! I'll also change the approach to have a separate action hook rendering the variables. |
Ah right, I think that should work! 🙂 The only "gotcha" I think just might be the weird few things the theme does with colours (eg. half use the primary colour as the default header colour; others use shades of grey), but approaching this in more of a future looking way would be best in the long term -- we can always tackle those weird things as they come up! For this, it may not make sense to add the theme contrast colours after all? I'm not exactly sure how those would be replaced dynamically in a future FSE theme... though that can also be something we can tackle when it actually becomes a problem. It's a ways in the future at the moment. |
It may be the case to adjust/include the existing color variables as they are required. AFAIK, FSE does all that automatically, so we'll soon not have to worry about exposing theme colors at all. It'll be about choosing which and where to use them. |
|
For reference, this is how Twenty Twenty-Two rendered body variables looks: body {
--wp--preset--color--black: #000000;
--wp--preset--color--cyan-bluish-gray: #abb8c3;
--wp--preset--color--white: #ffffff;
--wp--preset--color--pale-pink: #f78da7;
--wp--preset--color--vivid-red: #cf2e2e;
--wp--preset--color--luminous-vivid-orange: #ff6900;
--wp--preset--color--luminous-vivid-amber: #fcb900;
--wp--preset--color--light-green-cyan: #7bdcb5;
--wp--preset--color--vivid-green-cyan: #00d084;
--wp--preset--color--pale-cyan-blue: #8ed1fc;
--wp--preset--color--vivid-cyan-blue: #0693e3;
--wp--preset--color--vivid-purple: #9b51e0;
--wp--preset--color--foreground: #CA2315;
--wp--preset--color--background: #FFF6F6;
--wp--preset--color--primary: #2031b8;
--wp--preset--color--secondary: #FFFFFF;
--wp--preset--color--tertiary: #F5F5F5;
--wp--preset--gradient--vivid-cyan-blue-to-vivid-purple: linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%);
--wp--preset--gradient--light-green-cyan-to-vivid-green-cyan: linear-gradient(135deg,rgb(122,220,180) 0%,rgb(0,208,130) 100%);
--wp--preset--gradient--luminous-vivid-amber-to-luminous-vivid-orange: linear-gradient(135deg,rgba(252,185,0,1) 0%,rgba(255,105,0,1) 100%);
--wp--preset--gradient--luminous-vivid-orange-to-vivid-red: linear-gradient(135deg,rgba(255,105,0,1) 0%,rgb(207,46,46) 100%);
--wp--preset--gradient--very-light-gray-to-cyan-bluish-gray: linear-gradient(135deg,rgb(238,238,238) 0%,rgb(169,184,195) 100%);
--wp--preset--gradient--cool-to-warm-spectrum: linear-gradient(135deg,rgb(74,234,220) 0%,rgb(151,120,209) 20%,rgb(207,42,186) 40%,rgb(238,44,130) 60%,rgb(251,105,98) 80%,rgb(254,248,76) 100%);
--wp--preset--gradient--blush-light-purple: linear-gradient(135deg,rgb(255,206,236) 0%,rgb(152,150,240) 100%);
--wp--preset--gradient--blush-bordeaux: linear-gradient(135deg,rgb(254,205,165) 0%,rgb(254,45,45) 50%,rgb(107,0,62) 100%);
--wp--preset--gradient--luminous-dusk: linear-gradient(135deg,rgb(255,203,112) 0%,rgb(199,81,192) 50%,rgb(65,88,208) 100%);
--wp--preset--gradient--pale-ocean: linear-gradient(135deg,rgb(255,245,203) 0%,rgb(182,227,212) 50%,rgb(51,167,181) 100%);
--wp--preset--gradient--electric-grass: linear-gradient(135deg,rgb(202,248,128) 0%,rgb(113,206,126) 100%);
--wp--preset--gradient--midnight: linear-gradient(135deg,rgb(2,3,129) 0%,rgb(40,116,252) 100%);
--wp--preset--gradient--vertical-secondary-to-tertiary: linear-gradient(to bottom,var(--wp--preset--color--secondary) 0%,var(--wp--preset--color--tertiary) 100%);
--wp--preset--gradient--vertical-secondary-to-background: linear-gradient(to bottom,var(--wp--preset--color--secondary) 0%,var(--wp--preset--color--background) 100%);
--wp--preset--gradient--vertical-tertiary-to-background: linear-gradient(to bottom,var(--wp--preset--color--tertiary) 0%,var(--wp--preset--color--background) 100%);
--wp--preset--gradient--diagonal-primary-to-foreground: linear-gradient(to bottom right,var(--wp--preset--color--primary) 0%,var(--wp--preset--color--foreground) 100%);
--wp--preset--gradient--diagonal-secondary-to-background: linear-gradient(to bottom right,var(--wp--preset--color--secondary) 50%,var(--wp--preset--color--background) 50%);
--wp--preset--gradient--diagonal-background-to-secondary: linear-gradient(to bottom right,var(--wp--preset--color--background) 50%,var(--wp--preset--color--secondary) 50%);
--wp--preset--gradient--diagonal-tertiary-to-background: linear-gradient(to bottom right,var(--wp--preset--color--tertiary) 50%,var(--wp--preset--color--background) 50%);
--wp--preset--gradient--diagonal-background-to-tertiary: linear-gradient(to bottom right,var(--wp--preset--color--background) 50%,var(--wp--preset--color--tertiary) 50%);
--wp--preset--duotone--dark-grayscale: url(#wp-duotone-dark-grayscale);
--wp--preset--duotone--grayscale: url(#wp-duotone-grayscale);
--wp--preset--duotone--purple-yellow: url(#wp-duotone-purple-yellow);
--wp--preset--duotone--blue-red: url(#wp-duotone-blue-red);
--wp--preset--duotone--midnight: url(#wp-duotone-midnight);
--wp--preset--duotone--magenta-yellow: url(#wp-duotone-magenta-yellow);
--wp--preset--duotone--purple-green: url(#wp-duotone-purple-green);
--wp--preset--duotone--blue-orange: url(#wp-duotone-blue-orange);
--wp--preset--duotone--foreground-and-background: url(#wp-duotone-foreground-and-background);
--wp--preset--duotone--foreground-and-secondary: url(#wp-duotone-foreground-and-secondary);
--wp--preset--duotone--foreground-and-tertiary: url(#wp-duotone-foreground-and-tertiary);
--wp--preset--duotone--primary-and-background: url(#wp-duotone-primary-and-background);
--wp--preset--duotone--primary-and-secondary: url(#wp-duotone-primary-and-secondary);
--wp--preset--duotone--primary-and-tertiary: url(#wp-duotone-primary-and-tertiary);
--wp--preset--font-size--small: 0.875rem;
--wp--preset--font-size--medium: 1rem;
--wp--preset--font-size--large: 1.25rem;
--wp--preset--font-size--x-large: clamp(1.5rem, 3vw, 2rem);
--wp--preset--font-family--ibm-plex-sans: "IBM Plex Sans", sans-serif;
--wp--preset--font-family--ibm-plex-mono: "IBM Plex Mono", monospace;
--wp--custom--spacing--small: max(0.75rem, 4vw);
--wp--custom--spacing--medium: clamp(1.75rem, 6vw, calc(1.5 * var(--wp--style--block-gap)));
--wp--custom--spacing--large: clamp(3rem, 8vw, 5rem);
--wp--custom--spacing--outer: var(--wp--custom--spacing--small, 0.75rem);
--wp--custom--typography--font-size--huge: clamp(2rem, 4vw, 2.25rem);
--wp--custom--typography--font-size--gigantic: clamp(2.25rem, 6vw, 2.75rem);
--wp--custom--typography--font-size--colossal: clamp(2.75rem, 8vw, 3.25rem);
--wp--custom--typography--line-height--tiny: 1.15;
--wp--custom--typography--line-height--small: 1.2;
--wp--custom--typography--line-height--medium: 1.4;
--wp--custom--typography--line-height--normal: 1.6;
--wp--custom--line-height--normal: 1.7;
} |
|
2ea6497 moves the color variables to its own hook to not be conditioned to existing customizations. |
Note: relies on Automattic/newspack-theme#1875
|
Thanks for updating this, @miguelpeixe! I'm not sure it will fully work as expected -- when I change the theme colours, I still end up with mostly the defaults (in my settings, primary, secondary, mobile CTA and header have been changed, but only the mobile CTA variable is different than the default in the CSS variables): Also, the header colour isn't always the primary colour -- it's the default for some of the themes when you turn on the solid background, but then it can be changed, but it doesn't look like that will work with the current set up. Would it work to set a default for these variables -- even in one of the theme's SCSS files -- and then override them using the original custom colours code as needed? |
|
Thanks, @laurelfulford! I didn't properly set up the variables used to generate the CSS variables, I was copying a subset of the definition of the variables. For better maintenance, 24e2a3c isolates the definition of colors to be used by the The CSS variables should now reflect the patterns exactly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @miguelpeixe! What's here looks good, and is a nice refactor of all that colour code!
I did run into one issue: each of the child themes also has their own colour patterns PHP under /inc/child-color-patterns.php, and the formatting should be updated to match. Overall I don't think this is an issue that has to be resolved in this PR -- we can refactor all of those in a separate PR -- but it is going to cause one small bug:
Three of the child themes don't use the primary colour as their header background default, they use different shades of grey -- specifically:
- Newspack Joseph uses
#111 - Newspack Katharine uses
#333 - Newspack Sacha uses
#333
(Originally there wasn't an option to control the header colour at all -- it just either used the primary colour for half the themes, and grey for the other half. This is a weird artifact of that).
If the header with these themes is set to have a solid background but not a custom colour, the CSS variables will be incorrect -- they will be for the primary colour and its contrasting text colour, rather than the actual header colour and its contrasting text colour.
In the unlikely chance a site has one of these themes, a solid header and no custom header colour set, the issue could be worked around by setting the header background colour to the same grey as the default.
Based on the above, I still think the child theme code can be addressed in a separate PR to help keep things moving. So I'm marking this one as 'approved' -- if you have any hesitation about moving forward with it as is, though, I'm happy to re-review!
|
Thank you, @laurelfulford!
Where will this bug be visible? I noticed that it'll generate an inconsistency between the created CSS variable and the actual applied color for the child themes. Although the CSS variables are created for all colors, they are currently only implemented for reader activation buttons/links using the primary color. |
It would only be visible if:
The issue would be the CSS variable for the header text colour would be dark (to contrast against the light primary colour), but it should actually be light, to contrast against the default header colour. It's a VERY specific set of circumstances, and pretty unlikely to actually crop up in the wild 🙂 If it did, setting the header background to be a dark grey would fix it! |
* feat: set client id cookie; reader activation tweaks (#1780) * feat(reader-activation): registration auth cookie control (#1787) * fix(reader-activation): username generation handling (#1789) * feat(stripe): webhook auto-creation and validation * feat(reader-activation): account link and auth form (#1754) Co-authored-by: Adam Boro <adam@adamboro.com> * feat: handle new frequency options in Campaigns dashbaord (#1779) * feat: handle new frequency options in Campaigns dashbaord * feat: only enable new frequency options if reader activation flag is on * feat(registration-block): newsletter subscription (#1778) * fix(popups): use new Campaigns method for creating donation events on new orders (#1794) * fix(popups): use new Campaigns method for creating donation events on new orders * refactor: use action hook instead of calling Campaigns methods directly * chore: remove unneeded condition * refactor: use a hook for WooCommerce donations, too * fix: add client_id to contact info passed from Stripe * feat(my-account): stripe billing portal link (#1761) Note: some styling relies on Automattic/newspack-theme#1875 Closes #1742 Closes #1739 Closes #1740 Closes #1741 Closes #1782 * feat(registration-block): login with Google (#1781) Closes #1774 Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com> * chore(deps): bump @babel/preset-env from 7.18.6 to 7.18.9 Bumps [@babel/preset-env](https://github.com/babel/babel/tree/HEAD/packages/babel-preset-env) from 7.18.6 to 7.18.9. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.18.9/packages/babel-preset-env) --- updated-dependencies: - dependency-name: "@babel/preset-env" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump date-fns from 2.28.0 to 2.29.1 Bumps [date-fns](https://github.com/date-fns/date-fns) from 2.28.0 to 2.29.1. - [Release notes](https://github.com/date-fns/date-fns/releases) - [Changelog](https://github.com/date-fns/date-fns/blob/master/CHANGELOG.md) - [Commits](date-fns/date-fns@v2.28.0...v2.29.1) --- updated-dependencies: - dependency-name: date-fns dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump @babel/plugin-transform-runtime from 7.18.6 to 7.18.9 Bumps [@babel/plugin-transform-runtime](https://github.com/babel/babel/tree/HEAD/packages/babel-plugin-transform-runtime) from 7.18.6 to 7.18.9. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.18.9/packages/babel-plugin-transform-runtime) --- updated-dependencies: - dependency-name: "@babel/plugin-transform-runtime" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump stripe/stripe-php from 8.10.0 to 8.11.0 Bumps [stripe/stripe-php](https://github.com/stripe/stripe-php) from 8.10.0 to 8.11.0. - [Release notes](https://github.com/stripe/stripe-php/releases) - [Changelog](https://github.com/stripe/stripe-php/blob/master/CHANGELOG.md) - [Commits](stripe/stripe-php@v8.10.0...v8.11.0) --- updated-dependencies: - dependency-name: stripe/stripe-php dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * feat: register anonymous single donors (#1795) Co-authored-by: Adam Borowski <adam@adamboro.com> * feat(registration-block): editable success state (#1785) Closes #1768 Co-authored-by: Thomas Guillot <thomasguillot@users.noreply.github.com> * feat(registration-block): add success icon (#1804) * refactor: remove unneeded prop * feat: send user metadata to AC (#1793) * feat: remove reader registration on adding contact via hook This was causing an infinite loop: Newsletters is triggering reader registration when a contact is added (`Newspack_Newsletters_Subscription::newspack_registered_reader`). Then, on adding a contact, registration was triggered again here. * fix(registration-block): margin for success message (#1808) * Reader Activation: auth form with third-party and lists subscriptions (#1800) * feat: tweak registration block styling * feat(reader-auth): make password login the first option, instead of login link Closes #1809 * fix(reader-activation): reinitialize auth links after DOM load (#1812) * fix: ensure scroll on smaller height (#1813) * feat(reader-activation): settings wizard (#1773) Co-authored-by: Adam Boro <adam@adamboro.com> * feat: handle contact update w/out lists selection (#1816) Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com> * chore: logger update (#1807) Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com> * feat(reader-activation): disable 3rd party login buttons initially (#1806) * feat(reader-activation): prevent updating user email in my-account * feat(reader-activation): activecampaign master list (#1818) Co-authored-by: Adam Boro <adam@adamboro.com> * chore(deps): bump stripe/stripe-php from 8.11.0 to 8.12.0 Bumps [stripe/stripe-php](https://github.com/stripe/stripe-php) from 8.11.0 to 8.12.0. - [Release notes](https://github.com/stripe/stripe-php/releases) - [Changelog](https://github.com/stripe/stripe-php/blob/master/CHANGELOG.md) - [Commits](stripe/stripe-php@v8.11.0...v8.12.0) --- updated-dependencies: - dependency-name: stripe/stripe-php dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * fix(campaigns-wizard): segmentation wording * feat(rss): adds offset feature (#1790) Adds offset feature to RSS, allowing better ad integration with RSS feed based emails * fix(reader-activation): handle no lists config available * fix: fix fatal error when debug mode active (#1826) * feat: reorganise donations wizard and use buttongroup for donation type (#1824) * fix: google auth button type (#1829) * fix(magic-links): fix email encoding on sent link (#1833) * fix(registration-block): don't escape html for sign in labels (#1834) * fix(reader-activation): add metadata to reader registered on donation * fix(registration-block): render on preview (#1844) Co-authored-by: Derrick Koo <dkoo@users.noreply.github.com> * fix(reader-activation): remove async prop from library (#1846) * feat(analytics): send GA events on the server side (#1828) * refactor: abstract server-side GA custom event sending * feat(reader-activation): send custom event to GA on reader registration * feat: report user login method to GA; refactor how it's stored * refactor: handle extended data from the newspack_newsletters_contact_data hook * feat: send NTG custom events on registration, newsletter signup * fix(my account): handle legacy data (#1823) * fix(reader-activation): handle modal conflict when auth is triggered from a prompt Closes #1835 * feat(reader-activation): optimistic account link (#1847) * fix(google-auth): ensure popup on user click event (#1831) Co-authored-by: Adam Boro <adam@adamboro.com> * feat(active-campaigns): override is-new-contact for legacy contacts * feat(active-campaign): metadata improvements (#1851) * feat: if registering an email that already has an account, show different message (#1849) * feat: if registering an email that already has an account, show different message * refactor: use existing var * feat: replace WooCommerce’s login form with our own (#1854) * feat: replace WooCommerce’s login form with our own * fix: use WC method to get account URL Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com> * refactor: call render method from template file * feat: hide page title on WC account pages * refactor: restore modal on My Account pages; handle multiple form instancse * refactor: use $class method to build inline class Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com> * style: remove unneeded padding from inline form * fix: move handlers and functions outside of loop * chore: reword auth message for consistency * fix: avoid JS error if redirect input is null * fix: avoid JS error if email input is null Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com> * fix(newsletters): use international date format (#1855) * fix: tweak arguments for magic link client hash (#1862) * feat(donations): remove defaultFrequency from the configuration (#1814) It's not configurable. See Automattic/newspack-blocks#1218 * fix(ga): cookie parsing (#1857) * fix(active-campaign): legacy contacts detection (#1858) Co-authored-by: Adam Boro <adam@adamboro.com> Co-authored-by: Miguel Peixe <miguel.peixe@automattic.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Thomas Guillot <thomasguillot@users.noreply.github.com> Co-authored-by: matticbot <sysops+ghmatticbot@automattic.com> Co-authored-by: dnalla1928 <53319922+dnalla1928@users.noreply.github.com> Co-authored-by: Claudiu Lodromanean <claudiulodro@gmail.com>
# [1.63.0-alpha.1](v1.62.0...v1.63.0-alpha.1) (2022-08-05) ### Bug Fixes * **registration-block:** make sure font-family in the editor matches front-end ([#1889](#1889)) ([e0c4309](e0c4309)) ### Features * add custom style for upcoming registration pattern (style 1) ([#1888](#1888)) ([58f303d](58f303d)) * Add featured listing styles ([#1877](#1877)) ([efc4936](efc4936)) * colors' css variables and action hook for mobile toggle ([#1875](#1875)) ([0830ca7](0830ca7)) * redesign "My Account" page ([#1879](#1879)) ([9258f21](9258f21))
|
🎉 This PR is included in version 1.63.0-alpha.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
# [1.63.0](v1.62.0...v1.63.0) (2022-08-16) ### Bug Fixes * **registration-block:** make sure font-family in the editor matches front-end ([#1889](#1889)) ([e0c4309](e0c4309)) * use proper variable and escape function for primary color ([#1898](#1898)) ([1062b1a](1062b1a)) ### Features * add custom style for upcoming registration pattern (style 1) ([#1888](#1888)) ([58f303d](58f303d)) * Add featured listing styles ([#1877](#1877)) ([efc4936](efc4936)) * colors' css variables and action hook for mobile toggle ([#1875](#1875)) ([0830ca7](0830ca7)) * redesign "My Account" page ([#1879](#1879)) ([9258f21](9258f21))
|
🎉 This PR is included in version 1.63.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |


All Submissions:
Changes proposed in this Pull Request:
This PR introduces root CSS variables for the theme's colors and 2 action hooks placed before and after the header mobile menu toggle.
How to test the changes in this Pull Request:
Further details and instructions at Automattic/newspack-plugin#1754
Other information: