如何使react-admin默认主题RTL

moh*_*has 2 reactjs material-ui react-admin

我需要制作在RTL中使用material-ui的react-admin,到目前为止没有任何效果,因为每个元素上都有覆盖dir="rtl"body标签的样式,创建一个自定义主题,例如:

const theme = {
  direction: 'rtl',
  isRtl: true
};
const themeWithDirection = createMuiTheme({...defaultTheme, ...theme});
Run Code Online (Sandbox Code Playgroud)

并在管理组件上使用它,例如:

<Admin locale="ar" dataProvider={dataProvider} i18nProvider={i18nProvider} theme={themeWithDirection} layout={layout}>
Run Code Online (Sandbox Code Playgroud)

不工作。在自定义布局上使用也StyleProvider不起作用:

import React from 'react';
import { Layout } from 'react-admin';

import { create } from 'jss';
import rtl from 'jss-rtl';
import {  jssPreset } from '@material-ui/core/styles';
import { StylesProvider } from '@material-ui/core/styles';

const jss = create({ plugins: [...jssPreset().plugins, rtl()] });

const MyLayout = props => 
  <StylesProvider jss={jss}>
    <Layout
      {...props}
    />
  </StylesProvider>;
Run Code Online (Sandbox Code Playgroud)

问题是像TextFielduse这样的组件text-align: left;,那么我如何翻转它们的 css 而不在自定义 css 文件中覆盖它们呢?

moh*_*has 5

使用ListGuesser我没有运气将网格切换到 RTL,但是,在编写自定义列表组件和 JssProvider 之后,它现在可以工作:

import React from 'react';
import { List, Datagrid, TextField, EmailField } from 'react-admin';

import { create } from 'jss';
import rtl from 'jss-rtl';
import JssProvider from 'react-jss/lib/JssProvider';
import { jssPreset } from '@material-ui/core/styles';


const jss = create({ plugins: [...jssPreset().plugins, rtl()] });

export const UserList = props => (
  <JssProvider jss={jss}>
    <List {...props}>
      <Datagrid rowClick="edit">
        <TextField source="id" />
        <TextField source="name" />
        <TextField source="username" />
        <EmailField source="email" />
        <TextField source="address.street" />
        <TextField source="phone" />
        <TextField source="website" />
        <TextField source="company.name" />
      </Datagrid>
    </List>
  </JssProvider>
);
Run Code Online (Sandbox Code Playgroud)