-
Notifications
You must be signed in to change notification settings - Fork 4.1k
emotion 9 --> emotion 10 #3321
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 9 --> emotion 10 #3321
Conversation
18de288
to
38a5147
Compare
@@ -48,7 +50,7 @@ | |||
"css-loader": "^0.28.7", | |||
"cypress": "^1.4.1", | |||
"dotenv": "^5.0.1", | |||
"enzyme": "^3.3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upgrade enzyme so it plays well with emotion 10 and new context api
src/Select.js
Outdated
import memoizeOne from 'memoize-one'; | ||
import createEmotion, { type Emotion } from 'create-emotion'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed createEmotion in favor of emotion 10s CacheProvider and createCache for adding nonce support.
src/Select.js
Outdated
@@ -1703,7 +1696,7 @@ export default class Select extends Component<Props, State> { | |||
onTopArrive={onMenuScrollToTop} | |||
onBottomArrive={onMenuScrollToBottom} | |||
> | |||
<ScrollBlock emotion={this.emotion} isEnabled={menuShouldBlockScroll}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't want to be doing this anymore, it locks us into emotion as an intrinsic part of our components API, while this is true of our own implementations, this should ultimately not be true for power users.
src/components/Control.js
Outdated
{({ css }) => ( | ||
<div | ||
ref={innerRef} | ||
className={cx(css(getStyles('control', props)), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we're using the ClassNames fn from emotion 10 to access the css method so we can pass the processed style objects from css(getStyles()) to our custom cx implementation.
@mitchellhamilton I just wanted to sanity check the fact that we're using a custom cx implementation her instead of the one provided to us by ClassNames is ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using your own cx function is totally fine, it just means that emotion styles won't be merged together which in this case, I don't believe it matters. I'm not really sure about this whole approach though, ClassNames is intended to be a workaround when a component doesn't accept a className prop, I'd recommend an approach like this:
diff --git a/src/components/Control.js b/src/components/Control.js
index a964547..c38a9ad 100644
--- a/src/components/Control.js
+++ b/src/components/Control.js
@@ -1,6 +1,7 @@
// @flow
-import React, { type Node, type ElementRef } from 'react';
-import { ClassNames } from '@emotion/core';
+import { type Node, type ElementRef } from 'react';
+/** @jsx jsx */
+import { jsx } from '@emotion/core';
import type { CommonProps, PropsWithStyles } from '../types';
@@ -56,22 +57,19 @@ export const css = ({
const Control = (props: ControlProps) => {
const { children, cx, getStyles, className, isDisabled, isFocused, innerRef, innerProps, menuIsOpen } = props;
return (
- <ClassNames>
- {({ css }) => (
- <div
- ref={innerRef}
- className={cx(css(getStyles('control', props)), {
- 'control': true,
- 'control--is-disabled': isDisabled,
- 'control--is-focused': isFocused,
- 'control--menu-is-open': menuIsOpen
- }, className)}
- {...innerProps}
- >
- {children}
- </div>
- )}
- </ClassNames>
+ <div
+ ref={innerRef}
+ css={getStyles('control', props)}
+ className={cx({
+ 'control': true,
+ 'control--is-disabled': isDisabled,
+ 'control--is-focused': isFocused,
+ 'control--menu-is-open': menuIsOpen
+ }, className)}
+ {...innerProps}
+ >
+ {children}
+ </div>
);
};
diff --git a/src/utils.js b/src/utils.js
index 0787bfd..d37f037 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -41,11 +41,10 @@ function applyPrefixToName(prefix, name) {
export function classNames(
prefix?: string | null,
- cssKey?: string | null,
state?: ClassNamesState,
className?: string,
) {
- const arr = [cssKey, className];
+ const arr = [className];
if (state && prefix) {
for (let key in state) {
if (state.hasOwnProperty(key) && state[key]) {
src/components/indicators.js
Outdated
viewBox="0 0 20 20" | ||
aria-hidden="true" | ||
focusable="false" | ||
className={css({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mitchellhamilton We technically don't need to be using ClassNames here to access the css method, since we aren't generating a custom className using our own cx implementation, however I noticed that using the css prop with the jsx pragma generated a style tag without a nonce attribute. Not sure why this is the case, but using the ClassNames renderProp to circumnavigate this for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's very strange, gonna look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating to latest of babel-plugin-emotion resolves this issue
})} | ||
/> | ||
type DotProps = { color: string, delay: number, offset: boolean }; | ||
const LoadingDot = ({ color, delay, offset }: DotProps) => ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mitchellhamilton same as with the svg example above, technically not necessary to use here, but noticed that nonces were not being added, and the keyframes`` call above was not working.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
eba74b2
to
6304b9b
Compare
@JedWatson after talking to @jossmac we agreed that this is a breaking change, and should be a 3.0.0. |
With this update how would I style custom Options? I used to get emotion as a prop but nolonger... I also don't seem to be getting Sorry I just realized that css can come from my import of {css} from emotion... |
6304b9b
to
6f1c946
Compare
@gwyneplaine are we plan to merge this? |
@Faradey27 plan is to merge this as a 3.x, we're doing a bit of clean up to release another 2.x.x before this happens, thanks for the patience |
This is critically needed. |
hey @ematipico, thanks for raising interest in this body of work. |
Would love to see this get released! We've had to do a bunch of workarounds to get |
@gwyneplaine give me a yell if you need a hand with anything. Happy to pair on this. |
Any ETA on when this will be merged in? |
@leerob I am using this with Gatsby and having issues after SSR. Any advice on what workarounds you used to get it to work with Next.js? Looking forward to v3.0.0 👍 |
@senorgeno I am just forcing client-side only rendering for now until this is released by wrapping the select with |
Thanks @vaunus |
Refactor our usage of create-emotion as of v2.2.0 to emotion 10, and reverting the addition of the custom emotion instance passed into each component.
Please see the following PR for context on the create-emotion change: #3260
This is also an indirect response to the following issue #3317 caused by the above PR 😄
There's a few valid reasons for the upgrade:
Possible arguments against emotion 10:
** this is only true for users who are completely rewriting components, and doing their own style composition. Users on emotion 10 who are doing this should be familiar with this syntax already, users who are using any other css-in-js solution should have the necessary tools to create functioning custom components without having to use emotion.
Things I want to validate before this PR goes through: