#13704: add custom theme and clean code
authorArtur Janicki <artur.janicki@contractors.roche.com>
Tue, 3 Jul 2018 12:40:16 +0000 (14:40 +0200)
committerJanicki Artur <artur.janicki@contractors.roche.com>
Fri, 6 Jul 2018 06:49:51 +0000 (08:49 +0200)
Feature #13704

Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki@contractors.roche.com>

src/common/custom-theme.ts [new file with mode: 0644]
src/index.tsx
src/views-components/details-panel/details-panel.tsx
src/views-components/main-app-bar/main-app-bar.tsx
src/views/workbench/workbench.tsx

diff --git a/src/common/custom-theme.ts b/src/common/custom-theme.ts
new file mode 100644 (file)
index 0000000..e78185d
--- /dev/null
@@ -0,0 +1,61 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { createMuiTheme } from '@material-ui/core/styles';
+import { ThemeOptions, Theme } from '@material-ui/core/styles/createMuiTheme';
+import purple from '@material-ui/core/colors/purple';
+import blue from '@material-ui/core/colors/blue';
+import grey from '@material-ui/core/colors/grey';
+
+interface ArvadosThemeOptions extends ThemeOptions {
+    customs: any;
+}
+
+export interface ArvadosTheme extends Theme {
+    customs: any;
+}
+
+const purple900 = purple["900"];
+const grey600 = grey["600"];
+const themeOptions: ArvadosThemeOptions = {
+    customs: {
+        colors: {
+            
+        }
+    },
+    overrides: {
+        MuiAppBar: {
+            colorPrimary: {
+                backgroundColor: purple900
+            }
+        },
+        MuiTabs: {
+            root: {
+                color: grey600
+            },
+            indicator: {
+                backgroundColor: purple900
+            }
+        },
+        MuiTab: {
+            selected: {
+                fontWeight: 700,
+                color: purple900
+            }
+        }
+    },
+    mixins: {
+        toolbar: {
+            minHeight: '48px'
+        }
+    },
+    palette: {
+        primary: {
+            main: '#06C',
+            dark: blue.A100
+        }
+    }
+};
+
+export const CustomTheme = createMuiTheme(themeOptions);
\ No newline at end of file
index 580487846f05f9074068b20761c3b81579768f5b..21ecdab1ca0c5cf70dc84893501154d7601a3235 100644 (file)
@@ -15,6 +15,8 @@ import ApiToken from "./views-components/api-token/api-token";
 import authActions from "./store/auth/auth-action";
 import { authService } from "./services/services";
 import { getProjectList } from "./store/project/project-action";
 import authActions from "./store/auth/auth-action";
 import { authService } from "./services/services";
 import { getProjectList } from "./store/project/project-action";
+import { MuiThemeProvider } from '@material-ui/core/styles';
+import { CustomTheme } from './common/custom-theme';
 
 const history = createBrowserHistory();
 
 
 const history = createBrowserHistory();
 
@@ -25,14 +27,16 @@ const rootUuid = authService.getRootUuid();
 store.dispatch<any>(getProjectList(rootUuid));
 
 const App = () =>
 store.dispatch<any>(getProjectList(rootUuid));
 
 const App = () =>
-    <Provider store={store}>
-        <ConnectedRouter history={history}>
-            <div>
-                <Route path="/" component={Workbench}/>
-                <Route path="/token" component={ApiToken}/>
-            </div>
-        </ConnectedRouter>
-    </Provider>;
+    <MuiThemeProvider theme={CustomTheme}>
+        <Provider store={store}>
+            <ConnectedRouter history={history}>
+                <div>
+                    <Route path="/" component={Workbench}/>
+                    <Route path="/token" component={ApiToken}/>
+                </div>
+            </ConnectedRouter>
+        </Provider>
+    </MuiThemeProvider>;
 
 ReactDOM.render(
     <App/>,
 
 ReactDOM.render(
     <App/>,
index b63266a0e4d0237560e2223fc405b2ccac7af13c..a864d5078a46ff3d4c5905a35002cfe11a96218b 100644 (file)
@@ -6,7 +6,8 @@ import * as React from 'react';
 import Drawer from '@material-ui/core/Drawer';
 import IconButton from "@material-ui/core/IconButton";
 import CloseIcon from '@material-ui/icons/Close';
 import Drawer from '@material-ui/core/Drawer';
 import IconButton from "@material-ui/core/IconButton";
 import CloseIcon from '@material-ui/icons/Close';
-import { StyleRulesCallback, WithStyles, withStyles, Theme } from "@material-ui/core/styles";
+import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
+import { ArvadosTheme } from '../../common/custom-theme';
 import Tabs from '@material-ui/core/Tabs';
 import Tab from '@material-ui/core/Tab';
 import Typography from '@material-ui/core/Typography';
 import Tabs from '@material-ui/core/Tabs';
 import Tab from '@material-ui/core/Tab';
 import Typography from '@material-ui/core/Typography';
@@ -14,7 +15,7 @@ import Grid from '@material-ui/core/Grid';
 import * as classnames from "classnames";
 
 export interface DetailsPanelProps {
 import * as classnames from "classnames";
 
 export interface DetailsPanelProps {
-    closeDrawer: () => void;
+    onCloseDrawer: () => void;
     isOpened: boolean;
 }
 
     isOpened: boolean;
 }
 
@@ -27,16 +28,13 @@ class DetailsPanel extends React.Component<DetailsPanelProps & WithStyles<CssRul
                this.setState({ tabsValue: value });
        }
     
                this.setState({ tabsValue: value });
        }
     
-    renderTabContainer = (children: React.ReactElement<any>) => {
-        return (
-            <Typography className={this.props.classes.tabContainer} component="div">
-                {children}
-            </Typography>
-        );
-    }
+    renderTabContainer = (children: React.ReactElement<any>) => 
+        <Typography className={this.props.classes.tabContainer} component="div">
+            {children}
+        </Typography>
 
        render() {
 
        render() {
-        const { classes, closeDrawer, isOpened } = this.props;
+        const { classes, onCloseDrawer, isOpened } = this.props;
                const { tabsValue } = this.state;
         return (
             <div className={classnames([classes.container, { [classes.opened]: isOpened }])}>
                const { tabsValue } = this.state;
         return (
             <div className={classnames([classes.container, { [classes.opened]: isOpened }])}>
@@ -46,21 +44,14 @@ class DetailsPanel extends React.Component<DetailsPanelProps & WithStyles<CssRul
                                                        <Typography variant="title">
                                                                Tutorial pipeline
                                                        </Typography>
                                                        <Typography variant="title">
                                                                Tutorial pipeline
                                                        </Typography>
-                            <IconButton color="inherit" onClick={closeDrawer}>
+                            <IconButton color="inherit" onClick={onCloseDrawer}>
                                                                <CloseIcon />
                                                        </IconButton>
                                                </Grid>
                                        </Typography>
                                                                <CloseIcon />
                                                        </IconButton>
                                                </Grid>
                                        </Typography>
-                                       <Tabs value={tabsValue} onChange={this.handleChange}
-                                               classes={{ indicator: classes.tabsIndicator }}>
-                                               <Tab
-                                                       disableRipple
-                                                       classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
-                                                       label="Details" />
-                                               <Tab
-                                                       disableRipple
-                                                       classes={{ root: classes.tabRoot, selected: classes.tabSelected }}
-                                                       label="Activity" />
+                                       <Tabs value={tabsValue} onChange={this.handleChange}>
+                                               <Tab disableRipple label="Details" />
+                                               <Tab disableRipple label="Activity" />
                                        </Tabs>
                     {tabsValue === 0 && this.renderTabContainer(
                                                <Grid container>
                                        </Tabs>
                     {tabsValue === 0 && this.renderTabContainer(
                                                <Grid container>
@@ -102,15 +93,10 @@ class DetailsPanel extends React.Component<DetailsPanelProps & WithStyles<CssRul
 }
 
 type CssRules = 'drawerPaper' | 'container' | 'opened' | 'headerContainer' 
 }
 
 type CssRules = 'drawerPaper' | 'container' | 'opened' | 'headerContainer' 
-       | 'tabsIndicator' | 'tabRoot' | 'tabContainer' | 'tabSelected' | 'gridLabel';
+       | 'tabContainer' | 'tabSelected' | 'gridLabel';
 
 const drawerWidth = 320;
 
 const drawerWidth = 320;
-const colorPurple = '#692498';
-const colorLightGray = '#A1A1A1';
-const colorVeryLightGray = '#999999';
-const colorGray = '#333';
-
-const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
        container: {
         width: 0,
                position: 'relative',
        container: {
         width: 0,
                position: 'relative',
@@ -126,25 +112,15 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
         width: drawerWidth
        },
        headerContainer: {
         width: drawerWidth
        },
        headerContainer: {
-        color: colorLightGray,
+        color: theme.palette.grey["600"],
                margin: `${theme.spacing.unit}px 0`
        },
                margin: `${theme.spacing.unit}px 0`
        },
-       tabsIndicator: {
-        backgroundColor: colorPurple
-       },
-       tabRoot: {
-        color: colorGray,
-               '&$tabSelected': {
-                       fontWeight: 700,
-            color: colorPurple
-               }
-       },
        tabContainer: {
                padding: theme.spacing.unit * 3
        },
        tabSelected: {},
        gridLabel: {
        tabContainer: {
                padding: theme.spacing.unit * 3
        },
        tabSelected: {},
        gridLabel: {
-        color: colorVeryLightGray,
+        color: theme.palette.grey["500"]
        }
 });
 
        }
 });
 
index 135e1219d0bf7b3803df83b7acb0819b4b84ed1d..1230e3b7db60abe9901db66fa28a310a6737c804 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
-import { AppBar, Toolbar, Typography, Grid, IconButton, Badge, StyleRulesCallback, withStyles, WithStyles, Button, MenuItem } from "@material-ui/core";
+import { AppBar, Toolbar, Typography, Grid, IconButton, Badge, Button, MenuItem } from "@material-ui/core";
 import NotificationsIcon from "@material-ui/icons/Notifications";
 import PersonIcon from "@material-ui/icons/Person";
 import HelpIcon from "@material-ui/icons/Help";
 import NotificationsIcon from "@material-ui/icons/Notifications";
 import PersonIcon from "@material-ui/icons/Person";
 import HelpIcon from "@material-ui/icons/Help";
@@ -38,15 +38,12 @@ export interface MainAppBarActionProps {
     onDetailsPanelToggle: () => void;
 }
 
     onDetailsPanelToggle: () => void;
 }
 
-type MainAppBarProps = MainAppBarDataProps & MainAppBarActionProps & WithStyles<CssRules>;
+type MainAppBarProps = MainAppBarDataProps & MainAppBarActionProps;
 
 export const MainAppBar: React.SFC<MainAppBarProps> = (props) => {
 
 export const MainAppBar: React.SFC<MainAppBarProps> = (props) => {
-    return <AppBar className={props.classes.appBar} position="static">
-        <Toolbar className={props.classes.toolbar}>
-            <Grid
-                container
-                justify="space-between"
-            >
+    return <AppBar position="static">
+        <Toolbar>
+            <Grid container justify="space-between">
                 <Grid item xs={3}>
                     <Typography variant="headline" color="inherit" noWrap>
                         Arvados
                 <Grid item xs={3}>
                     <Typography variant="headline" color="inherit" noWrap>
                         Arvados
@@ -120,15 +117,4 @@ const renderMenuItems = (menuItems: MainAppBarMenuItem[], onMenuItemClick: (menu
     ));
 };
 
     ));
 };
 
-type CssRules = "appBar" | "toolbar";
-
-const styles: StyleRulesCallback<CssRules> = theme => ({
-    appBar: {
-        backgroundColor: "#692498"
-    },
-    toolbar: {
-        minHeight: '48px'
-    }
-});
-
-export default withStyles(styles)(MainAppBar);
+export default MainAppBar;
index 2cca921c6c58d3cbefbc47838942280bac9cafb2..8cc5fc22700571a207395746390d8e778ad4e1f8 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
-import { StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core/styles';
+import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
 import Drawer from '@material-ui/core/Drawer';
 import { connect, DispatchProp } from "react-redux";
 import { Route, Switch, RouteComponentProps, withRouter } from "react-router";
 import Drawer from '@material-ui/core/Drawer';
 import { connect, DispatchProp } from "react-redux";
 import { Route, Switch, RouteComponentProps, withRouter } from "react-router";
@@ -29,13 +29,14 @@ import projectActions from "../../store/project/project-action";
 import ProjectPanel from "../project-panel/project-panel";
 import { sidePanelData } from '../../store/side-panel/side-panel-reducer';
 import DetailsPanel from '../../views-components/details-panel/details-panel';
 import ProjectPanel from "../project-panel/project-panel";
 import { sidePanelData } from '../../store/side-panel/side-panel-reducer';
 import DetailsPanel from '../../views-components/details-panel/details-panel';
+import { ArvadosTheme } from '../../common/custom-theme';
 
 const drawerWidth = 240;
 
 const drawerWidth = 240;
-const appBarHeight = 116;
+const appBarHeight = 100;
 
 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
 
 
 type CssRules = 'root' | 'appBar' | 'drawerPaper' | 'content' | 'contentWrapper' | 'toolbar';
 
-const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
     root: {
         flexGrow: 1,
         zIndex: 1,
     root: {
         flexGrow: 1,
         zIndex: 1,
@@ -47,7 +48,6 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
     },
     appBar: {
         zIndex: theme.zIndex.drawer + 1,
     },
     appBar: {
         zIndex: theme.zIndex.drawer + 1,
-        backgroundColor: '#692498',
         position: "absolute",
         width: "100%"
     },
         position: "absolute",
         width: "100%"
     },
@@ -65,7 +65,7 @@ const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
         paddingTop: appBarHeight
     },
     content: {
         paddingTop: appBarHeight
     },
     content: {
-        padding: theme.spacing.unit * 3,
+        padding: `${theme.spacing.unit}px ${theme.spacing.unit * 3}px`,
         overflowY: "auto",
         flexGrow: 1
     },
         overflowY: "auto",
         flexGrow: 1
     },
@@ -204,7 +204,7 @@ class Workbench extends React.Component<WorkbenchProps, WorkbenchState> {
                     </div>
                     <DetailsPanel 
                         isOpened={this.state.isDetailsPanelOpened} 
                     </div>
                     <DetailsPanel 
                         isOpened={this.state.isDetailsPanelOpened} 
-                        closeDrawer={this.mainAppBarActions.onDetailsPanelToggle} />
+                        onCloseDrawer={this.mainAppBarActions.onDetailsPanelToggle} />
                 </main>
             </div>
         );
                 </main>
             </div>
         );