Skip to content

[EuiHeader] Set up CSS variable for fixed header affordance; [Emotion] Set up CSS variable architecture - #7151

Merged
cee-chen merged 7 commits into
mainfrom
theme-css-variables
Sep 5, 2023
Merged

cee-chen merged 7 commits into
mainfrom
theme-css-variables

Conversation

@cee-chen

@cee-chen cee-chen commented Sep 1, 2023 •

Copy link
Copy Markdown
Contributor

Summary

This is a feature branch merge. Please see the below constituent PRs for more information:

QA

General checklist

  • Checked in Chrome, Safari, Edge, and Firefox
  • Added documentation
  • Added or updated jest and cypress tests
  • Checked for breaking changes and labeled appropriately
  • [ ] A changelog entry exists and is marked appropriately Skipping for feature branch merge, changelogs for individual PRs were included

@cee-chen cee-chen added the skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation) label Sep 1, 2023
@cee-chen
cee-chen marked this pull request as ready for review September 1, 2023 16:47
@cee-chen
cee-chen requested a review from a team September 1, 2023 16:47
@kibanamachine

Copy link
Copy Markdown
Contributor

@cee-chen
cee-chen requested a review from tkajtoch September 1, 2023 19:04
@cee-chen

cee-chen commented Sep 1, 2023

Copy link
Copy Markdown
Contributor Author

@tkajtoch has expressed an interest in reviewing this feature before it merges in, so going to hold for his thoughts before merge!

@1Copenut 1Copenut left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 LGTM!

Comment thread src/global_styling/mixins/_helpers.ts Outdated
*/
interface _EuiYScroll {
height?: CSSProperties['height'];
height?: CSSProperties['height'] | false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure if I like having false as the magic value here. null isn't better, undefined defaults to 100% (but so does 0 which may not be expected). What about inherit though? It's a real CSS value and it means almost exactly what our implementation does.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Very fair! I reverted the euiYScroll change in 4f08b9a, and simply passed the height calc directly to the function (not sure why that didn't occur to me as opposed to overriding via CSS haha).

edit: I pushed up too early, you were also totally right that height: inherit works perfectly and saves us a calc()! 🎉 I've updated both the collapsible nav and flyout styles accordingly: d2e834c

</EuiColorModeContext.Provider>
<>
{isGlobalTheme && themeCSSVariables && (
<Global styles={{ ':root': themeCSSVariables }} />

@tkajtoch tkajtoch Sep 1, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:root won't work inside Shadow DOM because :root pseudoclass targets Document (<html>, <svg> tags) and not DocumentFragment that Shadow DOM uses. We should probably do one of two things if we want to address it in this PR:

  1. Add shadowDom: boolean prop and use :host instead of :root when true
  2. Automatically detect if EUI is used inside Shadow DOM by node.getRootNode() instanceof ShadowRoot (would require getting a ref)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks a million for catching this Tomasz! Just curious, could we simply target both via something like this:

:root,
:host {
  /* ... CSS variables */
}

And let CSS determine for us if :host/:root does or doesn't apply?

@cee-chen cee-chen Sep 5, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Disregard the above, it breaks a lot and CSS gets very confused 😅 Disregard this, it's Emotion that's confused

@cee-chen cee-chen Sep 5, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright, so even if I change the the selector to just :host, this currently won't work as-is with Shadow DOM because Emotion is still injecting the styles into the global <head> as opposed to the shadow container/host. Either way our current Emotion setup doesn't work in shadow DOM, period, and will need a lot of adjustment (at both the theme, provider, and Emotion level) to account for this.

@tkajtoch I'm going to move ahead with merging this PR as-is since full working shadow DOM support is going to be its own effort, and I don't think we should block the majority of current consumers benefiting from this work for a small subsection of consumers (when shadow DOM currently doesn't work in prod in any case).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Follow-up issue: #7158

@tkajtoch tkajtoch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I added a couple of comments, but overall it's a huge step in the right direction. Thank you for your work on this!

useEuiThemeCSSVariables and these CSS variables setter functions are great! Such a neat idea to implement it this way 🎉

@cee-chen
cee-chen force-pushed the theme-css-variables branch from da1e557 to d2e834c Compare September 5, 2023 20:46
@kibanamachine

Copy link
Copy Markdown
Contributor

@cee-chen
cee-chen enabled auto-merge (squash) September 5, 2023 21:29
@cee-chen
cee-chen merged commit 829709e into main Sep 5, 2023
@elasticmachine

Copy link
Copy Markdown
Collaborator

💚 Build Succeeded

History

@cee-chen
cee-chen deleted the theme-css-variables branch September 5, 2023 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emotion skip-changelog Use on PRs to skip changelog requirement (Don't delete - used for automation)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants