X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/dca911684e2f09e518e976f9e1e3d3c2aec2c86a..10ce16c28de952f6533ca3cc9df909269e3d2a53:/src/components/side-panel/side-panel.tsx?ds=sidebyside

diff --git a/src/components/side-panel/side-panel.tsx b/src/components/side-panel/side-panel.tsx
index 8b4398be77..4240b1bfd2 100644
--- a/src/components/side-panel/side-panel.tsx
+++ b/src/components/side-panel/side-panel.tsx
@@ -6,124 +6,117 @@ import * as React from 'react';
 import { ReactElement } from 'react';
 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
 import { ArvadosTheme } from '../../common/custom-theme';
-import { List, ListItem, ListItemText, ListItemIcon, Collapse, Typography } from "@material-ui/core";
-import IconBase, { IconTypes } from '../icon/icon';
+import { List, ListItem, ListItemIcon, Collapse } from "@material-ui/core";
+import { SidePanelRightArrowIcon, IconType } from '../icon/icon';
+import * as classnames from "classnames";
+import { ListItemTextIcon } from '../list-item-text-icon/list-item-text-icon';
 
-export interface SidePanelItem {
-    id: string;
-    name: string;
-    icon: IconTypes;
-    active?: boolean;
-    open?: boolean;
-    margin?: boolean;
-    openAble?: boolean;
-}
-
-interface SidePanelProps {
-    toggleOpen: (id: string) => void;
-    toggleActive: (id: string) => void;
-    sidePanelItems: SidePanelItem[];
-    onContextMenu: (event: React.MouseEvent<HTMLElement>, item: SidePanelItem) => void;
-}
-
-class SidePanel extends React.Component<SidePanelProps & WithStyles<CssRules>> {
-    render(): ReactElement<any> {
-        const { classes, toggleOpen, toggleActive, sidePanelItems, children } = this.props;
-        const { listItemText, leftSidePanelContainer, row, list, icon, projectIconMargin, active, 
-            iconOpen, iconClose, iconArrow, iconArrowContainer } = classes;
-        return (
-            <div className={leftSidePanelContainer}>
-                <List>
-                    {sidePanelItems.map(it => (
-                        <span key={it.name}>
-                            <ListItem button className={list} onClick={() => toggleActive(it.id)} onContextMenu={this.handleRowContextMenu(it)}>
-                                <span className={row}>
-                                    {it.openAble ? (
-                                        <i onClick={() => toggleOpen(it.id)} className={iconArrowContainer}>
-                                            <IconBase icon={IconTypes.PLAY_ARROW} 
-                                                className={`
-                                                    ${iconArrow}
-                                                    ${it.active ? active : ''}
-                                                    ${it.open ? iconOpen : iconClose} 
-                                                `} />
-                                        </i>
-                                    ) : null}
-                                    <ListItemIcon className={it.active ? active : ''}>
-                                        <IconBase icon={it.icon} 
-                                            className={ `${icon} ${it.margin ? projectIconMargin : ''}` } />
-                                    </ListItemIcon>
-                                    <ListItemText className={listItemText} 
-                                        primary={renderListItemText(it.name, active, it.active)} />
-                                </span>
-                            </ListItem>
-                            {it.openAble ? (
-                                <Collapse in={it.open} timeout="auto" unmountOnExit>
-                                    {children}
-                                </Collapse>
-                            ) : null}
-                        </span>
-                    ))}
-                </List>
-            </div>
-        );
-    }
-
-    handleRowContextMenu = (item: SidePanelItem) =>
-        (event: React.MouseEvent<HTMLElement>) =>
-            item.openAble ? this.props.onContextMenu(event, item) : null
-
-}
-
-const renderListItemText = (itemName: string, active: string, itemActive?: boolean) =>
-    <Typography className={itemActive ? active : ''}>{itemName}</Typography>;
-
-type CssRules = 'active' | 'listItemText' | 'row' | 'leftSidePanelContainer' | 'list' | 'icon' | 
-    'projectIconMargin' | 'iconClose' | 'iconOpen' | 'iconArrowContainer' | 'iconArrow';
+type CssRules = 'active' | 'row' | 'root' | 'list' | 'iconClose' | 'iconOpen' | 'toggableIconContainer' | 'toggableIcon';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
-    active: {
-        color: theme.palette.primary.main,
+    root: {
+        overflowY: 'auto',
+        minWidth: '240px',
+        whiteSpace: 'nowrap',
+        marginTop: '52px',
+        display: 'flex',
+        flexGrow: 1,
     },
-    listItemText: {
-        padding: '0px',
+    list: {
+        padding: '5px 0px 5px 14px',
+        minWidth: '240px',
     },
     row: {
         display: 'flex',
         alignItems: 'center',
     },
-    iconArrowContainer: {
+    toggableIconContainer: {
         color: theme.palette.grey["700"],
         height: '14px',
         position: 'absolute'
     },
-    iconArrow: {
+    toggableIcon: {
         fontSize: '14px'
     },
+    active: {
+        color: theme.palette.primary.main,
+    },
     iconClose: {
         transition: 'all 0.1s ease',
     },
     iconOpen: {
         transition: 'all 0.1s ease',
         transform: 'rotate(90deg)',
-    },
-    leftSidePanelContainer: {
-        overflowY: 'auto',
-        minWidth: '240px',
-        whiteSpace: 'nowrap',
-        marginTop: '52px',
-        display: 'flex',
-        flexGrow: 1,
-    },
-    list: {
-        padding: '5px 0px 5px 14px',
-        minWidth: '240px',
-    },
-    icon: {
-        fontSize: '20px'
-    },
-    projectIconMargin: {
-        marginLeft: '17px',
     }
 });
 
-export default withStyles(styles)(SidePanel);
\ No newline at end of file
+export interface SidePanelItem {
+    id: string;
+    name: string;
+    icon: IconType;
+    active?: boolean;
+    open?: boolean;
+    margin?: boolean;
+    openAble?: boolean;
+}
+
+interface SidePanelDataProps {
+    toggleOpen: (id: string) => void;
+    toggleActive: (id: string) => void;
+    sidePanelItems: SidePanelItem[];
+    onContextMenu: (event: React.MouseEvent<HTMLElement>, item: SidePanelItem) => void;
+}
+
+type SidePanelProps = SidePanelDataProps & WithStyles<CssRules>;
+
+export const SidePanel = withStyles(styles)(
+    class extends React.Component<SidePanelProps> {
+        render(): ReactElement<any> {
+            const { classes, toggleOpen, toggleActive, sidePanelItems, children } = this.props;
+            const { root, row, list, toggableIconContainer } = classes;
+            return (
+                <div className={root}>
+                    <List>
+                        {sidePanelItems.map(it => (
+                            <span key={it.name}>
+                                <ListItem button className={list} onClick={() => toggleActive(it.id)}
+                                          onContextMenu={this.handleRowContextMenu(it)}>
+                                    <span className={row}>
+                                        {it.openAble ? (
+                                            <i onClick={() => toggleOpen(it.id)} className={toggableIconContainer}>
+                                                <ListItemIcon
+                                                    className={this.getToggableIconClassNames(it.open, it.active)}>
+                                                    < SidePanelRightArrowIcon/>
+                                                </ListItemIcon>
+                                            </i>
+                                        ) : null}
+                                        <ListItemTextIcon icon={it.icon} name={it.name} isActive={it.active}
+                                                          hasMargin={it.margin}/>
+                                    </span>
+                                </ListItem>
+                                {it.openAble ? (
+                                    <Collapse in={it.open} timeout="auto" unmountOnExit>
+                                        {children}
+                                    </Collapse>
+                                ) : null}
+                            </span>
+                        ))}
+                    </List>
+                </div>
+            );
+        }
+
+        getToggableIconClassNames = (isOpen?: boolean, isActive ?: boolean) => {
+            const { classes } = this.props;
+            return classnames(classes.toggableIcon, {
+                [classes.iconOpen]: isOpen,
+                [classes.iconClose]: !isOpen,
+                [classes.active]: isActive
+            });
+        }
+
+        handleRowContextMenu = (item: SidePanelItem) =>
+            (event: React.MouseEvent<HTMLElement>) =>
+                item.openAble ? this.props.onContextMenu(event, item) : null
+    }
+);
