-
Notifications
You must be signed in to change notification settings - Fork 96
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
Send css method down as a prop instead of as a global #124
Send css method down as a prop instead of as a global #124
Conversation
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.
I've left in the resolve method as is... but I'm unsure if that is necessary. Should we still export it from the ThemedStyleSheet or the withStyles file?
Not sure it makes sense to keep around in this form. Should this maybe mimic create
where the exported create
is just the LTR
version?
src/withStyles.jsx
Outdated
@@ -56,9 +56,21 @@ export function withStyles( | |||
this.maybeCreateStyles(); | |||
} | |||
|
|||
getDirection() { |
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.
Nit: Maybe just make this isRTL()
since that's how it's used in both places below?
const direction = this.context[CHANNEL] && this.context[CHANNEL].getState();
return direction === DIRECTIONS.RTL;
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.
Looks great!
I've left in the resolve method as is... but I'm unsure if that is necessary. Should we still export it from the ThemedStyleSheet or the withStyles file?
Seems unnecessary, since the resolveLTR/RTL methods fallback to it internally. I guess it depends if we want this to be a breaking change or not.
Let's update the specs, too!
src/ThemedStyleSheet.js
Outdated
@@ -57,8 +65,9 @@ export default globalCache.setIfMissingThenGet( | |||
create: createLTR, | |||
createRTL, | |||
get, | |||
resolveNoRTL, |
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.
this makes it a breaking change, fwiw.
src/withStyles.jsx
Outdated
@@ -10,7 +10,6 @@ import ThemedStyleSheet from './ThemedStyleSheet'; | |||
|
|||
// Add some named exports for convenience. | |||
export const css = ThemedStyleSheet.resolve; | |||
export const cssNoRTL = ThemedStyleSheet.resolveNoRTL; |
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.
as does this
ae8e1f7
to
1ecee9d
Compare
@ljharb @yzimet @garrettberg PTAL! Also this pairs with airbnb/react-with-styles-interface-aphrodite#37. I think what I have in mind for the upgrade path is that by leaving the (non-directional) css export in, we are able to upgrade in chunks (as in a folder at a time) which seems beneficial. I'm going to couple this with a lint rule that prevents importing of the css file directly and a codemod that goes through and updates all files to use the prop instead. WDYT? |
are these problems detailed somewhere? |
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!
Upgrade plan sounds good too.
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!
componentDidMount() { | ||
if (this.context[CHANNEL]) { | ||
// subscribe to future direction changes | ||
this.channelUnsubscribe = this.context[CHANNEL].subscribe((direction) => { |
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.
could you remind me, did we consider using the withDirection
HOC directly instead of reimplementing this?
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.
I considered it, but adding the extra virtual DOM node seemed possibly problematic. We can go back and do that in a patch change if that makes more sense moving forward.
I did think it was sad to duplicate this code.... so maybe the right thing to do would be to wrap?
I'll defer to @lencioni when he is back from PTO.
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.
Because this HOC is used so prolifically throughout a tree, I would be hesitant to drop in another component into the mix. If you wanted to keep it DRY you could probably export some utility methods from withDirection and then use them here.
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’d be a great follow up, i had the same thought
To close the loop on @lencioni's comment, here is a description of why we're doing this change:
|
In order to solve some problems we've seen with specificity, as well as some server-side/client-side disparities, we will be attempting to separate out RTL and LTR styles entirely. Part of this has been accomplished by splitting StyleSheet creation into RTL and LTR. The next step is to send down a directional CSS method as a prop.
I've left in the resolve method as is... but I'm unsure if that is necessary. Should we still export it from the ThemedStyleSheet or the withStyles file?
to: @yzimet @lencioni @garrettberg @ljharb @airbnb/webinfra