Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RTL] Make Right-to-left optional (#8916)
- Loading branch information
1 parent
8860a60
commit 1af4456
Showing
9 changed files
with
86 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Right-to-left | ||
|
||
To change the direction of Material-UI components you must follow the following steps: | ||
|
||
## Steps | ||
|
||
### 1. HTML | ||
|
||
Make sure `dir="rtl"` is set on **body**, otherwise native components and portals will break. | ||
|
||
### 2. Theme | ||
|
||
Set `direction: 'rtl'` on your custom theme. | ||
|
||
### 3. jss-rtl | ||
|
||
We are relying on a JSS plugin to flip the styles: [jss-rtl](https://github.com/alitaheri/jss-rtl). | ||
|
||
```sh | ||
npm install jss-rtl | ||
``` | ||
|
||
Internally, we are dynamically enabling this plugin when `direction: 'rtl'` is set on the theme. | ||
The [CSS-in-JS documentation](/customization/css-in-js#opting-out-of-rtl-transformation) explains a bit more how this plugin is working. Head to the [plugin README](https://github.com/alitaheri/jss-rtl) to know everything about it. | ||
|
||
Once you have created a new JSS instance with the plugin, you need to make it available to all components in the component tree. We have a [`<JssProvider />`](https://github.com/cssinjs/react-jss) component for this: | ||
|
||
```jsx | ||
import { create } from 'jss'; | ||
import preset from 'jss-preset-default'; | ||
import rtl from 'jss-rtl'; | ||
import JssProvider from 'react-jss/lib/JssProvider'; | ||
import createGenerateClassName from 'material-ui/styles/createGenerateClassName'; | ||
|
||
// Configure JSS | ||
const jss = create({ plugins: [...preset().plugins, rtl()] }); | ||
jss.options.createGenerateClassName = createGenerateClassName; | ||
|
||
function RTL(props) { | ||
return ( | ||
<JssProvider jss={jss}> | ||
{props.children} | ||
</JssProvider> | ||
); | ||
} | ||
``` | ||
|
||
## Demo | ||
|
||
*Use the direction toggle button on the top left corner to flip the whole documentation* | ||
|
||
{{demo='pages/guides/Direction.js'}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// @flow | ||
|
||
import React from 'react'; | ||
import withRoot from 'docs/src/modules/components/withRoot'; | ||
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs'; | ||
import markdown from 'docs/src/pages/guides/right-to-left.md'; | ||
|
||
function Page() { | ||
return ( | ||
<MarkdownDocs | ||
markdown={markdown} | ||
demos={{ | ||
'pages/guides/Direction.js': { | ||
js: require('docs/src/pages/guides/Direction').default, | ||
raw: preval` | ||
module.exports = require('fs') | ||
.readFileSync(require.resolve('docs/src/pages/guides/Direction'), 'utf8') | ||
`, | ||
}, | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export default withRoot(Page); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters