Skip to content

[Emotion] Convert global className utilities - #6124

Merged
cee-chen merged 10 commits into
elastic:mainfrom
cee-chen:global-utils
Aug 16, 2022
Merged

cee-chen merged 10 commits into
elastic:mainfrom
cee-chen:global-utils

Conversation

@cee-chen

@cee-chen cee-chen commented Aug 11, 2022 •

Copy link
Copy Markdown
Contributor

Summary

I strongly recommend following along by commit, as I did a few extra side cleanup items (missing logical properties, mixin API updates, documentation) alongside the global conversions.

Checklist

  • Checked in both light and dark modes
  • Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Added documentation
  • Added or updated jest and cypress tests
  • Checked for breaking changes and labeled appropriately (this PR deliberately has no breaking changes / does not (yet) remove the IE utility - will be addressing that in a follow-up PR)
  • A changelog entry exists and is marked appropriately

- [ ] Props have proper autodocs and playground toggles
- [ ] Checked Code Sandbox works for any docs examples
- [ ] Checked for accessibility including keyboard-only and screenreader modes
- [ ] Updated the Figma library counterpart

@cee-chen cee-chen changed the title [Emotion] Convert global className utils [Emotion] Convert global className utilities Aug 11, 2022
+ fix missing CSS logical property on text truncation mixin
+ convert textLeft/Right to logical CSS
- note that we can't use the logicalTextAlign util for this as !important can't be passed to that util
@cee-chen
cee-chen force-pushed the global-utils branch 3 times, most recently from a2c7201 to 2b68854 Compare August 11, 2022 01:13
@cee-chen
cee-chen marked this pull request as ready for review August 11, 2022 01:17
@cee-chen
cee-chen requested a review from elizabetdev August 11, 2022 01:17
Comment thread src/global_styling/utility/utility.tsx Outdated
Comment on lines +34 to +38
.eui-isFocusable:focus {
// Forcing focus ring on non-EUI elements
${euiFocusRing(euiThemeContext)}
}

@cee-chen cee-chen Aug 11, 2022 •

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.

Question: is this global utility still valid? I'm not seeing any uses either in Kibana or EUI, and I feel like our *:focus reset should basically already covers this:

*:focus {
${euiFocusRing(euiThemeContext)}
}

Thoughts?

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.

It seems that it was being used in an old version of EUI: https://github.com/lcawl/eui/blob/8073430a578673eb9944c20cc39ef0752c9aadc4/src-docs/src/views/guidelines/colors/core_palette.js#L51.

I couldn't find any uses in Kibana and in recent versions of EUI. So I would say it's safe to delete.

@cee-chen cee-chen Aug 16, 2022 •

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.

Fantastic, I'll go ahead and delete it. Thanks @miukimiu!!

edit: 626c66f

@kibanamachine

Copy link
Copy Markdown
Contributor

+ convert euiFullHeight Sass mixin to Emotion

+ move @mixin euiFullHeight to `mixins/_helpers` instead of living in `_utility`
- since that's where the className was documented
- this requires adding a new `logicalCSSWithFallback` util, since overflow-inline/block is not yet supported on non-FF browsers

+ fix incorrect overflow mapping - inline should be x and block should be y
+ convert mixin to accept the entire euiThemeContext instead of just the euiTheme to match all other mixins
@kibanamachine

Copy link
Copy Markdown
Contributor

@kibanamachine

Copy link
Copy Markdown
Contributor

@cee-chen
cee-chen requested a review from breehall August 15, 2022 15:48
@cee-chen

Copy link
Copy Markdown
Contributor Author

Hey @breehall! If you have a time this week, do you mind helping code review this PR? Thank you!

@elizabetdev elizabetdev 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.

Thanks for converting these global className utilities. LGTM! 🎉

page: css`
&:is(a):focus {
${euiFocusRing(euiTheme, 'inset')};
${euiFocusRing(euiThemeContext, 'inset')};

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.

Much better! 🥳

${logicalCSS('max-height', '100vh')}; /* 1 */
overflow-y: auto; // Fallback for the 'overflow-inline' logical property, which is not yet supported
${logicalCSS('overflow-y', 'auto')};
${logicalCSSWithFallback('overflow-y', 'auto')};

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.

That's a great idea. 🥳

second parameter <EuiCode>mask</EuiCode>.
</p>
<p>
<EuiCode>{"useEuiOverflowScroll('x', true);"}</EuiCode>

@elizabetdev elizabetdev Aug 16, 2022 •

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.

Something that we need to decide as a team. We normally document the hooks instead of the function versions. But I use much more functions than hooks. Why? Because in component.styles.ts we can't use hooks.

If we search for useEuiShadow we find 0 usages in EUI. But euiShadow is being used multiple times. So I wonder if we should be documenting both functions and hooks or prefer documenting the functions rather than hooks.

@cee-chen cee-chen Aug 16, 2022 •

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.

Our docs are consumer facing, so we document the hooks because we expect consumers to be using hooks more than passing our euiThemeContext around. Internally in EUI we pass our theme around a lot, but consumers are much less likely to do so, so they'll probably just want a hook that handles getting the theme for them.

TBH, this is kind of an architectural choice we made too when setting up our Emotion styles pattern. We could have decided to make all our styles files/functions hooks instead, e.g. useEuiComponentStyles() which then allows us to call hook utils of all our styles instead of having to pass euiTheme around manually. But then hooks can't be called conditionally or in callbacks, so there's pros/cons to everything.

cc @thompsongl for more thoughts

${logicalCSS('width', '100% !important')}
}
.eui-fullHeight {
${euiFullHeight()}

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.

This is something that I never know... When we're calling functions should we end the line with semicolons?

@cee-chen cee-chen Aug 16, 2022 •

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.

Most of our functions are already fully fledged CSS line(s) and contain their own ending semicolon, so I remove the extra semicolon after use because it's unnecessary (although Emotion/CSS is smart enough to ignore extra semicolons).

A few functions do not have the trailing semicolon (although that's not common) so those will need it. Essentially It depends on the function; you may have to right click / trace the function to check its output.

+ already being handled by global reset
@kibanamachine

Copy link
Copy Markdown
Contributor

@cee-chen

Copy link
Copy Markdown
Contributor Author

@breehall Sorry for the whiplash, I'm going to go ahead and merge this PR after CI passes since there's another PR that relies on it (#6125). Please feel free to review if you want - I can address any questions/feedback in a follow-up PR!

@cee-chen
cee-chen enabled auto-merge (squash) August 16, 2022 16:40
@cee-chen
cee-chen merged commit 6d91a09 into elastic:main Aug 16, 2022
@cee-chen
cee-chen deleted the global-utils branch August 16, 2022 16:57
@cee-chen cee-chen mentioned this pull request Sep 21, 2022
49 tasks done
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.

3 participants