-
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
Add directional StyleSheet
creation based on context
#117
Conversation
@@ -78,6 +79,7 @@ | |||
"deepmerge": "^1.5.2", | |||
"global-cache": "^1.2.1", | |||
"hoist-non-react-statics": "^2.3.1", | |||
"prop-types": "^15.6.0" | |||
"prop-types": "^15.6.0", | |||
"react-with-direction": "^1.1.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.
let's make this both a dep and a peer dep - a peer dep so there's no conflict in case they use a different version of react-with-direction
, and "also a dep" so npm 3+ users don't have to manually add it to package.json.
@@ -59,7 +67,8 @@ export default globalCache.setIfMissingThenGet( | |||
() => ({ | |||
registerTheme, | |||
registerInterface, | |||
create, | |||
create: createLTR, | |||
createRTL, |
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.
should we also add createLTR,
here, for symmetry?
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 don't know how much sense that makes if create
always defaults to createLTR
and I wanna keep create for the default case (and for backwards compatibility)
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, exciting!
src/withStyles.jsx
Outdated
const isRTL = direction === DIRECTIONS.RTL; | ||
if (isRTL && !styleDefRTL) { | ||
styleDefRTL = styleFn ? ThemedStyleSheet.createRTL(styleFn) : EMPTY_STYLES_FN; | ||
} else if (!styleDefLTR) { |
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: add !isRTL
to the condition for clarity
test/withStyles_test.jsx
Outdated
); | ||
expect(testInterface.createRTL.callCount).to.equal(1); | ||
}); | ||
}); |
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: please add one more test for a <WrappedComponent />
that is not within a DirectionProvider
?
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.
Whoops that's what I meant the first test to be :P
952296c
to
c196ce1
Compare
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!
@@ -28,6 +31,10 @@ function baseClass(pureComponent) { | |||
return React.Component; | |||
} | |||
|
|||
const contextTypes = { | |||
[CHANNEL]: brcastShape, |
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.
it's unfortunate we're not using withDirection
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.
I mean it would add an extra virtual DOM node to ... every single component in our tree... which doesn't seem good. :/
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.
Maybe we could export more things from react-with-direction to avoid as much duplication as possible?
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.
Perhaps we could export directionProviderContextTypes
? the grabbing of the direction from the context is also a bit gross.
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'll think about implementing this in a follow up
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.
Yes, we should definitely do that at a minimum.
test/withStyles_test.jsx
Outdated
<WrappedComponent /> | ||
</DirectionProvider>, | ||
); | ||
expect(testInterface.createRTL.callCount).to.equal(1); |
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.
expect(testInterface.createRTL).to.have.property('callCount', 1)
will have a nicer failure message.
c196ce1
to
b875bd0
Compare
This change introduces a dependency on
react-with-direction
(https://github.com/airbnb/react-with-direction) although in the actual dependencies, we only make use of the constants from that package. The idea is that if you wanted to leverage the LTR/RTL capabilities ofreact-with-styles
, you would pair it with aDirectionProvider
at the top-level. Introducing those constants as part of thereact-with-styles
package makes that relationship explicit.If you want to continue using
react-with-styles
as is, this would not add terribly much weight and the default fallbacks would all still work as expected.The next step would be to add directional StyleSheet creation to our interfaces.
From #115:
This is step 2 of the process.
@ljharb @lencioni @yzimet @garrettberg