Refactor data-explorer to make it background more customizable, add slot for custom...
[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 }
37
38 type ListItemTextIconProps = ListItemTextIconDataProps & WithStyles<CssRules>;
39
40 export const ListItemTextIcon = withStyles(styles)(
41     class extends React.Component<ListItemTextIconProps, {}> {
42         render() {
43             const { classes, isActive, hasMargin, name, icon: Icon, iconSize } = this.props;
44             return (
45                 <Typography component='span' className={classes.root}>
46                     <ListItemIcon className={classnames({
47                             [classes.hasMargin]: hasMargin,
48                             [classes.active]: isActive
49                         })}>
50
51                         <Icon style={{ fontSize: `${iconSize}rem` }} />
52                     </ListItemIcon>
53                     <ListItemText primary={
54                         <Typography variant='body1' className={classnames(classes.listItemText, {
55                                 [classes.active]: isActive
56                             })}>
57                             {name}
58                         </Typography>
59                     } />
60                 </Typography>
61             );
62         }
63     }
64 );