1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { ReactElement } from 'react';
7 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
8 import { ArvadosTheme } from '../../common/custom-theme';
9 import { List, ListItem, ListItemText, ListItemIcon, Collapse, Typography } from "@material-ui/core";
10 import { SidePanelRightArrowIcon, IconType } from '../icon/icon';
11 import * as classnames from "classnames";
13 export interface SidePanelItem {
23 interface SidePanelProps {
24 toggleOpen: (id: string) => void;
25 toggleActive: (id: string) => void;
26 sidePanelItems: SidePanelItem[];
27 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: SidePanelItem) => void;
30 class SidePanel extends React.Component<SidePanelProps & WithStyles<CssRules>> {
31 render(): ReactElement<any> {
32 const { classes, toggleOpen, toggleActive, sidePanelItems, children } = this.props;
33 const { listItemText, leftSidePanelContainer, row, list, icon, projectIconMargin, active, iconArrowContainer } = classes;
35 <div className={leftSidePanelContainer}>
37 {sidePanelItems.map(it => (
39 <ListItem button className={list} onClick={() => toggleActive(it.id)} onContextMenu={this.handleRowContextMenu(it)}>
40 <span className={row}>
42 <i onClick={() => toggleOpen(it.id)} className={iconArrowContainer}>
43 <SidePanelRightArrowIcon className={this.getIconClassNames(it.open, it.active)} />
46 <ListItemIcon className={it.active ? active : ''}>
47 {<it.icon className={`${icon} ${it.margin ? projectIconMargin : ''}`} />}
49 <ListItemText className={listItemText}
50 primary={renderListItemText(it.name, active, it.active)} />
54 <Collapse in={it.open} timeout="auto" unmountOnExit>
65 getIconClassNames = (itemOpen ?: boolean, itemActive ?: boolean) => {
66 const { classes } = this.props;
67 return classnames(classes.iconArrow, {
68 [classes.iconOpen]: itemOpen,
69 [classes.iconClose]: !itemOpen,
70 [classes.active]: itemActive
74 handleRowContextMenu = (item: SidePanelItem) =>
75 (event: React.MouseEvent<HTMLElement>) =>
76 item.openAble ? this.props.onContextMenu(event, item) : null
80 const renderListItemText = (itemName: string, active: string, itemActive?: boolean) =>
81 <Typography className={itemActive ? active : ''}>{itemName}</Typography>;
83 type CssRules = 'active' | 'listItemText' | 'row' | 'leftSidePanelContainer' | 'list' | 'icon' |
84 'projectIconMargin' | 'iconClose' | 'iconOpen' | 'iconArrowContainer' | 'iconArrow';
86 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
88 color: theme.palette.primary.main,
98 color: theme.palette.grey["700"],
106 transition: 'all 0.1s ease',
109 transition: 'all 0.1s ease',
110 transform: 'rotate(90deg)',
112 leftSidePanelContainer: {
115 whiteSpace: 'nowrap',
121 padding: '5px 0px 5px 14px',
132 export default withStyles(styles)(SidePanel);