Skip to content
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

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

Merged
merged 7 commits into from
Sep 5, 2023

Conversation

cee-chen
Copy link
Member

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

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 and others added 3 commits August 30, 2023 09:41
…variable (#7144)

Co-authored-by: Trevor Pierce <1Copenut@users.noreply.github.com>
Co-authored-by: Trevor Pierce <1Copenut@users.noreply.github.com>
@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

Preview documentation changes for this PR: https://eui.elastic.co/pr_7151/

@cee-chen
Copy link
Member Author

cee-chen commented Sep 1, 2023

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

Copy link
Contributor

@1Copenut 1Copenut left a comment

Choose a reason for hiding this comment

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

👍 LGTM!

@@ -126,14 +126,14 @@ const euiOverflowShadowStyles = (
* Others like Safari, won't show anything at all.
*/
interface _EuiYScroll {
height?: CSSProperties['height'];
height?: CSSProperties['height'] | false;
Copy link
Member

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
Member 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 }} />
Copy link
Member

@tkajtoch tkajtoch Sep 1, 2023

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
Member 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?

Copy link
Member Author

@cee-chen cee-chen Sep 5, 2023

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

Copy link
Member Author

@cee-chen cee-chen Sep 5, 2023

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
Member 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

Copy link
Member

@tkajtoch tkajtoch left a comment

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 🎉

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_7151/

@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
7 checks passed
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants