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

[CSS-in-JS] Global style reset with emotion #5122

Merged
merged 39 commits into from
Oct 6, 2021

Conversation

thompsongl
Copy link
Contributor

@thompsongl thompsongl commented Sep 1, 2021

Summary

Replacing the Sass global reset file with a 1:1 conversion using Global from @emtion/react
Enabled in the docs; try to find any differences as compared to the production site 🕵️

Diff of the CSS vs. emotion output can be seen in this gist. Note that there are prefixing differences because emotion uses stylis for preprocessing.

This PR also changes the isDefaultTheme utility to isLegacyTheme.

Checklist

  • Check against all themes for compatibility in both light and dark modes

- [ ] Checked in mobile

  • Checked in Chrome, Safari, Edge, and Firefox

- [ ] Props have proper autodocs and playground toggles
- [ ] Added documentation

- [ ] Added or updated jest tests

  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes

- [ ] A changelog entry exists and is marked appropriately


// Our base fonts

export const useEuiFont = () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking that we should also provide non-hook versions of these utilities that do not use useEuiTheme directly, but accept a theme parameter. This style of hook can then just consume that function and layer on context awareness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I still think this is a good idea, but I'm going to do a follow-up PR because there are several other hooks that could use the same two-step treatment.

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

Comment on lines 26 to 27
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
Copy link
Contributor Author

@thompsongl thompsongl Sep 9, 2021

Choose a reason for hiding this comment

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

@kibanamachine
Copy link

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

@thompsongl
Copy link
Contributor Author

thompsongl commented Sep 9, 2021

Notable omissions from the diff gist:

@cchaos
Copy link
Contributor

cchaos commented Sep 9, 2021

Still researching missing font-family values

Because I removed those 😆 and reduced the font-family stack to a much smaller, necessary stack.

@thompsongl
Copy link
Contributor Author

Because I removed those 😆 and reduced the font-family stack to a much smaller, necessary stack.

Oh wow good thing I haven't actually spent any time looking into yet, then 😌

@kibanamachine
Copy link

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

@thompsongl
Copy link
Contributor Author

Opening this up for review. @cchaos let's decide what to do with the various variables that don't (yet) exist in the JS theme that the global file relies on.

@thompsongl thompsongl marked this pull request as ready for review September 10, 2021 14:46
@kibanamachine
Copy link

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

@cchaos
Copy link
Contributor

cchaos commented Sep 14, 2021

Issues

I'm just documenting issues as I'm finding them in the diff (I haven't looked at the new reset file yet), not delegating anyone to fix unless you know how to.

1. The compile order is now backwards. It seems the reset is coming in after the component styles.

This is clear in the example of input focus rings.

Correct
Screen Shot 2021-09-14 at 13 06 33 PM

Incorrect (this PR)
Screen Shot 2021-09-14 at 13 06 44 PM

2. Shouldn't be converting colors from hex to RGB

This is apparent in the Diff (but I see different results in the Dev Console locally).

Screen Shot 2021-09-14 at 13 04 10 PM

I think we'll need to add .hex() to any colors we want in hex. Chroma deals in rgba (from @thompsongl)

We may want to think on this one a bit then...

3. Stripping out quotes from font-family 👍

Outdated This is also happening in the Diff but not locally. But certain font families require the quotes to ensure it's finding the right one. I don't think this conversion is going to work as expected. Screen Shot 2021-09-14 at 13 11 31 PM

4. Using calcs for negative values 👍

Outdated Not sure if this is truly an issue, but just an oddity to point out. We should maybe look into the performance between straight values and `calc()`. Screen Shot 2021-09-14 at 13 15 51 PM

5. stylis seems to be wrong right with its prefixing 🤦‍♀️

Outdated For example `::-moz-selection` is absolutely necessary. Compare:

Correct
Screen Shot 2021-09-14 at 13 25 42 PM

Incorrect (this PR)
Screen Shot 2021-09-14 at 13 25 39 PM

Another example is checking for experimental flags like content: none which is apparently not supported by any browser, yet it removed the previous content: '' because it just saw two duplicate properties.

Screen Shot 2021-09-14 at 13 31 05 PM

6. Linter vs compiled CSS

This is just an observation, not necessarily an issue, but it looks like it will convert single quotes to double, but our Sass linter requires single quotes, so it just feels odd that we have reverse linter of what gets compiled. The same goes for the appending of px to 0 values.

Screen Shot 2021-09-14 at 13 29 38 PM

@kibanamachine
Copy link

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

@thompsongl
Copy link
Contributor Author

The compile order is now backwards. It seems the reset is coming in after the component styles.

Not entirely sure how to solve this one yet. Now that the global styles are injected after the static css file loads, we may need something like CacheProvider to specify where to inject the globals (i.e., before the static file). Note that this will not be a problem once EUI components are converted; global styles are always injected before non-global styles when done via Emotion.

cchaos added 5 commits September 14, 2021 15:17
Default will mean something different when Amsterdam becomes default so I want to head this off now by checking for “Legacy”
@kibanamachine
Copy link

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

@thompsongl
Copy link
Contributor Author

though one last think you might want to check is the TS by changing the app_view.js to .tsx

Looking at this but the imported png files cause the build to break

…in-js/reset

# Conflicts:
#	src-docs/src/views/app_view.js
#	src/global_styling/index.scss
#	src/themes/eui-amsterdam/global_styling/index.scss
@cchaos
Copy link
Contributor

cchaos commented Sep 30, 2021

We don't have to actually keep it converted to TS, i just wanted you to check the provider in a TS file. When I converted I was getting a TS error around the Provider. But as I just tried again, I'm not seeing one.

@thompsongl
Copy link
Contributor Author

Oh I see. No TS errors regarding Providers in that file.

@kibanamachine
Copy link

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

@thompsongl
Copy link
Contributor Author

thompsongl commented Oct 5, 2021

Added docs for EuiProvider, although the location is an afterthought at this point. Will likely refactor after #5227 and after a decision is made on the location of EuiThemeProvider (likely moves from services/ to components/).

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@thompsongl
Copy link
Contributor Author

The main CI job succeeded but the docs deployment is stuck. Merging without running again.

@thompsongl thompsongl merged commit 3b60df7 into elastic:css-in-js/breaking Oct 6, 2021
thompsongl added a commit that referenced this pull request Nov 30, 2021
* emotion as peerDep; babel and typescript

* jest config

* isDefaultTheme util

* CL TODO

* update snapshots

* [CSS-in-JS] [Breaking] Deprecating EUI theme to Legacy (#5222)

* [CSS-in-JS] Global style reset with `emotion` (#5122)

* global reset with emotion

* amsterdam overrides

* text-size-adjust

* ams reset

* invert ::selection

* Renamed `isDefaultTheme` utility to `isLegacyTheme`

Default will mean something different when Amsterdam becomes default so I want to head this off now by checking for “Legacy”

* Quick cleanup

* Fixed up scrollbar function

* Removed `useEuiFont` in favor of a single reset on the elements that need it

* Added `body` key to global `font` for setting base body font settings at the global level

* Some more fixes based on new diff

* global reset with emotion

* amsterdam overrides

* text-size-adjust

* ams reset

* invert ::selection

* Renamed `isDefaultTheme` utility to `isLegacyTheme`

Default will mean something different when Amsterdam becomes default so I want to head this off now by checking for “Legacy”

* Quick cleanup

* Fixed up scrollbar function

* Removed `useEuiFont` in favor of a single reset on the elements that need it

* Added `body` key to global `font` for setting base body font settings at the global level

* Some more fixes based on new diff

* Pulling our reset from global styles

* SVG `hacks` directly in reset file

* Fixed reset import

* euiprovider; reset styles

* use euiprovider with emotion/cache in docs

* Decision clean up

* Fixing a few things for legacy dark mode based on not having a provider

* Revert "Fixing a few things for legacy dark mode based on not having a provider"

This reverts commit 127f12e.

* Actually keeping `colorMode` even if `theme = null`

* Fixing merge

* Moved reset sass folder to `legacy`

* fix wiki

* euiprovider docs

* fix provider docs

* remove commented import

Co-authored-by: cchaos <[email protected]>

* [CSS-in-JS] Add provider to generated codesandbox examples (#5253)

* add provider to generated codesandbox examples

* indentation

* euithemeprovider -> euiprovider

* legacy theme

* fix snapshot tests

* [CSS-in-JS] Provider for fullscreen examples; Context refactor (#5309)

* refactor to extract context component

* refactor for fewer updates on route changes

* refactor AppView to function component

* [CSS-in-JS] [Breaking] Better Getting Started page (#5299)

* Moved all color Sass files to their respective theme folders
- Duplicates variables, but makes it actually capable of customization
- New files for code & vis colors that weren’t theme specific
* Remove outdated theming wiki page
* Cleanup (in MD files too)

* fix heading level

* update changelog page regex to fully remove the master section

* manual merge

* update release script changelog regex

* Cleanup some docs

* Hide LanguageSelector tour on Getting Started page

* Some GS page cleanup

* PR feedback

* cl

* Apply suggestions from code review

Co-authored-by: Constance <[email protected]>

* lint fix

* make amsterdam default

* provider updates

* fix cypress styles

* PR feedback:

- Removed blank mixins file
- Added `yarn add` block for dependencies
- Added props table to bottom of Provider docs page

* move keydown inside useeffect

* Reusing correct Sass customization snippet under Customizing

* fix cypress path

* update export

Co-authored-by: Caroline Horn <[email protected]>
Co-authored-by: cchaos <[email protected]>
Co-authored-by: Constance <[email protected]>
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.

4 participants