Skip to content

Commit

Permalink
Add some theme augmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette committed Feb 15, 2024
1 parent e2f8137 commit 28e4c7b
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { ChartsXReferenceLine, ChartsXReferenceLineProps } from './ChartsXRefere
import { ChartsYReferenceLine, ChartsYReferenceLineProps } from './ChartsYReferenceLine';
import { XOR } from '../internals/utils';

type ChartsReferenceLineProps<TValue extends string | number | Date = string | number | Date> = XOR<
ChartsXReferenceLineProps<TValue>,
ChartsYReferenceLineProps<TValue>
>;
export type ChartsReferenceLineProps<
TValue extends string | number | Date = string | number | Date,
> = XOR<ChartsXReferenceLineProps<TValue>, ChartsYReferenceLineProps<TValue>>;

function ChartsReferenceLine(props: ChartsReferenceLineProps) {
const { x, y } = props;
Expand Down
16 changes: 16 additions & 0 deletions packages/x-charts/src/themeAugmentation/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ export interface ChartsComponents {
MuiScatter?: {
defaultProps?: ComponentsProps['MuiScatter'];
};
MuiPieArc?: {
defaultProps?: ComponentsProps['MuiPieArc'];
styleOverrides?: ComponentsOverrides['MuiPieArc'];
};
MuiPieArcLabel?: {
defaultProps?: ComponentsProps['MuiPieArcLabel'];
styleOverrides?: ComponentsOverrides['MuiPieArcLabel'];
};
MuiChartsReferenceLine?: {
defaultProps?: ComponentsProps['MuiChartsReferenceLine'];
styleOverrides?: ComponentsOverrides['MuiChartsReferenceLine'];
};
MuiChartsGrid?: {
defaultProps?: ComponentsProps['MuiChartsGrid'];
styleOverrides?: ComponentsOverrides['MuiChartsGrid'];
};
}

declare module '@mui/material/styles' {
Expand Down
18 changes: 16 additions & 2 deletions packages/x-charts/src/themeAugmentation/overrides.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { BarElementClassKey } from '../BarChart/BarElement';
import { ChartsAxisClassKey } from '../ChartsAxis';
import { ChartsAxisHighlightClassKey } from '../ChartsAxisHighlight';
import { ChartsGridClassKey } from '../ChartsGrid';
import { ChartsLegendClassKey } from '../ChartsLegend';
import { ChartsReferenceLineClassKey } from '../ChartsReferenceLine';
import { ChartsTooltipClassKey } from '../ChartsTooltip';
import { AreaElementClassKey, LineElementClassKey, MarkElementClassKey } from '../LineChart';
import { PieArcClassKey, PieArcLabelClassKey } from '../PieChart';

// prettier-ignore
export interface PickersComponentNameToClassKey {
Expand All @@ -14,13 +17,24 @@ export interface PickersComponentNameToClassKey {

// BarChart components
MuiBarElement: BarElementClassKey;

// LineChart components

MuiAreaElement: AreaElementClassKey;
MuiLineElement: LineElementClassKey;
MuiMarkElement: MarkElementClassKey;
// ScatterChart components

// ScatterChart components


// PieChart components
MuiPieArc: PieArcClassKey;
MuiPieArcLabel: PieArcLabelClassKey;

// Reference line
MuiChartsReferenceLine: ChartsReferenceLineClassKey;

// Grid
MuiChartsGrid: ChartsGridClassKey;
}

declare module '@mui/material/styles' {
Expand Down
15 changes: 15 additions & 0 deletions packages/x-charts/src/themeAugmentation/props.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { BarElementProps } from '../BarChart/BarElement';
import { ChartsAxisProps } from '../ChartsAxis';
import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
import { ChartsClipPathProps } from '../ChartsClipPath';
import { ChartsGridProps } from '../ChartsGrid';
import { ChartsLegendProps } from '../ChartsLegend';
import { ChartsReferenceLineProps } from '../ChartsReferenceLine';
import { ChartsSurfaceProps } from '../ChartsSurface';
import { ChartsTooltipProps } from '../ChartsTooltip';
import { AreaElementProps, LineElementProps, MarkElementProps } from '../LineChart';
import { LineChartProps } from '../LineChart/LineChart';
import { PieArcLabelProps, PieArcProps } from '../PieChart';
import { ScatterProps } from '../ScatterChart/Scatter';
import { ScatterChartProps } from '../ScatterChart/ScatterChart';
import { ChartsXAxisProps, ChartsYAxisProps } from '../models/axis';
Expand All @@ -25,14 +28,26 @@ export interface ChartsComponentsPropsList {
// BarChart components
MuiBarChart: BarChartProps;
MuiBarElement: BarElementProps;

// LineChart components
MuiLineChart: LineChartProps;
MuiAreaElement: AreaElementProps;
MuiLineElement: LineElementProps;
MuiMarkElement: MarkElementProps;

// ScatterChart components
MuiScatterChart: ScatterChartProps;
MuiScatter: ScatterProps;

// PieChart components
MuiPieArc: PieArcProps;
MuiPieArcLabel: PieArcLabelProps;

// Reference line
MuiChartsReferenceLine: ChartsReferenceLineProps;

// Grid
MuiChartsGrid: ChartsGridProps;
}

declare module '@mui/material/styles' {
Expand Down
48 changes: 48 additions & 0 deletions packages/x-charts/src/themeAugmentation/themeAugmentation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,5 +188,53 @@ createTheme({
// constent: { color: 'red' },
// },
},
MuiPieArc: {
defaultProps: {
id: 'toto',
// @ts-expect-error invalid MuiMarkElement prop
someRandomProp: true,
},
styleOverrides: {
root: { backgroundColor: 'red' },
// @ts-expect-error invalid MuiMarkElement class key
constent: { color: 'red' },
},
},
MuiPieArcLabel: {
defaultProps: {
id: 'toto',
// @ts-expect-error invalid MuiMarkElement prop
someRandomProp: true,
},
styleOverrides: {
root: { backgroundColor: 'red' },
// @ts-expect-error invalid MuiMarkElement class key
constent: { color: 'red' },
},
},
MuiChartsReferenceLine: {
defaultProps: {
x: 5,
// @ts-expect-error invalid MuiMarkElement prop
someRandomProp: true,
},
styleOverrides: {
root: { backgroundColor: 'red' },
// @ts-expect-error invalid MuiMarkElement class key
constent: { color: 'red' },
},
},
MuiChartsGrid: {
defaultProps: {
vertical: true,
// @ts-expect-error invalid MuiMarkElement prop
someRandomProp: true,
},
styleOverrides: {
root: { backgroundColor: 'red' },
// @ts-expect-error invalid MuiMarkElement class key
constent: { color: 'red' },
},
},
},
});
1 change: 1 addition & 0 deletions scripts/x-charts.exports.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
{ "name": "ChartsReferenceLine", "kind": "Function" },
{ "name": "ChartsReferenceLineClasses", "kind": "Interface" },
{ "name": "ChartsReferenceLineClassKey", "kind": "TypeAlias" },
{ "name": "ChartsReferenceLineProps", "kind": "TypeAlias" },
{ "name": "ChartsSurface", "kind": "Variable" },
{ "name": "ChartsSurfaceProps", "kind": "Interface" },
{ "name": "ChartsText", "kind": "Function" },
Expand Down

0 comments on commit 28e4c7b

Please sign in to comment.