X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/ce55180216574bddb30dd052215a7320632a9fb1..22cfdad7a451f67b0b4c195b58815cdf2abcfda9:/src/components/tree/tree.tsx

diff --git a/src/components/tree/tree.tsx b/src/components/tree/tree.tsx
index a8cfabd0bf..fdde3c16a6 100644
--- a/src/components/tree/tree.tsx
+++ b/src/components/tree/tree.tsx
@@ -9,12 +9,22 @@ import { StyleRulesCallback, Theme, withStyles, WithStyles } from '@material-ui/
 import { ReactElement } from "react";
 import Collapse from "@material-ui/core/Collapse/Collapse";
 
-type CssRules = 'list';
+type CssRules = 'list' | 'activeArrow' | 'arrow' | 'arrowRotate';
 
 const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
     list: {
         paddingBottom: '3px', 
         paddingTop: '3px',
+    },
+    activeArrow: {
+        color: '#4285F6', 
+        position: 'absolute',
+    },
+    arrow: {
+        position: 'absolute',
+    },
+    arrowRotate: {
+        transform: 'rotate(-90deg)',
     }
 });
 
@@ -34,23 +44,24 @@ interface TreeProps<T> {
 }
 
 class Tree<T> extends React.Component<TreeProps<T> & WithStyles<CssRules>, {}> {
+    renderArrow (items: Array<TreeItem<T>> | undefined, arrowClass: string, isOpen: boolean){
+        return items && items.length > 0 ? <i className={`${arrowClass} ${isOpen ? "fas fa-caret-down" : `fas fa-caret-down ${this.props.classes.arrowRotate}`}`} /> : ''
+    }
     render(): ReactElement<any> {
         const level = this.props.level ? this.props.level : 0;
         const {classes, render, toggleItem, items} = this.props;
-        return <List component="div" className={classes.list}>
+        const {list, arrow, activeArrow, arrowRotate} = classes;
+        return <List component="div" className={list}>
             {items && items.map((it: TreeItem<T>, idx: number) =>
              <div key={`item/${level}/${idx}`}>      
-                <ListItem button onClick={() => toggleItem(it.id)} className={classes.list} style={{paddingLeft: (level + 1) * 15}}>  
-                    {
-                        it.active ? 
-                            (it.items && it.items.length > 0 ? <i style={{color: '#4285F6', position: 'absolute'}} className={it.open ? "fas fa-caret-down" : "fas fa-caret-right"} /> : null) : 
-                            (it.items && it.items.length > 0 ? <i style={{position: 'absolute'}} className={it.open ? "fas fa-caret-down" : "fas fa-caret-right"} /> : null)
-                    }
+                <ListItem button onClick={() => toggleItem(it.id)} className={list} style={{paddingLeft: (level + 1) * 20}}>  
+                    {it.active ? this.renderArrow(it.items, activeArrow, it.open) : this.renderArrow(it.items, arrow, it.open)}
                     {render(it)}
                 </ListItem>
                 {it.items && it.items.length > 0 &&
                 <Collapse in={it.open} timeout="auto" unmountOnExit>
-                    <Tree items={it.items}
+                    <StyledTree 
+                        items={it.items}
                         render={render}
                         toggleItem={toggleItem}
                         level={level + 1}/>
@@ -60,5 +71,5 @@ class Tree<T> extends React.Component<TreeProps<T> & WithStyles<CssRules>, {}> {
     }
 }
 
-
-export default withStyles(styles)(Tree);
+const StyledTree = withStyles(styles)(Tree);
+export default StyledTree
