Update material UI to 3.3.2 and fix side panel icon sizes
[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' | 'fixFontSize';
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     fixFontSize: {
29         fontSize: '1.25rem'
30     }
31 });
32
33 export interface ListItemTextIconDataProps {
34     icon: IconType;
35     name: string;
36     isActive?: boolean;
37     hasMargin?: boolean;
38     fixFontSize?: boolean;
39 }
40
41 type ListItemTextIconProps = ListItemTextIconDataProps & WithStyles<CssRules>;
42
43 export const ListItemTextIcon = withStyles(styles)(
44     class extends React.Component<ListItemTextIconProps, {}> {
45         render() {
46             const { classes, isActive, hasMargin, name, icon: Icon, fixFontSize } = this.props;
47             return (
48                 <Typography component='span' className={classes.root}>
49                     <ListItemIcon className={classnames({
50                             [classes.hasMargin]: hasMargin,
51                             [classes.active]: isActive
52                         })}>
53                         <Icon className={classnames({
54                             [classes.fixFontSize]: fixFontSize
55                         })}/>
56                     </ListItemIcon>
57                     <ListItemText primary={
58                         <Typography variant='body1' className={classnames(classes.listItemText, {
59                                 [classes.active]: isActive
60                             })}>
61                             {name}
62                         </Typography>
63                     } />
64                 </Typography>
65             );
66         }
67     }
68 );