You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/data/charts/components/components.md
+108Lines changed: 108 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,6 +91,114 @@ For example, you can use `useLineSeries()` to obtain the series of a Line Chart
91
91
92
92
{{"demo": "SeriesDemo.js"}}
93
93
94
+
## Custom slot props with TypeScript
95
+
96
+
If the custom component requires additional props to work properly, TypeScript may throw type errors.
97
+
To solve these type errors, use [module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation) to enhance the props interface.
98
+
99
+
The naming of overridable interfaces uses a pattern like this:
100
+
101
+
```js
102
+
`${slotNameInPascalCase}PropsOverrides`;
103
+
```
104
+
105
+
For example, for the `tooltip` slot, the interface name is `TooltipPropsOverrides`.
106
+
107
+
These files list every overridable interface for the Charts packages:
-[`@mui/x-charts-pro`](https://github.com/mui/mui-x/blob/-/packages/x-charts-pro/src/models/chartsSlotsComponentsPropsPro.ts) (pro-only slots: heatmap `cell`, funnel sections, pro toolbar icons, pro base slots)
// augment the props for a pro-only slot (heatmap cell)
142
+
declaremodule'@mui/x-charts-pro' {
143
+
interfaceCellPropsOverrides {
144
+
someCustomString:string;
145
+
someCustomNumber:number;
146
+
}
147
+
}
148
+
149
+
<Heatmap
150
+
xAxis={[{ data: [1, 2, 3] }]}
151
+
yAxis={[{ data: [1, 2, 3] }]}
152
+
series={[{ data: [[0, 0, 1]] }]}
153
+
slots={{
154
+
// custom component passed to the cell slot
155
+
cell: CustomHeatmapCell,
156
+
}}
157
+
slotProps={{
158
+
cell: {
159
+
// props used by CustomHeatmapCell
160
+
someCustomString: 'Hello',
161
+
someCustomNumber: 42,
162
+
},
163
+
}}
164
+
/>;
165
+
```
166
+
167
+
```tsx Premium
168
+
// augment the props for a premium-only slot (radial line highlight)
169
+
declaremodule'@mui/x-charts-premium' {
170
+
interfaceRadialLineHighlightPropsOverrides {
171
+
someCustomString:string;
172
+
someCustomNumber:number;
173
+
}
174
+
}
175
+
176
+
<RadialLineChart
177
+
series={[{ data: [1, 2, 3] }]}
178
+
radiusAxis={[{ data: [1, 2, 3] }]}
179
+
rotationAxis={[{ data: [0, 120, 240] }]}
180
+
slots={{
181
+
// custom component passed to the radialLineHighlight slot
182
+
radialLineHighlight: CustomRadialLineHighlight,
183
+
}}
184
+
slotProps={{
185
+
radialLineHighlight: {
186
+
// props used by CustomRadialLineHighlight
187
+
someCustomString: 'Hello',
188
+
someCustomNumber: 42,
189
+
},
190
+
}}
191
+
/>;
192
+
```
193
+
194
+
</codeblock>
195
+
196
+
:::info
197
+
Augmentations always target the module where the interface is **originally declared**.
198
+
The Pro and Premium tabs above augment `@mui/x-charts-pro` and `@mui/x-charts-premium` because the example slots (`cell`, `radialLineHighlight`) are declared in those packages.
199
+
Slots shared across tiers (such as `tooltip`, `legend`, `toolbar`) are declared in `@mui/x-charts` — augment them via `declare module '@mui/x-charts'` regardless of which chart you use.
200
+
:::
201
+
94
202
## HTML components
95
203
96
204
Use the `ChartsDataProvider` to access chart data from any component.
0 commit comments