import React from 'react'; import { makeStyles, Theme, createStyles } from '@material-ui/core/styles'; import TreeView from '@material-ui/lab/TreeView'; import TreeItem, { TreeItemProps } from '@material-ui/lab/TreeItem'; import Typography from '@material-ui/core/Typography'; import MailIcon from '@material-ui/icons/Mail'; import DeleteIcon from '@material-ui/icons/Delete'; import Label from '@material-ui/icons/Label'; import SupervisorAccountIcon from '@material-ui/icons/SupervisorAccount'; import InfoIcon from '@material-ui/icons/Info'; import ForumIcon from '@material-ui/icons/Forum'; import LocalOfferIcon from '@material-ui/icons/LocalOffer'; import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown'; import ArrowRightIcon from '@material-ui/icons/ArrowRight'; import { SvgIconProps } from '@material-ui/core/SvgIcon'; declare module 'csstype' { interface Properties { '--tree-view-color'?: string; '--tree-view-bg-color'?: string; } } type StyledTreeItemProps = TreeItemProps & { bgColor?: string; color?: string; labelIcon: React.ElementType; labelInfo?: string; labelText: string; }; const useTreeItemStyles = makeStyles((theme: Theme) => createStyles({ root: { color: theme.palette.text.secondary, '&:hover > $content': { backgroundColor: theme.palette.action.hover, }, '&:focus > $content, &$selected > $content': { backgroundColor: `var(--tree-view-bg-color, ${theme.palette.grey[400]})`, color: 'var(--tree-view-color)', }, '&:focus > $content $label, &:hover > $content $label, &$selected > $content $label': { backgroundColor: 'transparent', }, }, content: { color: theme.palette.text.secondary, borderTopRightRadius: theme.spacing(2), borderBottomRightRadius: theme.spacing(2), paddingRight: theme.spacing(1), fontWeight: theme.typography.fontWeightMedium, '$expanded > &': { fontWeight: theme.typography.fontWeightRegular, }, }, group: { marginLeft: 0, '& $content': { paddingLeft: theme.spacing(2), }, }, expanded: {}, selected: {}, label: { fontWeight: 'inherit', color: 'inherit', }, labelRoot: { display: 'flex', alignItems: 'center', padding: theme.spacing(0.5, 0), }, labelIcon: { marginRight: theme.spacing(1), }, labelText: { fontWeight: 'inherit', flexGrow: 1, }, }), ); function StyledTreeItem(props: StyledTreeItemProps) { const classes = useTreeItemStyles(); const { labelText, labelIcon: LabelIcon, labelInfo, color, bgColor, ...other } = props; return ( {labelText} {labelInfo} } style={{ '--tree-view-color': color, '--tree-view-bg-color': bgColor, }} classes={{ root: classes.root, content: classes.content, expanded: classes.expanded, selected: classes.selected, group: classes.group, label: classes.label, }} {...other} /> ); } const useStyles = makeStyles( createStyles({ root: { height: 264, flexGrow: 1, maxWidth: 400, }, }), ); export default function GmailTreeView() { const classes = useStyles(); return ( } defaultExpandIcon={} defaultEndIcon={
} > ); }