Skip to content

Conversation

@heyMP
Copy link
Contributor

@heyMP heyMP commented Apr 19, 2022

Problem / Solution

This illustrates how to tie the legacy CSS vars for pfe-cta into the new color context controller --pfe-context-background-color: var(--pfe-cta--BackgroundColor);

The _sharedStyles.scss generates all of the color-palette and priority overrides via css custom properties. Since the color context provider sets background-color and only background-color, we have to specifically use that custom property to override background-color.

color-context.scss

:host(:is([color-palette])) {
  background-color: var(--pfe-context-background-color, var(--pfe-theme--color--surface--base));
}

Alternatives

Related issues

Preview

Link(s) to demo page(s) where this element can be viewed:

What has changed and why

Testing instructions

Browser requirements

Your component should work in all of the following environments:

  • Latest 2 versions of Edge
  • Internet Explorer 11 (should be useable, not pixel perfect)
  • Latest 2 versions of Firefox (one on Mac OS, one of Windows OS)
  • Firefox 78 (or latest version for Red Hat Enterprise Linux distribution)
  • Latest 2 versions of Chrome (one on Mac OS, one of Windows OS)
  • Latest 2 versions of Safari
  • Android mobile device (such as the Galaxy S9)
  • Apple mobile device (such as the iPhone X)
  • Apple tablet device (such as the iPhone Pro)

Ready-for-merge Checklist

  • Expected files: all files in this pull request are related to one request or issue (no stragglers or scope-creep).
  • Tests have been updated to cover these changes.
  • Browser testing passed.
  • Changelog updated.
  • Documentation (README.md, WHY.md, etc.) updated or added.
  • Link to the demo recording:
  • Approved by designer.

Merging

Please squash when merging and ensure your commit message uses conventional commit formatting.

Be sure to share your updates with the [email protected] mailing list!

@heyMP heyMP added the styles An issue or PR pertaining only to CSS/Sass label Apr 19, 2022
@changeset-bot
Copy link

changeset-bot bot commented Apr 19, 2022

🦋 Changeset detected

Latest commit: 814e5f8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@patternfly/pfe-cta Patch
@patternfly/pfe-tools Minor
@patternfly/pfe-core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the demo Updating demo pages label Apr 19, 2022
@heyMP heyMP requested a review from zeroedin April 19, 2022 13:17
@github-actions github-actions bot added the AT passed Automated testing has passed label Apr 19, 2022
@netlify
Copy link

netlify bot commented Apr 25, 2022

Deploy Preview for patternfly-elements ready!

Name Link
🔨 Latest commit 814e5f8
🔍 Latest deploy log https://app.netlify.com/sites/patternfly-elements/deploys/626a4dae768828000976b16a
😎 Deploy Preview https://deploy-preview-2006--patternfly-elements.netlify.app/blog/pfe-2-0-prerelease
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@bennypowers
Copy link
Member

I pushed some commits which fix up the context variables for CTA by explicitly defining them. Is is the prettiest code? No. However I'd prefer not to dwell on it, since I'm fixing to refactor this CSS at some point anyway. It would be nice to add some regression tests on this branch once we reach consensus (through manual testing) that it passes acceptance criteria.

I haven't yet addressed the custom --context div wrapper, will tackle that next.

I tested this by running two separate dev servers, one with commit c10f678 checked out (i.e. before the context refactor) and one with this branch checked out.

In these screenshots, the left hand side is the old, pre-refactor version, and the right hand side is the PR branch
Screen Shot 2022-04-25 at 11 46 49
Screen Shot 2022-04-25 at 11 47 04

@bennypowers
Copy link
Member

bennypowers commented Apr 25, 2022

OK the issue with the --context div is that the refactor moved responsibility for deriving the context from the css var to the provider only. This was a performance enhancement as much as it was about simplifying the code. So let's reopen that discussion: Should we stop supporting --context without a provider element?

Opposed:

  • That means changing the pfe-cta demo file, which is another way of saying making a breaking change to our acceptance criteria
  • There may be cases of such 'in the wild' which will break (@zhawkins reports that redhat.com does not appear to use --context as such)

In Favour:

  • --context is not documented on patternflyelements.org
  • Context is JS-only anyways, so we don't lose by doubling down on custom element registration
  • Allows us to simplify context code and improve performance

We could take a compromise position and require on=${intendedContext} in markup.

You'll notice that one of the examples in the demo came with it's own on attr in markup, so perhaps that was the intention?

<pfe-cta on="saturated"><a href="https://www.redhat.com#default">Default</a></pfe-cta>

A fourth option would be to add escape hatches to ContextConsumer for specific cases

Practically speaking...

So, the practical options before us as I see them ATM are:

  1. partially revert context rewrite to support orphaned --context var
  2. decide to stop supporting same and rewrite the demos (per @heyMP)
  3. compromise and require on in markup
  4. add escape hatches to ContextConsumer for cases like this

@zeroedin
Copy link
Contributor

I think the compromise with on might fit the bill here. While it isn't ideal to have to set the attribute individually when used inside a parent that isn't a color context provider, it provides flexibility and performance by not having to need additional js.

@bennypowers
Copy link
Member

Ok, taking @heyMP and @zeroedin 's comments into consideration, what I will do is:

  • explicitly add on to demo examples
  • add theming examples to demo pages which place CTAs on context providers, but customize documented theme vars
  • add regression tests for CTA

There are a few other examples in the repo where --context is set, so i'll examine those, and if I find the same issue there i'll take the same approach

@github-actions github-actions bot added tests Related to testing tools Development and build tools labels Apr 27, 2022
@bennypowers
Copy link
Member

bennypowers commented Apr 27, 2022

@heyMP @zeroedin

  • --context by itself is no longer supported (it was never documented). Authors that want to 'fake' a context should provide both --context and on to each element. And actually, they shouldn't ever do that.
  • on set in HTML now overrides color context for providers. in other words, manually setting on is an escape hatch which opts out of color context calculations. Currently there's no way to later on imperatively opt back in.
    • docs do mention the on attribute, but imply that it is 'behind the scenes'. perhaps we should make this explicit in docs?
    • elsewhere in docs pfe-theme is documented as an override for on, this should be updated, right?
  • adds some test helpers for validating css color strings

compare this PR (https://deploy-preview-2006--patternfly-elements.netlify.app/components/cta/demo/) with an old version (https://deploy-preview-1989--patternfly-elements.netlify.app/components/cta/demo/)

@bennypowers bennypowers force-pushed the fix/cta-styling-color-context-v2 branch from 2646a51 to 814e5f8 Compare April 28, 2022 08:17
@bennypowers bennypowers enabled auto-merge (rebase) April 28, 2022 08:18
Copy link
Member

@bennypowers bennypowers left a comment

Choose a reason for hiding this comment

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

Less griping, tinker more!

@bennypowers bennypowers merged commit 7239cb4 into main Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AT passed Automated testing has passed demo Updating demo pages ready to merge styles An issue or PR pertaining only to CSS/Sass tests Related to testing tools Development and build tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants