Skip to content

Commit

Permalink
[charts] Add ownerState function to slotProps typing when availab…
Browse files Browse the repository at this point in the history
…le (mui#13965)
  • Loading branch information
alexfauquette authored and thomasmoon committed Sep 6, 2024
1 parent f9c1815 commit 3cef882
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/x-charts/src/BarChart/BarElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { styled } from '@mui/material/styles';
import { color as d3Color } from 'd3-color';
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
import { AnimatedProps, animated } from '@react-spring/web';
import { SlotComponentPropsFromProps } from '../internals/SlotComponentPropsFromProps';
import { useInteractionItemProps } from '../hooks/useInteractionItemProps';
import { SeriesId } from '../models/seriesType/common';
import { useItemHighlighted } from '../context';
Expand Down Expand Up @@ -78,9 +79,8 @@ export interface BarElementSlots {
*/
bar?: React.ElementType<BarProps>;
}

export interface BarElementSlotProps {
bar?: Partial<BarProps>;
bar?: SlotComponentPropsFromProps<BarProps, {}, BarElementOwnerState>;
}

export type BarElementProps = Omit<BarElementOwnerState, 'isFaded' | 'isHighlighted'> &
Expand Down
3 changes: 2 additions & 1 deletion packages/x-charts/src/BarChart/BarLabel/BarLabelItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import { useSlotProps } from '@mui/base/utils';
import PropTypes from 'prop-types';
import { SlotComponentPropsFromProps } from '../../internals/SlotComponentPropsFromProps';
import { useUtilityClasses } from './barLabelClasses';
import { BarLabelOwnerState, BarItem, BarLabelContext } from './BarLabel.types';
import { getBarLabel } from './getBarLabel';
Expand All @@ -16,7 +17,7 @@ export interface BarLabelSlots {
}

export interface BarLabelSlotProps {
barLabel?: Partial<BarLabelProps>;
barLabel?: SlotComponentPropsFromProps<BarLabelProps, {}, BarLabelOwnerState>;
}

export type BarLabelItemProps = Omit<BarLabelOwnerState, 'isFaded' | 'isHighlighted'> &
Expand Down
5 changes: 3 additions & 2 deletions packages/x-charts/src/ChartsOverlay/ChartsOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { SxProps, Theme } from '@mui/material/styles';
import { SlotComponentPropsFromProps } from '../internals/SlotComponentPropsFromProps';
import { ChartsLoadingOverlay } from './ChartsLoadingOverlay';
import { useSeries } from '../hooks/useSeries';
import { SeriesId } from '../models/seriesType/common';
Expand Down Expand Up @@ -39,8 +40,8 @@ export interface ChartsOverlaySlots {
noDataOverlay?: React.ElementType<CommonOverlayProps>;
}
export interface ChartsOverlaySlotProps {
loadingOverlay?: Partial<CommonOverlayProps>;
noDataOverlay?: Partial<CommonOverlayProps>;
loadingOverlay?: SlotComponentPropsFromProps<CommonOverlayProps, {}, {}>;
noDataOverlay?: SlotComponentPropsFromProps<CommonOverlayProps, {}, {}>;
}

export interface ChartsOverlayProps {
Expand Down
3 changes: 2 additions & 1 deletion packages/x-charts/src/LineChart/AreaElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import composeClasses from '@mui/utils/composeClasses';
import { useSlotProps } from '@mui/base/utils';
import generateUtilityClass from '@mui/utils/generateUtilityClass';
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
import { SlotComponentPropsFromProps } from '../internals/SlotComponentPropsFromProps';
import { useInteractionItemProps } from '../hooks/useInteractionItemProps';
import { AnimatedArea, AnimatedAreaProps } from './AnimatedArea';
import { SeriesId } from '../models/seriesType/common';
Expand Down Expand Up @@ -57,7 +58,7 @@ export interface AreaElementSlots {
}

export interface AreaElementSlotProps {
area?: AnimatedAreaProps;
area?: SlotComponentPropsFromProps<AnimatedAreaProps, {}, AreaElementOwnerState>;
}

export interface AreaElementProps
Expand Down
3 changes: 2 additions & 1 deletion packages/x-charts/src/LineChart/LineElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import composeClasses from '@mui/utils/composeClasses';
import { useSlotProps } from '@mui/base/utils';
import generateUtilityClass from '@mui/utils/generateUtilityClass';
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
import { SlotComponentPropsFromProps } from '../internals/SlotComponentPropsFromProps';
import { useInteractionItemProps } from '../hooks/useInteractionItemProps';
import { AnimatedLine, AnimatedLineProps } from './AnimatedLine';
import { SeriesId } from '../models/seriesType/common';
Expand Down Expand Up @@ -57,7 +58,7 @@ export interface LineElementSlots {
}

export interface LineElementSlotProps {
line?: AnimatedLineProps;
line?: SlotComponentPropsFromProps<AnimatedLineProps, {}, LineElementOwnerState>;
}

export interface LineElementProps
Expand Down
3 changes: 2 additions & 1 deletion packages/x-charts/src/LineChart/LineHighlightPlot.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import { SlotComponentPropsFromProps } from '../internals/SlotComponentPropsFromProps';
import { useCartesianContext } from '../context/CartesianProvider';
import { LineHighlightElement, LineHighlightElementProps } from './LineHighlightElement';
import { getValueToPositionMapper } from '../hooks/useScale';
Expand All @@ -14,7 +15,7 @@ export interface LineHighlightPlotSlots {
}

export interface LineHighlightPlotSlotProps {
lineHighlight?: Partial<LineHighlightElementProps>;
lineHighlight?: SlotComponentPropsFromProps<LineHighlightElementProps, {}, {}>;
}

export interface LineHighlightPlotProps extends React.SVGAttributes<SVGSVGElement> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type SlotComponentPropsFromProps<
TProps extends {},
TOverrides extends {},
TOwnerState extends {},
> = (Partial<TProps> & TOverrides) | ((ownerState: TOwnerState) => Partial<TProps> & TOverrides);

0 comments on commit 3cef882

Please sign in to comment.