我在我的项目中使用material-ui
and next
,但使用后页面仍然存在问题jss-rtl
react
ltr
<JssProvider ...>
-rtl 组件代码:
import React from "react";
import { create } from 'jss';
import rtl from 'jss-rtl';
import JssProvider from 'react-jss/lib/JssProvider';
import { createGenerateClassName, jssPreset } from 'material-ui/styles';
// Configure JSS
const jss = create({ plugins: [...jssPreset().plugins, rtl()] });
// Custom Material-UI class name generator.
const generateClassName = createGenerateClassName();
function RTL(props) {
return (
<JssProvider jss={jss} generateClassName={generateClassName}>
{props.children}
</JssProvider>
);
}
export default RTL;
-index.js 代码:
import React from 'react';
import ReactDOM from 'react-dom';
import {createBrowserHistory} from "history";
import {Router, Route, Switch} from 'react-router-dom';
import {MuiThemeProvider, createMuiTheme} from 'material-ui/styles';
import r8 from "./components/r8";
import RTL from "./components/RTL";
import appRoutes from "./routes/app";
import "./assets/css/App.css";
import "./assets/fonts/fonts.css";
const hist = createBrowserHistory();
const theme = createMuiTheme({
typography: {
fontFamily: "PhpPlus"
},
pallete: {
primary: {
light: r8.color.indigo[300],
main: r8.color.indigo[500],
dark: r8.color.indigo[700],
},
secondary: {
light: r8.color.pink.A200,
main: r8.color.pink.A400,
dark: r8.color.pink.A700,
},
error: {
light: r8.color.red[300],
main: r8.color.red[500],
dark: r8.color.red[700],
}
}
});
const Rendering = <RTL>
<MuiThemeProvider theme={theme}>
<Router history={hist}>
<Switch>
{
appRoutes.map((route, key) => {
return <Route {...route} key={key}/>;
})
}
</Switch>
</Router>
</MuiThemeProvider>
</RTL>;
ReactDOM.render(Rendering, document.getElementById('R8'));
[注意] 控制台没有错误
我测试过:
const theme = createMuiTheme({ direction: "rtl", ...});
//no change , still ltr
或者
<body dir="rtl">
//page direction is rtl but paddings or margins and floats and other css codes not flipped!
有人知道出了什么问题吗?请注意,此代码在 Windows 10 上我的项目的早期版本中运行。当我将我的操作系统更改为 Linux Ubuntu 16.04 (LTS) 并安装 Nodejs 时,它不再工作了......(抱歉输入英文不好 - 我是波斯语!:) )