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

[charts] Fix themeAugmentation #14372

Merged
merged 8 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 7 additions & 6 deletions packages/x-charts/src/ChartsTooltip/ChartsTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const useUtilityClasses = <T extends ChartSeriesType>(ownerState: {

const slots = {
root: ['root'],
paper: ['paper'],
table: ['table'],
row: ['row'],
cell: ['cell'],
Expand Down Expand Up @@ -124,12 +125,12 @@ const ChartsTooltipRoot = styled(Popper, {
*
* - [ChartsTooltip API](https://mui.com/x/api/charts/charts-tool-tip/)
*/
function ChartsTooltip<T extends ChartSeriesType>(props: ChartsTooltipProps<T>) {
const themeProps = useThemeProps({
props,
function ChartsTooltip<T extends ChartSeriesType>(inProps: ChartsTooltipProps<T>) {
const props = useThemeProps({
props: inProps,
name: 'MuiChartsTooltip',
});
const { trigger = 'axis', itemContent, axisContent, slots, slotProps } = themeProps;
const { trigger = 'axis', itemContent, axisContent, slots, slotProps } = props;

const mousePosition = useMouseTracker();

Expand All @@ -140,7 +141,7 @@ function ChartsTooltip<T extends ChartSeriesType>(props: ChartsTooltipProps<T>)
const tooltipHasData = getTooltipHasData(trigger, displayedData);
const popperOpen = mousePosition !== null && tooltipHasData;

const classes = useUtilityClasses({ classes: themeProps.classes });
const classes = useUtilityClasses({ classes: props.classes });

const PopperComponent = slots?.popper ?? ChartsTooltipRoot;
const popperProps = useSlotProps({
Expand Down Expand Up @@ -170,7 +171,7 @@ function ChartsTooltip<T extends ChartSeriesType>(props: ChartsTooltipProps<T>)
return (
<NoSsr>
{popperOpen && (
<PopperComponent {...popperProps}>
<PopperComponent {...popperProps} className={classes.root}>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before that change, the PopperComponent has the styleOverride.root, but the classes.root was on the ChartsTooltipPaper

With that modification both styleOverrides.root and classes.root are on the same component

{trigger === 'item' ? (
<ChartsItemTooltipContent
itemData={displayedData as ItemInteractionData<T>}
Expand Down
5 changes: 5 additions & 0 deletions packages/x-charts/src/ChartsTooltip/ChartsTooltipTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { chartsTooltipClasses } from './chartsTooltipClasses';
export const ChartsTooltipPaper = styled('div', {
name: 'MuiChartsTooltip',
slot: 'Container',
overridesResolver: (props, styles) => styles.paper,
})(({ theme }) => ({
boxShadow: theme.shadows[1],
backgroundColor: (theme.vars || theme).palette.background.paper,
Expand All @@ -22,6 +23,7 @@ export const ChartsTooltipPaper = styled('div', {
export const ChartsTooltipTable = styled('table', {
name: 'MuiChartsTooltip',
slot: 'Table',
overridesResolver: (props, styles) => styles.table,
})(({ theme }) => ({
borderSpacing: 0,
'& thead td': {
Expand All @@ -35,6 +37,7 @@ export const ChartsTooltipTable = styled('table', {
export const ChartsTooltipRow = styled('tr', {
name: 'MuiChartsTooltip',
slot: 'Row',
overridesResolver: (props, styles) => styles.row,
})(({ theme }) => ({
'tr:first-of-type& td': {
paddingTop: theme.spacing(1),
Expand All @@ -50,6 +53,7 @@ export const ChartsTooltipRow = styled('tr', {
export const ChartsTooltipCell = styled('td', {
name: 'MuiChartsTooltip',
slot: 'Cell',
overridesResolver: (props, styles) => styles.cell,
})(({ theme }) => ({
verticalAlign: 'middle',
color: (theme.vars || theme).palette.text.secondary,
Expand All @@ -74,6 +78,7 @@ export const ChartsTooltipCell = styled('td', {
export const ChartsTooltipMark = styled('div', {
name: 'MuiChartsTooltip',
slot: 'Mark',
overridesResolver: (props, styles) => styles.mark,
shouldForwardProp: (prop) => shouldForwardProp(prop) && prop !== 'color',
})<{ color: string }>(({ theme, color }) => ({
width: theme.spacing(1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function DefaultChartsAxisTooltipContent(props: ChartsAxisContentProps) {
axis.scaleType === 'utc' ? utcFormatter(v) : v.toLocaleString());

return (
<ChartsTooltipPaper sx={sx} className={classes.root}>
<ChartsTooltipPaper sx={sx} className={classes.paper}>
<ChartsTooltipTable className={classes.table}>
{axisValue != null && !axis.hideTooltip && (
<thead>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function DefaultChartsItemTooltipContent<T extends ChartSeriesType = ChartSeries
series.valueFormatter as CommonSeriesType<typeof value>['valueFormatter']
)?.(value, { dataIndex: itemData.dataIndex });
return (
<ChartsTooltipPaper sx={sx} className={classes.root}>
<ChartsTooltipPaper sx={sx} className={classes.paper}>
<ChartsTooltipTable className={classes.table}>
<tbody>
<ChartsTooltipRow className={classes.row}>
Expand Down
4 changes: 3 additions & 1 deletion packages/x-charts/src/ChartsTooltip/chartsTooltipClasses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
export interface ChartsTooltipClasses {
/** Styles applied to the root element. */
root: string;
/** Styles applied to the paper element. */
paper: string;
/** Styles applied to the table element. */
table: string;
/** Styles applied to the row element. */
Expand Down Expand Up @@ -33,5 +35,5 @@ export function getChartsTooltipUtilityClass(slot: string) {
}
export const chartsTooltipClasses: ChartsTooltipClasses = generateUtilityClasses(
'MuiChartsTooltip',
['root', 'table', 'row', 'cell', 'mark', 'markCell', 'labelCell', 'valueCell'],
['root', 'paper', 'table', 'row', 'cell', 'mark', 'markCell', 'labelCell', 'valueCell'],
);
1 change: 0 additions & 1 deletion packages/x-charts/src/themeAugmentation/overrides.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { BarLabelClassKey } from '../BarChart';
import { BarElementClassKey } from '../BarChart/BarElement';
import { ChartsAxisHighlightClassKey } from '../ChartsAxisHighlight';
import { ChartsGridClassKey } from '../ChartsGrid';

import { ChartsTooltipClassKey } from '../ChartsTooltip';
import { AreaElementClassKey, LineElementClassKey, MarkElementClassKey } from '../LineChart';

Expand Down