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

Full RTL support #1674

Merged
merged 5 commits into from
Oct 14, 2015
Merged

Full RTL support #1674

merged 5 commits into from
Oct 14, 2015

Conversation

louy
Copy link
Contributor

@louy louy commented Sep 17, 2015

Closes #1661.

@louy
Copy link
Contributor Author

louy commented Sep 17, 2015

Travis build failed because of a network issue or something apparently. npm run build works fine.

@shaurya947
Copy link
Contributor

@louy maybe try pushing an empty commit to re-start the Travis build?

@louy
Copy link
Contributor Author

louy commented Sep 17, 2015

@shaurya947 I believe admins can restart a build manually.
http://stackoverflow.com/a/17624403/1644422

It would be much cleaner than an empty commit.

@louy louy closed this Sep 19, 2015
@louy louy reopened this Sep 19, 2015
@louy
Copy link
Contributor Author

louy commented Sep 27, 2015

@shaurya947 can I get any feedback on this?

@@ -83,6 +83,14 @@ const MenuItem = React.createClass({
},

getStyles() {
const isRtl = this.context.muiTheme.isRtl;
Copy link
Member

Choose a reason for hiding this comment

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

I think that is should be this.state.muiTheme.isRtl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. This was written before state.muiTheme was introduced. I've just seen that feature.

@louy
Copy link
Contributor Author

louy commented Oct 2, 2015

@oliviertassinari do you think adding another function to StylePropable that flips the direction automatically for all components might be a better approach?

@oliviertassinari
Copy link
Member

Well, If you want to add the support of RTL on a large set of component, yes I would use a different approach.
I see two issues, first, we are going to duplicate this in a lot of different component. Second, in terms of perf/memory, I think that we can do better.
My idea would be to precompute on object called RTL at the theme level depending on the isRTL boolean.

@shaurya947
Copy link
Contributor

Sorry @louy, I've been a little MIA on this issue.

I don't think using the mixin is the best option. But I agree with @oliviertassinari that having something on the theme-level is a good approach. Take a look at theme-manager and see if you have any ideas :-)

@oliviertassinari
Copy link
Member

For instance, when we contruct the theme we can compute a LTR variable that we add to the theme.

if (isRtl) {
  LTR = {
    right: 'left',
    left: 'right',
    marginRight: 'marginLeft',
    paddingLeft: 'paddingRight',
  }
} else {
  LTR = {
    right: 'right',
    left: 'left',
    marginRight: 'marginRight',
    paddingLeft: 'paddingLeft',
  }
}

@shaurya947
Copy link
Contributor

👍

@louy louy changed the title RTL support for <MenuItem> Full RTL support Oct 11, 2015
@louy
Copy link
Contributor Author

louy commented Oct 11, 2015

Hi,
I've made direction flipping automated using the function "prepareStyles" in style-propable. Please try to get back on this and merge it before making edits because it wasn't easy to do and took a lot of effort to refactor some stuff.

To see it in action, just uncomment the line in docs/src/components/master.jsx.

A few things to be careful about:

  • Never call prepareStyles on the same "style" object twice. You'll get a warning if you do so.
  • I wasn't able to reverse CircularProgress and LoadingIndicator yet.
  • Not all css properties are supported yet. We have padding, margin, border, transform, float, direction, right/left. Those are the ones I found that are being used in the project currently.
  • I should probably add unit tests for utils/styles. I just wanted to finish this asap to avoid rebasing.
  • I thought you might have some performance considerations. So when isRtl isn't set to true the ensureDirection function does nothing. This means performance won't be affected.

@alitaheri
Copy link
Member

WOW, I love it 👍 👍 ❤️ ❤️

@louy
Copy link
Contributor Author

louy commented Oct 11, 2015

I also wasn't able to add rtl support to all docs pages because they're written in es6 class style and I need to use mixins. That shouldn’t be a big issue.
The CodeMirror component has a tiny issue with spacing as well. It's not a full react component and I didn't get the chance to fix it yet. :)

}, style);
}

if (!muiTheme.isRtl) return style; // Performance hack!
Copy link
Member

Choose a reason for hiding this comment

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

Performance hack!

I would rather say Left to right is the default.
What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Left to right is the default doesn't imply that this line of code is there for optimization. Maybe:
Skip further processing to improve performance, since ltr is the default.

Copy link
Member

Choose a reason for hiding this comment

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

My point is that this line isn't for optimisation. It's there because the default style is for LTR. Hence, we shouldn't invert the style properties if isRtl is false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@oliviertassinari
Copy link
Member

I like this approach. I'm wondering if this can work with flexbox.
Aside from that. I think that it would be better to squash all the commits into one or two (for history readability).

@louy
Copy link
Contributor Author

louy commented Oct 11, 2015

Awesome! It's working fine with <Grid> so I guess we won't be having issues.
There might be some possible cleanups (like changing mergeAndPrefix to just mergeStyles). I'll write some documentation about this whole thing this week and send another PR.
I'll squash them all in a minute.

@louy
Copy link
Contributor Author

louy commented Oct 12, 2015

@shaurya947 can we get this merged soon?

@@ -18,4 +18,5 @@ module.exports = {
borderColor: ColorManipulator.fade(Colors.fullWhite, 0.3),
disabledColor: ColorManipulator.fade(Colors.fullWhite, 0.3),
},
isRtl: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this shouldn't be part of the rawTheme, semantically speaking.

@shaurya947
Copy link
Contributor

@louy see the comments above and let me know what you think.

Also, there's a lot of changes here. Can you make sure that nothing breaks when isRtl is set to false (the default value I suppose)?

Good job consolidating all this btw 👍

@louy
Copy link
Contributor Author

louy commented Oct 13, 2015

Hi @shaurya947,

Just did some cleanup and the a quick look through the whole docs to make nothing is broken. Everything looks fine.
I've removed styleConstants from ThemeManager as well.

Thanks :)

@shaurya947
Copy link
Contributor

I'll go ahead and merge this then, and we can tackle any issues that come along the way. Thanks @louy

shaurya947 added a commit that referenced this pull request Oct 14, 2015
@shaurya947 shaurya947 merged commit e59a0be into mui:master Oct 14, 2015
return newStyle;
},

prepareStyles(muiTheme, ...styles) {
Copy link
Member

Choose a reason for hiding this comment

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

muiTheme is not passed as parameter when used.
I had to revert this commit in this PR #1882.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(for reference) This is not a bug.
See src/mixins/style-propable.js#L35-L37

Copy link
Member

Choose a reason for hiding this comment

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

Oh sorry, I overlooked this.

@oliviertassinari
Copy link
Member

@andreychev Can you submit a PR to fix this ?

@zannager zannager added the component: menu This is the name of the generic UI component, not the React module! label Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: menu This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drop Down Menu's icon in RTL mode does not float left.
6 participants