Skip to content

Commit

Permalink
[charts] Rename slots and slotProps types (#10875)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfauquette authored Nov 8, 2023
1 parent 8d55392 commit cb7dd8f
Show file tree
Hide file tree
Showing 25 changed files with 420 additions and 179 deletions.
1 change: 1 addition & 0 deletions docs/data/charts-component-api-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export default [
{ pathname: '/x/api/charts/charts-axis', title: 'ChartsAxis' },
{ pathname: '/x/api/charts/charts-axis-highlight', title: 'ChartsAxisHighlight' },
{ pathname: '/x/api/charts/charts-clip-path', title: 'ChartsClipPath' },
{ pathname: '/x/api/charts/charts-legend', title: 'ChartsLegend' },
{ pathname: '/x/api/charts/charts-reference-line', title: 'ChartsReferenceLine' },
{ pathname: '/x/api/charts/charts-tooltip', title: 'ChartsTooltip' },
{ pathname: '/x/api/charts/charts-x-axis', title: 'ChartsXAxis' },
Expand Down
13 changes: 12 additions & 1 deletion docs/data/migration/migration-charts-v6/migration-charts-v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ productId: x-charts

## Introduction

TBD
This is a reference guide for upgrading `@mui/x-charts` from v6 to v7.
The change between v6 and v7 is mostly here to match the version with other MUI X packages.
Not big breaking changes are expected.

## Start using the new release

Expand All @@ -23,3 +25,12 @@ In `package.json`, change the version of the charts package to `next`.

Since `v7` is a major release, it contains changes that affect the public API.
These changes were done for consistency, improved stability and to make room for new features.

### Renaming

Some types got renamed for coherence

| v6 | v7 |
| :------------------------------ | :--------------------- |
| ChartsTooltipSlotComponentProps | ChartsTooltipSlotProps |
| ChartsTooltipSlotsComponent | ChartsTooltipSlots |
23 changes: 23 additions & 0 deletions docs/pages/x/api/charts/charts-legend.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as React from 'react';
import ApiPage from 'docs/src/modules/components/ApiPage';
import mapApiPageTranslations from 'docs/src/modules/utils/mapApiPageTranslations';
import jsonPageContent from './charts-legend.json';

export default function Page(props) {
const { descriptions, pageContent } = props;
return <ApiPage descriptions={descriptions} pageContent={pageContent} />;
}

Page.getInitialProps = () => {
const req = require.context(
'docsx/translations/api-docs/charts',
false,
/\.\/charts-legend(-[a-z]{2})?\.json$/,
);
const descriptions = mapApiPageTranslations(req);

return {
descriptions,
pageContent: jsonPageContent,
};
};
22 changes: 22 additions & 0 deletions docs/pages/x/api/charts/charts-legend.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"props": {
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
"direction": { "type": { "name": "enum", "description": "'column'<br>&#124;&nbsp;'row'" } },
"hidden": { "type": { "name": "bool" } },
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" }
},
"slots": [{ "class": null, "name": "legend", "description": "" }],
"name": "ChartsLegend",
"imports": [
"import { ChartsLegend } from '@mui/x-charts/ChartsLegend';",
"import { ChartsLegend } from '@mui/x-charts';"
],
"styles": {
"classes": ["root", "series", "mark", "label", "column", "row"],
"globalClasses": {},
"name": "MuiChartsLegend"
},
"filename": "/packages/x-charts/src/ChartsLegend/ChartsLegend.tsx",
"demos": "<ul></ul>"
}
45 changes: 45 additions & 0 deletions docs/translations/api-docs/charts/charts-legend.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"componentDescription": "",
"propDescriptions": {
"classes": {
"description": "Override or extend the styles applied to the component.",
"deprecated": "",
"typeDescriptions": {}
},
"direction": {
"description": "The direction of the legend layout. The default depends on the chart.",
"deprecated": "",
"typeDescriptions": {}
},
"hidden": {
"description": "Set to true to hide the legend.",
"deprecated": "",
"typeDescriptions": {}
},
"slotProps": {
"description": "The props used for each component slot.",
"deprecated": "",
"typeDescriptions": {}
},
"slots": {
"description": "Overridable component slots.",
"deprecated": "",
"typeDescriptions": {}
}
},
"classDescriptions": {
"root": { "description": "Styles applied to the root element." },
"series": { "description": "Styles applied to {{nodeName}}.", "nodeName": "a series element" },
"mark": { "description": "Styles applied to {{nodeName}}.", "nodeName": "series mark element" },
"label": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the series label" },
"column": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the legend with column layout"
},
"row": {
"description": "Styles applied to {{nodeName}}.",
"nodeName": "the legend with row layout"
}
},
"slotDescriptions": { "legend": "" }
}
36 changes: 18 additions & 18 deletions packages/x-charts/src/BarChart/BarChart.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import useId from '@mui/utils/useId';
import PropTypes from 'prop-types';
import { BarPlot, BarPlotProps, BarPlotSlotComponentProps, BarPlotSlotsComponent } from './BarPlot';
import { BarPlot, BarPlotProps, BarPlotSlotProps, BarPlotSlots } from './BarPlot';
import {
ResponsiveChartContainer,
ResponsiveChartContainerProps,
Expand All @@ -13,29 +13,29 @@ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
import {
ChartsTooltip,
ChartsTooltipProps,
ChartsTooltipSlotComponentProps,
ChartsTooltipSlotsComponent,
ChartsTooltipSlotProps,
ChartsTooltipSlots,
} from '../ChartsTooltip';
import {
ChartsLegend,
ChartsLegendProps,
ChartsLegendSlotsComponent,
ChartsLegendSlotComponentProps,
ChartsLegendSlots,
ChartsLegendSlotProps,
} from '../ChartsLegend';
import { ChartsAxisHighlight, ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
import { ChartsClipPath } from '../ChartsClipPath';
import { ChartsAxisSlotsComponent, ChartsAxisSlotComponentProps } from '../models/axis';
import { ChartsAxisSlots, ChartsAxisSlotProps } from '../models/axis';

export interface BarChartSlotsComponent
extends ChartsAxisSlotsComponent,
BarPlotSlotsComponent,
ChartsLegendSlotsComponent,
ChartsTooltipSlotsComponent {}
export interface BarChartSlotComponentProps
extends ChartsAxisSlotComponentProps,
BarPlotSlotComponentProps,
ChartsLegendSlotComponentProps,
ChartsTooltipSlotComponentProps {}
export interface BarChartSlots
extends ChartsAxisSlots,
BarPlotSlots,
ChartsLegendSlots,
ChartsTooltipSlots {}
export interface BarChartSlotProps
extends ChartsAxisSlotProps,
BarPlotSlotProps,
ChartsLegendSlotProps,
ChartsTooltipSlotProps {}

export interface BarChartProps
extends Omit<ResponsiveChartContainerProps, 'series'>,
Expand All @@ -59,12 +59,12 @@ export interface BarChartProps
* Overridable component slots.
* @default {}
*/
slots?: BarChartSlotsComponent;
slots?: BarChartSlots;
/**
* The props used for each component slot.
* @default {}
*/
slotProps?: BarChartSlotComponentProps;
slotProps?: BarChartSlotProps;
layout?: BarSeriesType['layout'];
}

Expand Down
4 changes: 2 additions & 2 deletions packages/x-charts/src/BarChart/BarPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ function getBandSize({
};
}

export interface BarPlotSlotsComponent {
export interface BarPlotSlots {
bar?: React.JSXElementConstructor<BarElementProps>;
}

export interface BarPlotSlotComponentProps {
export interface BarPlotSlotProps {
bar?: Partial<BarElementProps>;
}

Expand Down
12 changes: 6 additions & 6 deletions packages/x-charts/src/ChartsAxis/ChartsAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { CartesianContext } from '../context/CartesianContextProvider';
import { ChartsXAxis } from '../ChartsXAxis';
import { ChartsYAxis } from '../ChartsYAxis';
import {
ChartsAxisSlotComponentProps,
ChartsAxisSlotsComponent,
ChartsAxisSlotProps,
ChartsAxisSlots,
ChartsXAxisProps,
ChartsYAxisProps,
} from '../models/axis';
Expand Down Expand Up @@ -40,12 +40,12 @@ export interface ChartsAxisProps {
* Overridable component slots.
* @default {}
*/
slots?: ChartsAxisSlotsComponent;
slots?: ChartsAxisSlots;
/**
* The props used for each component slot.
* @default {}
*/
slotProps?: ChartsAxisSlotComponentProps;
slotProps?: ChartsAxisSlotProps;
}

const getAxisId = (
Expand All @@ -62,8 +62,8 @@ const getAxisId = (

const mergeProps = (
axisConfig: undefined | null | string | ChartsXAxisProps | ChartsYAxisProps,
slots?: Partial<ChartsAxisSlotsComponent>,
slotProps?: Partial<ChartsAxisSlotComponentProps>,
slots?: Partial<ChartsAxisSlots>,
slotProps?: Partial<ChartsAxisSlotProps>,
) => {
return typeof axisConfig === 'object'
? {
Expand Down
Loading

0 comments on commit cb7dd8f

Please sign in to comment.