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

adding rtl theme #740

Merged
merged 3 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
48 changes: 25 additions & 23 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { FC, useEffect } from 'react';

import { BrowserRouter as Router, Route, Switch } from 'react-router-dom';
import HomePage from './pages/HomePage';
import { Footer } from './components/organisms/Footer';
Expand All @@ -15,14 +16,14 @@ const headerHeight = '5vh';
const pageContentHeight = '88vh';
const footerHeight = '7vh';


const useStyles = makeStyles((theme: Theme) =>
createStyles({
pageContent: {
overflow: 'auto',
},
}),
);

const App: FC = () => {
const { i18n } = useTranslation();
const classes = useStyles();
Expand All @@ -31,32 +32,33 @@ const App: FC = () => {

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

Choose a reason for hiding this comment

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

remove comments


return (
<StoreContext.Provider value={store}>
<ThemeProvider theme={store.settingsStore.theme}>
<Router>
<Box>
<Box height={headerHeight} display="flex">
<Header />
</Box>
<Box height={pageContentHeight} className={classes.pageContent}>
<Switch>
<Route exact path="/" component={HomePageRedirect} />
<Route path="/:lng?/newsflash/:id" component={HomePage} />
<Route path="/login-popup-redirect" component={PopUpRedirect} />
</Switch>
</Box>
<Box height={footerHeight} display="flex">
<Footer />
<StoreContext.Provider value={store}>
<ThemeProvider theme={appDir === 'rtl' ? store.settingsStore.rtlTheme : store.settingsStore.theme}>
<Router>
<Box>
<Box height={headerHeight} display="flex">
<Header />
</Box>
<Box height={pageContentHeight} className={classes.pageContent}>
<Switch>
<Route exact path="/" component={HomePageRedirect} />
<Route path="/:lng?/newsflash/:id" component={HomePage} />
<Route path="/login-popup-redirect" component={PopUpRedirect} />
</Switch>
</Box>
<Box height={footerHeight} display="flex">
<Footer />
</Box>
</Box>
</Box>
</Router>
</ThemeProvider>
</Router>
</ThemeProvider>
</StoreContext.Provider>
);
};
Expand Down
9 changes: 9 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
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 />}>
<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