15012: Uses varargs version of joinFilters().
[arvados-workbench2.git] / src / components / list-item-text-icon / list-item-text-icon.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
7 import { ArvadosTheme } from '~/common/custom-theme';
8 import { ListItemIcon, ListItemText, Typography } from '@material-ui/core';
9 import { IconType } from '../icon/icon';
10 import * as classnames from "classnames";
11
12 type CssRules = 'root' | 'listItemText' | 'hasMargin' | 'active';
13
14 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
15     root: {
16         display: 'flex',
17         alignItems: 'center'
18     },
19     listItemText: {
20         fontWeight: 400
21     },
22     active: {
23         color: theme.palette.primary.main,
24     },
25     hasMargin: {
26         marginLeft: `${theme.spacing.unit}px`,
27     }
28 });
29
30 export interface ListItemTextIconDataProps {
31     icon: IconType;
32     name: string;
33     isActive?: boolean;
34     hasMargin?: boolean;
35     iconSize?: number;
36     nameDecorator?: JSX.Element;
37 }
38
39 type ListItemTextIconProps = ListItemTextIconDataProps & WithStyles<CssRules>;
40
41 export const ListItemTextIcon = withStyles(styles)(
42     class extends React.Component<ListItemTextIconProps, {}> {
43         render() {
44             const { classes, isActive, hasMargin, name, icon: Icon, iconSize, nameDecorator } = this.props;
45             return (
46                 <Typography component='span' className={classes.root}>
47                     <ListItemIcon className={classnames({
48                             [classes.hasMargin]: hasMargin,
49                             [classes.active]: isActive
50                         })}>
51
52                         <Icon style={{ fontSize: `${iconSize}rem` }} />
53                     </ListItemIcon>
54                     {nameDecorator || null}
55                     <ListItemText primary={
56                         <Typography className={classnames(classes.listItemText, {
57                                 [classes.active]: isActive
58                             })}>
59                             {name}
60                         </Typography>
61                     } />
62                 </Typography>
63             );
64         }
65     }
66 );