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

[Emotion] Convert Sass typography mixins to JS #5854

Merged
merged 18 commits into from
May 3, 2022

Conversation

cee-chen
Copy link
Member

@cee-chen cee-chen commented Apr 28, 2022

Summary

For QA, please see: https://eui.elastic.co/pr_5854/#/utilities/text

For code review, I recommend following along by commit.

What this PR does:

  • Converts all remaining Sass mixins in _typography.scss to JS
    • In the case of the euiTextShift, this was moved to functions/typography.ts and not mixins/_typography.ts as it's mostly an internal-only util
  • Adds documentation snippets for both Emotion and Sass mixins for consumer usage (Sass mixins were previously not documented alongside the CSS classes)

What this PR does not do:

  • Convert any components currently using the Sass mixins
  • Delete the old Sass mixins - that will be done all at once at a later period

Checklist

Not sure if a changelog is needed here Sass mixins were not previously documented - thoughts?

@cee-chen cee-chen requested a review from cchaos April 28, 2022 20:59
@cee-chen cee-chen marked this pull request as ready for review April 28, 2022 21:00
@@ -64,7 +64,7 @@ export const useEuiTitle = (
*/
export const euiTitleStyles = ({ euiTheme }: UseEuiTheme) => ({
euiTitle: css`
${euiTextBreakWord}
${euiTextBreakWord()}
Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up converting this into a function to match other mixin usages. From a JS perspective I think it makes 'mixin' usage a bit clearer

src-docs/src/views/text_utilities/wrapping.tsx Outdated Show resolved Hide resolved
@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Thanks for doing all these conversions and adding tests. Lots of comments, but mostly repetitive stuff around language and just a few comments about the mixins themselves.

src/global_styling/mixins/_typography.ts Outdated Show resolved Hide resolved
src/global_styling/mixins/_typography.ts Outdated Show resolved Hide resolved
src/global_styling/mixins/_typography.ts Show resolved Hide resolved
src/global_styling/mixins/_typography.test.ts Outdated Show resolved Hide resolved
src/global_styling/functions/typography.ts Outdated Show resolved Hide resolved
Comment on lines 71 to 73
export const euiNumberFormat = () => `
font-feature-settings: 'calt' 1, 'kern' 1, 'liga' 1, 'tnum' 1;
`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is actually an opprtunity to merge global styles. We have euiTheme.font.featureSettings which is set to 'calt' 1, 'kern' 1, 'liga' 1. In sass, there wasn't a good way to merge these, but here we can make this a hook and append just the 'tnum' 1 portion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah fantastic, I totally missed that variable!

Copy link
Member Author

Choose a reason for hiding this comment

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

65517bf

Making the mixin use euiTheme now requires euiTheme as an arg, so I ended up making a hook version of this and documenting the hook version instead. I'd be curious to hear your thoughts on whether documenting both hook and non hook mixins feels confusing.

src-docs/src/views/text_utilities/numbers.tsx Outdated Show resolved Hide resolved
src-docs/src/views/text_utilities/numbers.tsx Outdated Show resolved Hide resolved
description={
<p>
Changes the element’s text alignment property to{' '}
<EuiCode language="sass">text-align: left;</EuiCode>
Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized we need to be changing these all to logical properties. 😬

Copy link
Contributor

Choose a reason for hiding this comment

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

I would still keep the name of the thing as left and right, but the output should be logical.

Copy link
Member Author

Choose a reason for hiding this comment

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

As in I should be changing this in Sass itself? Could we maybe wait until we convert our Sass-only text utils to CSS-in-JS globals before doing this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry no, I didn't realize this PR didn't contain the JS version of the Sass utility. When we do convert the pure utility, we need to make sure output uses the logical properties. Then in this description, instead of explicitly saying what the output style is, we'd just say something like:

Suggested change
<EuiCode language="sass">text-align: left;</EuiCode>
be aligned to the left (starting) side of its container.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ahh gotcha! Makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

I made that documentation tweak while here since I figured it was easy enough - LMK if you'd rather revert/wait until we tackle Sass/Emotion globals b4d2c2d

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

An optional idea.

src-docs/src/views/text_utilities/wrapping.tsx Outdated Show resolved Hide resolved
src-docs/src/views/text_utilities/wrapping.tsx Outdated Show resolved Hide resolved
@cee-chen
Copy link
Member Author

cee-chen commented May 2, 2022

@cchaos by the way, any thoughts on whether this PR needs a changelog? I'm unsure as Sass mixins were previously undocumented.

@cee-chen cee-chen requested a review from cchaos May 2, 2022 17:30
@kibanamachine
Copy link

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

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

@constancecchen , Yes it needs a changelog stating these new additions. It doesn't need to be under the conversion header. Just something like

Add euiNumberFormat(), ..., ... text utilities.

@kibanamachine
Copy link

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

@cee-chen cee-chen requested a review from cchaos May 3, 2022 16:36
Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

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

Looks great to me!

@cee-chen cee-chen merged commit 0bbacf0 into elastic:main May 3, 2022
@cee-chen cee-chen deleted the emotion/text-utilities branch May 3, 2022 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants