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 EuiLink #5856

Merged

Conversation

MichaelMarcialis
Copy link
Contributor

@MichaelMarcialis MichaelMarcialis commented Apr 29, 2022

Summary

This PR converts the majority of the EuiLink component to CSS-in-JS. The only outstanding SCSS is the portion that references the euiFocusRing mixin, which has yet to be converted to Emotion. Once that has been converted, we can go back and remove that last bit of SCSS. TODO comments have been added to echo that statement in the appropriate files.

I did not add a deprecation warning to the global and Amsterdam euiLink mixins, as it is being used by other yet-to-be-converted components in EUI. However, if the deprecation warning should be added regardless, please let me know.

Big thanks to @cchaos for the guidance!

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?
  • [ ] All animations or transitions are wrapped in euiCanAnimate

QA

  • Does the output CSS match the previous CSS / as expected
  • Does the rendered class read as expected

@MichaelMarcialis MichaelMarcialis marked this pull request as ready for review April 29, 2022 21:30
@miukimiu miukimiu self-requested a review May 2, 2022 15:46
@cchaos
Copy link
Contributor

cchaos commented May 2, 2022

@thompsongl Something odd is happening on CI when it's trying to create TS defs on this PR for EuiLink:

12:35:15 Generating typescript definitions file
12:35:15 eui.d.ts(7225,31): error TS2307: Cannot find module '@elastic/eui/src/components/link/' or its corresponding type declarations.

I couldn't find anything specifically that would have affected this in the changeset. Can you take a look?

@MichaelMarcialis MichaelMarcialis self-assigned this May 4, 2022
Copy link
Contributor

@miukimiu miukimiu left a comment

Choose a reason for hiding this comment

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

Thanks, @MichaelMarcialis for doing this conversion.

There are some things that can be improved and I added some suggestions.

I'm just not completely sure about the best way of doing the mixins. @constancecchen or @cchaos can take a look at the mixins to see if they can be improved?

src/components/link/link.tsx Outdated Show resolved Hide resolved
src/components/link/link.tsx Outdated Show resolved Hide resolved
src/components/link/link.tsx Outdated Show resolved Hide resolved
src/global_styling/mixins/_link.ts Outdated Show resolved Hide resolved
src/global_styling/mixins/_link.ts Outdated Show resolved Hide resolved
src/global_styling/mixins/_link.ts Outdated Show resolved Hide resolved
src/components/link/link.styles.ts Outdated Show resolved Hide resolved
src/components/link/link.styles.ts Outdated Show resolved Hide resolved
src/global_styling/mixins/_link.ts Outdated Show resolved Hide resolved
src/components/link/link.styles.ts Outdated Show resolved Hide resolved
@thompsongl
Copy link
Contributor

Something odd is happening on CI when it's trying to create TS defs on this PR for EuiLink

I have an idea, but everything passes locally. So I'm just going to push commits here until it's resolved.

@kibanamachine
Copy link

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

@thompsongl
Copy link
Contributor

10:31:40 Generating typescript definitions file
10:33:06 ✔ Finished generating definitions

6be8eea resolved the CI failure

@MichaelMarcialis
Copy link
Contributor Author

Thanks so much for the detailed review, @miukimiu! Please forgive all my rookie mistakes 😬

I believe I've addressed all your comments, but let me know if I've missed anything. While making these changes, two questions came to mind regarding modifier styles:

  • It looks like we're using a BEM-style naming convention for the child selector styles (block__element), but not for modifier styles (block--modifier). Is that correct?
  • Similarly, we only show examples of declaring child selector styles at the top of the document (as mentioned in your comments). But this is not necessary for modifier styles, right?

Thanks again!

@kibanamachine
Copy link

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

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 @MichaelMarcialis! I found just a couple other things and some nits.

Regarding BEM naming...

As you can see from the snapshot out of the className we don't have to manually apply BEM naming for modifiers:

Which is why we always make sure the name of the component is the first style key, in this case euiLink. Then Emotion will apply the subsequent style keys as -modifier to the className.

css-uj6g16-euiLink-button-colorStyles-accent

The same applies for children. The first key we grab and pass to the children needs to be the euiComponentName__childName so that it's output first as you can see in the external icon use:

class="css-jqzood-euiLink__externalIcon"

upcoming_changelogs/5856.md Outdated Show resolved Hide resolved
src/components/link/link.tsx Show resolved Hide resolved
${colorStyles(euiTheme.colors.primaryText)}
`,
subdued: css`
${colorStyles(euiTheme.colors.subdued)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not to self, I think this token name should change to subduedText to be explicit.

src/global_styling/mixins/index.ts Outdated Show resolved Hide resolved
src/components/link/link.tsx Outdated Show resolved Hide resolved
src/components/link/link.styles.ts Outdated Show resolved Hide resolved
src/components/link/link.styles.ts Outdated Show resolved Hide resolved
src/components/link/link.styles.ts Outdated Show resolved Hide resolved
@MichaelMarcialis
Copy link
Contributor Author

Thanks, @cchaos! I've updated the PR with your feedback. Let me know if I missed anything.

@kibanamachine
Copy link

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

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.

🙌 LGTM! Just one last nit and maybe a conflict resolve gone bad? Otherwise, should be good to merge

@kibanamachine
Copy link

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

@cchaos cchaos dismissed miukimiu’s stale review May 6, 2022 20:17

Taken care of

Copy link
Contributor

@miukimiu miukimiu left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@kibanamachine
Copy link

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

@MichaelMarcialis MichaelMarcialis merged commit a22356c into elastic:main May 9, 2022
@MichaelMarcialis MichaelMarcialis deleted the 5685/euiLinkConversion branch May 9, 2022 13:24
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.

6 participants