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 TS bottle neck #13137

Merged
merged 2 commits into from
May 15, 2024
Merged
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
19 changes: 14 additions & 5 deletions packages/x-charts/src/BarChart/BarElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import generateUtilityClass from '@mui/utils/generateUtilityClass';
import { styled } from '@mui/material/styles';
import { color as d3Color } from 'd3-color';
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
import { animated } from '@react-spring/web';
import { AnimatedProps, animated } from '@react-spring/web';
import {
getIsFaded,
getIsHighlighted,
Expand Down Expand Up @@ -62,9 +62,18 @@ export const BarElementPath = styled(animated.rect, {
opacity: (ownerState.isFaded && 0.3) || 1,
}));

interface BarProps extends Omit<React.ComponentPropsWithoutRef<'path'>, 'id' | 'color'> {
interface BarProps
extends Omit<
React.SVGProps<SVGRectElement>,
'id' | 'color' | 'ref' | 'x' | 'y' | 'height' | 'width'
>,
AnimatedProps<{
x?: string | number | undefined;
y?: string | number | undefined;
height?: string | number | undefined;
width?: string | number | undefined;
}> {
highlightScope?: Partial<HighlightScope>;
onClick?: (event: React.MouseEvent<SVGPathElement, MouseEvent>) => void;
ownerState: BarElementOwnerState;
}

Expand All @@ -73,7 +82,7 @@ export interface BarElementSlots {
* The component that renders the bar.
* @default BarElementPath
*/
bar?: React.JSXElementConstructor<BarProps>;
bar?: React.ElementType<BarProps>;
}

export interface BarElementSlotProps {
Expand Down Expand Up @@ -130,7 +139,7 @@ function BarElement(props: BarElementProps) {
};
const classes = useUtilityClasses(ownerState);

const Bar = slots?.bar ?? BarElementPath;
const Bar = slots?.bar ?? (BarElementPath as React.ElementType<BarProps>);

const barProps = useSlotProps({
elementType: Bar,
Expand Down
Loading