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] Convert EuiBreakpoint Mixin to Emotion #6057

Merged
merged 15 commits into from
Jul 20, 2022

Conversation

breehall
Copy link
Contributor

@breehall breehall commented Jul 18, 2022

Summary

Converted the euiBreakpoint mixin to Emotion and created a hook for use within components. Unlike the Sass mixin, the JS mixin allows creating media queries with just (min-width) and (max-width) via the 0 and Infinity args.
Example:
euiBreakpoint(['m', Infinity]) becomes @media only screen and (min-width: 768px)
euiBreakpoint([0, 'm']) becomes @media only screen and (max-width: 767px)

Checklist

…n conditions to allow consumers the flexibility of obtaining a min-width, max-width, or min and max width media query from a variety of different scenarios
@breehall breehall changed the title [Emotion} Convert EuiBreakpoint Mixin to Emotion [Emotion] Convert EuiBreakpoint Mixin to Emotion Jul 18, 2022
@kibanamachine
Copy link

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

@breehall breehall marked this pull request as ready for review July 18, 2022 17:46
@breehall
Copy link
Contributor Author

👋🏾 Hey Greg and Constance, I can go through and clean up some of my comments after the reviews are good. I just wanted to make sure that my thought process matched our goal here. Also, I know the validation might look like a lot, but the more I added conditions to account for 0, infinity, and undefined, I realized there were a few holes.

@breehall breehall changed the title [Emotion] Convert EuiBreakpoint Mixin to Emotion [CSS-in-JS] Convert EuiBreakpoint Mixin to Emotion Jul 18, 2022
@kibanamachine
Copy link

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

Comment on lines 25 to 26
| '0'
| 'infinity'
Copy link
Member

Choose a reason for hiding this comment

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

We should likely be using the numeric version of these for easier type checking:

Suggested change
| '0'
| 'infinity'
| 0
| Infinity

@thompsongl
Copy link
Contributor

Breaking Change
The previous version of euiBreakpoint allowed single element arrays to be passed.

I don't think we need to consider this a breaking change. The previous mixin was written in Sass and this is more of a port than a refactor. Any one choosing to "upgrade" to the JS version will be working with new APIs outside of Sass. Probably worth noting the difference(s) in a code comment in responsive.ts

- Prefer types from theme instead of the breakpoints service (which likely needs to be refactored to use the theme)

- simplify output to use array logic to output/concatenate a string

- Remove undefined type

- improve unit tests:
  - catch console warn conditions
  - don't snapshot invalid/uncommon size combos
@cee-chen
Copy link
Member

cee-chen commented Jul 19, 2022

@breehall I realize I was a little unspecific with what I wanted in the euiBreakpoint 0/Infinity API change, for which I apologize (I also totally did not realize xs was already 0 or that Infinity has Typescript shenanigans 🙈). FWIW, I don't think we need undefined as an arg, just 0/Infinity, which helps simplify checks/testing some.

I've created a local spike that simplifies the checks/warnings as well as adds more specific unit tests. Let me know what you think! If you think it's an improvement, feel free to cherry-pick it in.

FYI, we'll almost certainly want to document this new function in https://elastic.github.io/eui/#/theming/breakpoints/values. There might need to be more updates down the road as src/services/breakpoint.ts currently does not use euiTheme.breakpoints when it likely should, but for now, we should at minimum add useEuiBreakpoints() in there with example usage.

[PR feedback] Simplify branching logic and typing
@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

@cee-chen
Copy link
Member

@thompsongl Any feedback on the revised function/logic?

@breehall I think this is good to move forward with removing the breaking change changelog line and adding documentation to the Breakpoints CSS-in-JS utils!

@thompsongl
Copy link
Contributor

Nope, let's start adding documentation 👍

@breehall
Copy link
Contributor Author

breehall commented Jul 19, 2022

I think this is good to move forward with removing the breaking change changelog line and adding documentation to the Breakpoints CSS-in-JS utils!

@constancecchen Gotcha! I've added documentation to the Breakpoints page in the docs. I only added an entry for the hook because there's no variation between the hook and the function. Part of me would like to see two examples here, but I believe that would break a pattern as no other examples have two code snippets.

@kibanamachine
Copy link

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

@thompsongl
Copy link
Contributor

Part of me would like to see two examples here, but I believe that would break a pattern as no other examples have two code snippets.

Let's add a new entry for the function version. Not just another snippet, but another ThemeExample section and specify that they accept the same arguments.

@kibanamachine
Copy link

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

@cee-chen
Copy link
Member

cee-chen commented Jul 20, 2022

Let's add a new entry for the function version. Not just another snippet, but another ThemeExample section and specify that they accept the same arguments.

@thompsongl I don't think we do this anywhere else, actually. It looks like if a non-hook and a hook util both exist, we document the hook version only (the most likely version for consumers to use, the non-hook version is most likely to only be used internally by EUI). For example, our color utilities: https://eui.elastic.co/pr_6057/#/theming/colors/utilities

breehall and others added 2 commits July 20, 2022 13:23
Co-authored-by: Constance <constancecchen@users.noreply.github.com>
Co-authored-by: Constance <constancecchen@users.noreply.github.com>
@kibanamachine
Copy link

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

@breehall
Copy link
Contributor Author

@constancecchen I'm not sure why I can't respond to the comment about the imports, but as you commented, I just pushed a commit cleaning them up.

@cee-chen
Copy link
Member

Haha sike! Nobody saw that last comment Homer disappearing into a bush

@thompsongl I think this is good to merge on my end - any objections/change requests to the docs?

@kibanamachine
Copy link

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

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

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

Might as well round out the example. Otherwise this all LGTM!

src-docs/src/views/theme/breakpoints/_breakpoints_js.tsx Outdated Show resolved Hide resolved
Co-authored-by: Greg Thompson <thompson.glowe@gmail.com>
@kibanamachine
Copy link

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

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

Successfully merging this pull request may close these issues.

4 participants