Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TreeView] Improve overrides story #20159

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/pages/api-docs/tree-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Any other props supplied will be provided to the root element (native element).
| <span class="prop-name">group</span> | <span class="prop-name">.MuiTreeItem-group</span> | Styles applied to the `role="group"` element.
| <span class="prop-name">content</span> | <span class="prop-name">.MuiTreeItem-content</span> | Styles applied to the tree node content.
| <span class="prop-name">iconContainer</span> | <span class="prop-name">.MuiTreeItem-iconContainer</span> | Styles applied to the tree node icon and collapse/expand icon.
| <span class="prop-name">labelContainer</span> | <span class="prop-name">.MuiTreeItem-labelContainer</span> | Styles applied to the label container.
| <span class="prop-name">label</span> | <span class="prop-name">.MuiTreeItem-label</span> | Styles applied to the label element.

You can override the style of the component thanks to one of these customization points:
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/tree-view/GmailTreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ const useTreeItemStyles = makeStyles((theme) => ({
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,
Expand All @@ -53,7 +50,7 @@ const useTreeItemStyles = makeStyles((theme) => ({
labelRoot: {
display: 'flex',
alignItems: 'center',
padding: theme.spacing(0.5, 0),
padding: theme.spacing(0.5, 0, 0.5, 0.5),
},
labelIcon: {
marginRight: theme.spacing(1),
Expand Down
5 changes: 1 addition & 4 deletions docs/src/pages/components/tree-view/GmailTreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ const useTreeItemStyles = makeStyles((theme: Theme) =>
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,
Expand All @@ -69,7 +66,7 @@ const useTreeItemStyles = makeStyles((theme: Theme) =>
labelRoot: {
display: 'flex',
alignItems: 'center',
padding: theme.spacing(0.5, 0),
padding: theme.spacing(0.5, 0, 0.5, 0.5),
},
labelIcon: {
marginRight: theme.spacing(1),
Expand Down
5 changes: 3 additions & 2 deletions docs/src/pages/customization/default-theme/DefaultTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import clsx from 'clsx';
import { makeStyles, withStyles, createMuiTheme, lighten } from '@material-ui/core/styles';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Switch from '@material-ui/core/Switch';
import Typography from '@material-ui/core/Typography';

/**
* @param {unknown} value
Expand Down Expand Up @@ -96,15 +97,15 @@ function ObjectEntryLabel(props) {
const classes = useObjectEntryLabelStyles();

return (
<React.Fragment>
<Typography component="div">
{`${objectKey}: `}
{type === 'color' ? (
<span className={classes.color} style={{ borderColor: lighten(label, 0.7) }}>
<span className={classes.colorInner} style={{ backgroundColor: label }} />
</span>
) : null}
<span className={clsx('token', tokenType)}>{label}</span>
</React.Fragment>
</Typography>
);
}

Expand Down
19 changes: 14 additions & 5 deletions packages/material-ui-lab/src/TreeItem/TreeItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ export const styles = (theme) => ({
fontSize: 18,
},
},
/* Styles applied to the label container. */
labelContainer: {
width: '100%',
position: 'relative',
},
/* Styles applied to the label element. */
label: {
width: '100%',
paddingLeft: 4,
position: 'relative',
'&:hover': {
backgroundColor: theme.palette.action.hover,
// Reset on touch devices, it doesn't add specificity
Expand Down Expand Up @@ -395,9 +398,15 @@ const TreeItem = React.forwardRef(function TreeItem(props, ref) {
ref={contentRef}
>
<div className={classes.iconContainer}>{icon}</div>
<Typography component="div" className={classes.label}>
{label}
</Typography>
<div className={classes.labelContainer}>
{React.isValidElement(label) ? (
label
) : (
<Typography component="div" className={classes.label}>
{label}
</Typography>
)}
</div>
</div>
{children && (
<TransitionComponent
Expand Down