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";
12 import ListItemTextIcon from '../list-item-text-icon/list-item-text-icon';
14 export interface SidePanelItem {
24 interface SidePanelProps {
25 toggleOpen: (id: string) => void;
26 toggleActive: (id: string) => void;
27 sidePanelItems: SidePanelItem[];
28 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: SidePanelItem) => void;
31 class SidePanel extends React.Component<SidePanelProps & WithStyles<CssRules>> {
32 render(): ReactElement<any> {
33 const { classes, toggleOpen, toggleActive, sidePanelItems, children } = this.props;
34 const { root, row, list, toggableIconContainer } = classes;
36 <div className={root}>
38 {sidePanelItems.map(it => (
40 <ListItem button className={list} onClick={() => toggleActive(it.id)} onContextMenu={this.handleRowContextMenu(it)}>
41 <span className={row}>
43 <i onClick={() => toggleOpen(it.id)} className={toggableIconContainer}>
44 <ListItemIcon className={this.getToggableIconClassNames(it.open, it.active)}>
45 < SidePanelRightArrowIcon />
49 <ListItemTextIcon icon={it.icon} name={it.name} isActive={it.active} hasMargin={it.margin} />
53 <Collapse in={it.open} timeout="auto" unmountOnExit>
64 getToggableIconClassNames = (isOpen?: boolean, isActive ?: boolean) => {
65 const { classes } = this.props;
66 return classnames(classes.toggableIcon, {
67 [classes.iconOpen]: isOpen,
68 [classes.iconClose]: !isOpen,
69 [classes.active]: isActive
73 handleRowContextMenu = (item: SidePanelItem) =>
74 (event: React.MouseEvent<HTMLElement>) =>
75 item.openAble ? this.props.onContextMenu(event, item) : null
79 type CssRules = 'active' | 'row' | 'root' | 'list' | 'iconClose' | 'iconOpen' | 'toggableIconContainer' | 'toggableIcon';
81 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
91 padding: '5px 0px 5px 14px',
98 toggableIconContainer: {
99 color: theme.palette.grey["700"],
107 color: theme.palette.primary.main,
110 transition: 'all 0.1s ease',
113 transition: 'all 0.1s ease',
114 transform: 'rotate(90deg)',
118 export default withStyles(styles)(SidePanel);