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 typescript error when using sx property on ChartsTooltip #12659

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/x-charts/src/ChartsTooltip/ChartsTooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import composeClasses from '@mui/utils/composeClasses';
import { styled, useThemeProps } from '@mui/material/styles';
import { Popper, PopperProps } from '@mui/base/Popper';
import { styled, useThemeProps, SxProps, Theme } from '@mui/material/styles';
import { Popper, PopperProps as BasePopperProps } from '@mui/base/Popper';
import { NoSsr } from '@mui/base/NoSsr';
import { useSlotProps } from '@mui/base/utils';
import {
Expand All @@ -21,6 +21,13 @@ import { ChartsItemContentProps, ChartsItemTooltipContent } from './ChartsItemTo
import { ChartsAxisContentProps, ChartsAxisTooltipContent } from './ChartsAxisTooltipContent';
import { ChartsTooltipClasses, getChartsTooltipUtilityClass } from './chartsTooltipClasses';

export type PopperProps = BasePopperProps & {
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: IMHO, this type could have also been prefixed with Charts to avoid the conflict with base and material types.

Copy link
Member Author

Choose a reason for hiding this comment

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

That could be better indeed, is there a pattern we follow in such cases? Like, both material and base are PopperProps, so there is already some confusion there 🤔

Copy link
Member

Choose a reason for hiding this comment

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

There are no hard rules and material/base are not an examples of making types unique.
For Charts we somewhat settled on trying to prefix types (especially generic ones) with Charts to avoid further confusion.
For example, we have the ChartsGridProps instead of GridProps to avoid potential errors. 🙈
Maybe @alexfauquette has a more clear vision/direction for type naming? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Since the component name is ChartsTooltipRoot I assume we could have named it ChartsTooltipRootProps But those naming are not ideal. They would benefit an entire renaming to harmonize the notion of tooltip/popper

I do not expect user to use it, or if they do the confusion with the core type should not be a big deal since they are quite similar

/**
* The system prop that allows defining system overrides as well as additional CSS styles.
*/
sx?: SxProps<Theme>;
};

export interface ChartsTooltipSlots {
/**
* Custom component for the tooltip popper.
Expand Down