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

[EuiSpacer] Converts EuiSpacer to Emotion #5812

Merged
merged 13 commits into from
Apr 20, 2022
Merged

Conversation

snide
Copy link
Contributor

@snide snide commented Apr 19, 2022

Summary

Converts EuiSpacer to emotion.

Video diff
https://snid.es/2022APR/Glcc87PjPKbXzX92.mp4

Checklist

  • Checked 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
  • Checked Code Sandbox works for any docs examples
  • Added or updated jest and cypress tests
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • Updated the Figma library counterpart
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

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

@snide snide changed the title [DRAFT] Converts spacer to Emotion Converts spacer to Emotion Apr 19, 2022
@snide snide marked this pull request as ready for review April 19, 2022 15:43
@snide snide mentioned this pull request Apr 19, 2022
49 tasks
@snide snide changed the title Converts spacer to Emotion Converts EuiSpacer to Emotion Apr 19, 2022
@snide snide changed the title Converts EuiSpacer to Emotion [EuiSpacer] Converts EuiSpacer to Emotion Apr 19, 2022
@kibanamachine
Copy link

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

@cee-chen
Copy link
Member

cee-chen commented Apr 19, 2022

Adding QA checklist specific to CSS-in-JS conversions:

Things to look out for when moving styles

- [ ] Anything in the backlog that could be a quick fix for that component?

  • Convert global Sass vars to JS version like sizing

- [ ] Convert component-specific Sass vars to exported JS versions
- [ ] Convert side specific padding, margin, and position to -inline and -block (Logical properties)
- [ ] Reduce specificity where possible (usually by reducing class name chaining)
- [ ] Use gap property to add margin between items if using flex
- [ ] Can any still existing .js files be converted to TS?

QA

  • Do className, css, and style props work properly when passed by the consumer
  • Does the rendered class read as expected

@cee-chen
Copy link
Member

Looks like there's a couple downstream snapshots that need to be updated - LMK if you're still updating this PR @snide or if you want me to grab it!

@snide
Copy link
Contributor Author

snide commented Apr 19, 2022

@constancecchen ty. Updated (I think I got them, EuiContextMenu continues to be a little flakey for me and failed locally)

@cee-chen
Copy link
Member

I'm investigating the EuiContextMenu flaking in a separate PR btw 🤞

return <div className={classes} {...rest} />;
const cssStyles = [styles.euiSpacer, styles[size]];

return <div className={classes} css={cssStyles} {...rest} />;
Copy link
Member

Choose a reason for hiding this comment

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

Per the #5685 (comment) checklist, do we want to add a renderWithStyles() test to spacer.test.tsx? See the EuiMark example:

describe('EuiMark', () => {
renderWithStyles(<EuiMark>Marked</EuiMark>);

Copy link
Contributor

Choose a reason for hiding this comment

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

@constancecchen in that comment also mentions adding shouldRenderCustomStyles. Is that correct?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah! I just added that helper yesterday after I made this comment. We would want both (or just 1, if/when we decide to get renderWithStyles either fixed or removed)

@kibanamachine
Copy link

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

@@ -1,18 +0,0 @@
$spacerSizes: (
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like 10 instances in Kibana are targeting this map from the converted JSON. How would we like to handle that upgrade process?

Copy link
Member

Choose a reason for hiding this comment

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

try not to cry

In all seriousness, we'd probably convert over directly to theme.eui.euiSize{size} similar to what I did here: elastic/kibana@64651f1

Copy link
Contributor

Choose a reason for hiding this comment

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

For @snide to explain, why we can't have the consumers now import from euiSpacerStyles

Current:

padding: ${(props) => props.theme.eui.spacerSizes.xl};

which evaluated essentially to:

padding: $euiSizeXXL;

which rendered as:

padding: 40px

If they tried to grab the emotion styles

euiSpacerStyles(euiTheme)[xxl]

They get a string:

'height: 40px;'

So they can't do:

padding: ${euiSpacerStyles(euiTheme)[xxl]};

as it would render as:

padding: height: 40px;

Copy link
Contributor

@cchaos cchaos Apr 19, 2022

Choose a reason for hiding this comment

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

In this specific component's case, it's actually quite an easy conversion as the spacers were exactly mapped to the same named size variable. So they easily just not import from Spacer but just the global sizing variable instead.

Others may not be so easy, and may depend on how exactly they're trying to match components.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK I wrote up some explanation here. Ultimately this will remain tricky, but at least it's something we can point to. @cchaos can you give it a read to see if it reads clear?

5781933

@kibanamachine
Copy link

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

@cchaos
Copy link
Contributor

cchaos commented Apr 19, 2022

I pushed a quick fix to the docs:
Screen Shot 2022-04-19 at 16 11 05 PM

@kibanamachine
Copy link

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

@cchaos
Copy link
Contributor

cchaos commented Apr 19, 2022

Wait.. is this right??
Screen Shot 2022-04-19 at 16 52 14 PM

upcoming_changelogs/5812.md Outdated Show resolved Hide resolved
@cee-chen
Copy link
Member

cee-chen commented Apr 19, 2022

Wait.. is this right??

Yes, it's correct. the EuiMarkDown snapshot was unnecessary and was removed in favor of an assertion. I copied the same approach Chandler took in #5815

@kibanamachine
Copy link

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

@kibanamachine
Copy link

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

Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>
wiki/consuming.md Outdated Show resolved Hide resolved
@kibanamachine
Copy link

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

Co-authored-by: Elizabet Oliveira <elizabet.oliveira@elastic.co>
wiki/consuming.md Show resolved Hide resolved
wiki/consuming.md Show resolved Hide resolved
@kibanamachine
Copy link

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

snide and others added 2 commits April 20, 2022 15:43
Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>
Co-authored-by: Caroline Horn <549577+cchaos@users.noreply.github.com>
@snide
Copy link
Contributor Author

snide commented Apr 20, 2022

@cchaos Good suggestions. I think we're good to go now?

@kibanamachine
Copy link

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

@snide snide merged commit 810c0a0 into elastic:main Apr 20, 2022
@snide snide deleted the emotion_spacer branch April 20, 2022 22:28
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.

5 participants