Skip to content

Commit

Permalink
adding rtl theme (#740)
Browse files Browse the repository at this point in the history
* adding rtl theme

* fix indentation

Co-authored-by: almogbhl <almogbh.l@gmail.com>
  • Loading branch information
EyalIlan and almogbhl authored Oct 13, 2021
1 parent 95cd4a4 commit fa4cf2c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"html-to-image": "^1.6.2",
"i18next": "^20.3.2",
"i18next-http-backend": "^1.2.6",
"jss-rtl": "^0.3.0",
"leaflet": "^1.7.1",
"leaflet.heat": "^0.2.0",
"mobx": "^6.3.2",
Expand Down
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ const App: FC = () => {
const theme = useTheme();

const appDir = i18n.dir();

useEffect(() => {
// https://material-ui.com/guides/right-to-left/
document.body.dir = appDir;
theme.direction = appDir;
}, [i18n, theme, theme.direction, appDir]);
}, [i18n, theme, appDir]);

return (
<StoreContext.Provider value={store}>
<ThemeProvider theme={store.settingsStore.theme}>
<ThemeProvider theme={appDir === 'rtl' ? store.settingsStore.rtlTheme : store.settingsStore.theme}>
<Router>
<Box>
<Box height={headerHeight} display="flex">
Expand Down
9 changes: 8 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import React, { Suspense } from 'react';
import { create } from 'jss';
import rtl from 'jss-rtl';
import { StylesProvider, jssPreset } from '@material-ui/core/styles';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import './services/i18n.service';
import * as serviceWorker from './serviceWorker';
import OverlayLoader from './components/molecules/OverlayLoader';

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

ReactDOM.render(
<Suspense fallback={<OverlayLoader show />}>
<App />
<StylesProvider jss={jss}>
<App />
</StylesProvider>
</Suspense>,
document.getElementById('root'),
);
Expand Down
5 changes: 5 additions & 0 deletions src/store/settings.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import RootStore from './root.store';
export default class SettingsStore {
private _theme: Theme = createMuiTheme(defaultThemeOptions);

private _themeRtl: Theme = createMuiTheme({ ...defaultThemeOptions, direction: 'rtl' });

constructor(private rootStore: RootStore) {
makeAutoObservable(this);
}
get rtlTheme(): Theme {
return this._themeRtl;
}

get theme(): Theme {
return this._theme;
Expand Down
1 change: 1 addition & 0 deletions src/style/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ThemeOptions } from '@material-ui/core';
import { fontFamilyString, darkGrey } from './';

const defaultThemeOptions: ThemeOptions = {
direction: 'ltr',
palette: {},
overrides: {
MuiCardContent: {
Expand Down

0 comments on commit fa4cf2c

Please sign in to comment.