Skip to content

[CSS-in-JS] Convert mixins#5754

Merged
thompsongl merged 33 commits intoelastic:mainfrom
thompsongl:css-in-js/mixins
Apr 18, 2022
Merged

[CSS-in-JS] Convert mixins#5754
thompsongl merged 33 commits intoelastic:mainfrom
thompsongl:css-in-js/mixins

Conversation

@thompsongl
Copy link
Copy Markdown
Contributor

@thompsongl thompsongl commented Mar 31, 2022

Summary

Convert Sass mixins to JS factories and React hooks

  • Create helper and shadow mixins and hooks
    • Deleted legacy theme shadow mixins from global_styling
    • Amsterdam theme mixins live in its theme directory
  • Create createStyleHookFromMixin
    • Takes a mixin, returns a React hook with theme applied
    • Attempts to handle optional colorMode gracefully

Discuss:

  • Naming patterns
    • euiThemeThing
    • useEuiThemeThing
  • Comparing output to Sass
    • Would some kind of diff with compiled CSS be helpful?

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
  • Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link
Copy Markdown

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

@kibanamachine
Copy link
Copy Markdown

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

@thompsongl thompsongl changed the title [WIP][CSS-in-JS] Convert mixins [CSS-in-JS] Convert mixins Apr 6, 2022
@thompsongl
Copy link
Copy Markdown
Contributor Author

Opening for review. Will likely write some tests if we feel good about the direction. Not sure if/how we want to document the functions.

@thompsongl thompsongl marked this pull request as ready for review April 6, 2022 20:32
@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Apr 6, 2022

Not sure if/how we want to document the functions.

Can you attempt to update the shadows section of https://elastic.github.io/eui/#/theming/more-tokens#shadow? You should be able to replicate what exists for Sass.

@thompsongl
Copy link
Copy Markdown
Contributor Author

Can you attempt to update the shadows section

Ah nice; I didn't remember that was there

@thompsongl
Copy link
Copy Markdown
Contributor Author

Added some shadow docs!

@kibanamachine
Copy link
Copy Markdown

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

@cchaos
Copy link
Copy Markdown
Contributor

cchaos commented Apr 11, 2022

PR4U: thompsongl#16

@kibanamachine
Copy link
Copy Markdown

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

@kibanamachine
Copy link
Copy Markdown

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

Copy link
Copy Markdown
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

I really like how the methods break down, and I think it covers a lot of precedent-setting that we can follow moving forward. Had a couple thoughts on the docs side of things, but the EUI code LGTM.

* @param content
* @returns string
*/
export const euiCanAnimate = (content: string) => `
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.

Have you explored Emotion's InterpolationPrimitive type and if it, a subset, or this string is the right choice here and in other utility methods?

export type InterpolationPrimitive =
  | null
  | undefined
  | boolean
  | number
  | string
  | ComponentSelector
  | Keyframes
  | SerializedStyles
  | CSSObject

Copy link
Copy Markdown
Contributor Author

@thompsongl thompsongl Apr 18, 2022

Choose a reason for hiding this comment

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

I hadn't seen this but it might make sense in some cases. We'd need add @emotion/serialize as a dependency to use it, so I'm ok going with the more restrictive string here for now.

@thompsongl thompsongl enabled auto-merge (squash) April 18, 2022 20:43
@kibanamachine
Copy link
Copy Markdown

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

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