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, ListItemIcon, Collapse } 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 type CssRules = 'active' | 'row' | 'root' | 'list' | 'iconClose' | 'iconOpen' | 'toggableIconContainer' | 'toggableIcon';
16 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
26 padding: '5px 0px 5px 14px',
33 toggableIconContainer: {
34 color: theme.palette.grey["700"],
42 color: theme.palette.primary.main,
45 transition: 'all 0.1s ease',
48 transition: 'all 0.1s ease',
49 transform: 'rotate(90deg)',
53 export interface SidePanelItem {
63 interface SidePanelDataProps {
64 toggleOpen: (id: string) => void;
65 toggleActive: (id: string) => void;
66 sidePanelItems: SidePanelItem[];
67 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: SidePanelItem) => void;
70 type SidePanelProps = SidePanelDataProps & WithStyles<CssRules>;
72 export const SidePanel = withStyles(styles)(
73 class extends React.Component<SidePanelProps> {
74 render(): ReactElement<any> {
75 const { classes, toggleOpen, toggleActive, sidePanelItems, children } = this.props;
76 const { root, row, list, toggableIconContainer } = classes;
78 <div className={root}>
80 {sidePanelItems.map(it => (
82 <ListItem button className={list} onClick={() => toggleActive(it.id)}
83 onContextMenu={this.handleRowContextMenu(it)}>
84 <span className={row}>
86 <i onClick={() => toggleOpen(it.id)} className={toggableIconContainer}>
88 className={this.getToggableIconClassNames(it.open, it.active)}>
89 < SidePanelRightArrowIcon/>
93 <ListItemTextIcon icon={it.icon} name={it.name} isActive={it.active}
94 hasMargin={it.margin}/>
98 <Collapse in={it.open} timeout="auto" unmountOnExit>
109 getToggableIconClassNames = (isOpen?: boolean, isActive ?: boolean) => {
110 const { iconOpen, iconClose, active, toggableIcon } = this.props.classes;
111 return classnames(toggableIcon, {
113 [iconClose]: !isOpen,
118 handleRowContextMenu = (item: SidePanelItem) =>
119 (event: React.MouseEvent<HTMLElement>) =>
120 item.openAble ? this.props.onContextMenu(event, item) : null