Skip to content

Commit

Permalink
[core] Generate slot API descriptions based on slots or `componen…
Browse files Browse the repository at this point in the history
…ts` (#10879)
  • Loading branch information
LukasTy authored Nov 2, 2023
1 parent b0cb729 commit 4295a7f
Show file tree
Hide file tree
Showing 40 changed files with 380 additions and 130 deletions.
9 changes: 8 additions & 1 deletion docs/pages/x/api/charts/area-element.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" }
},
"slots": [],
"slots": [
{
"class": null,
"name": "area",
"description": "The component that renders the root.",
"default": "AreaElementPath"
}
],
"name": "AreaElement",
"imports": [
"import { AreaElement } from '@mui/x-charts/LineChart';",
Expand Down
9 changes: 8 additions & 1 deletion docs/pages/x/api/charts/area-plot.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" }
},
"slots": [],
"slots": [
{
"class": null,
"name": "area",
"description": "The component that renders the root.",
"default": "AreaElementPath"
}
],
"name": "AreaPlot",
"imports": [
"import { AreaPlot } from '@mui/x-charts/LineChart';",
Expand Down
12 changes: 11 additions & 1 deletion docs/pages/x/api/charts/bar-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,17 @@
"default": "null"
}
},
"slots": [],
"slots": [
{ "class": null, "name": "axisContent", "description": "" },
{ "class": null, "name": "axisLabel", "description": "" },
{ "class": null, "name": "axisLine", "description": "" },
{ "class": null, "name": "axisTick", "description": "" },
{ "class": null, "name": "axisTickLabel", "description": "" },
{ "class": null, "name": "bar", "description": "" },
{ "class": null, "name": "itemContent", "description": "" },
{ "class": null, "name": "legend", "description": "" },
{ "class": null, "name": "popper", "description": "" }
],
"name": "BarChart",
"imports": [
"import { BarChart } from '@mui/x-charts/BarChart';",
Expand Down
9 changes: 8 additions & 1 deletion docs/pages/x/api/charts/bar-plot.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" }
},
"slots": [],
"slots": [
{
"class": null,
"name": "bar",
"description": "The component that renders the root.",
"default": "BarElementPath"
}
],
"name": "BarPlot",
"imports": [
"import { BarPlot } from '@mui/x-charts/BarChart';",
Expand Down
7 changes: 6 additions & 1 deletion docs/pages/x/api/charts/charts-axis.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
"default": "null"
}
},
"slots": [],
"slots": [
{ "class": null, "name": "axisLabel", "description": "" },
{ "class": null, "name": "axisLine", "description": "" },
{ "class": null, "name": "axisTick", "description": "" },
{ "class": null, "name": "axisTickLabel", "description": "" }
],
"name": "ChartsAxis",
"imports": [
"import { ChartsAxis } from '@mui/x-charts/ChartsAxis';",
Expand Down
6 changes: 5 additions & 1 deletion docs/pages/x/api/charts/charts-tooltip.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
"default": "'item'"
}
},
"slots": [],
"slots": [
{ "class": null, "name": "axisContent", "description": "" },
{ "class": null, "name": "itemContent", "description": "" },
{ "class": null, "name": "popper", "description": "" }
],
"name": "ChartsTooltip",
"imports": [
"import { ChartsTooltip } from '@mui/x-charts/ChartsTooltip';",
Expand Down
7 changes: 6 additions & 1 deletion docs/pages/x/api/charts/charts-x-axis.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@
"tickNumber": { "type": { "name": "number" } },
"tickSize": { "type": { "name": "number" }, "default": "6" }
},
"slots": [],
"slots": [
{ "class": null, "name": "axisLabel", "description": "" },
{ "class": null, "name": "axisLine", "description": "" },
{ "class": null, "name": "axisTick", "description": "" },
{ "class": null, "name": "axisTickLabel", "description": "" }
],
"name": "ChartsXAxis",
"imports": [
"import { ChartsXAxis } from '@mui/x-charts/ChartsXAxis';",
Expand Down
7 changes: 6 additions & 1 deletion docs/pages/x/api/charts/charts-y-axis.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@
"tickNumber": { "type": { "name": "number" } },
"tickSize": { "type": { "name": "number" }, "default": "6" }
},
"slots": [],
"slots": [
{ "class": null, "name": "axisLabel", "description": "" },
{ "class": null, "name": "axisLine", "description": "" },
{ "class": null, "name": "axisTick", "description": "" },
{ "class": null, "name": "axisTickLabel", "description": "" }
],
"name": "ChartsYAxis",
"imports": [
"import { ChartsYAxis } from '@mui/x-charts/ChartsYAxis';",
Expand Down
15 changes: 14 additions & 1 deletion docs/pages/x/api/charts/line-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@
"default": "null"
}
},
"slots": [],
"slots": [
{ "class": null, "name": "area", "description": "" },
{ "class": null, "name": "axisContent", "description": "" },
{ "class": null, "name": "axisLabel", "description": "" },
{ "class": null, "name": "axisLine", "description": "" },
{ "class": null, "name": "axisTick", "description": "" },
{ "class": null, "name": "axisTickLabel", "description": "" },
{ "class": null, "name": "itemContent", "description": "" },
{ "class": null, "name": "legend", "description": "" },
{ "class": null, "name": "line", "description": "" },
{ "class": null, "name": "lineHighlight", "description": "" },
{ "class": null, "name": "mark", "description": "" },
{ "class": null, "name": "popper", "description": "" }
],
"name": "LineChart",
"imports": [
"import { LineChart } from '@mui/x-charts/LineChart';",
Expand Down
9 changes: 8 additions & 1 deletion docs/pages/x/api/charts/line-element.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" }
},
"slots": [],
"slots": [
{
"class": null,
"name": "line",
"description": "The component that renders the root.",
"default": "LineElementPath"
}
],
"name": "LineElement",
"imports": [
"import { LineElement } from '@mui/x-charts/LineChart';",
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/line-highlight-plot.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" }
},
"slots": [],
"slots": [{ "class": null, "name": "lineHighlight", "description": "" }],
"name": "LineHighlightPlot",
"imports": [
"import { LineHighlightPlot } from '@mui/x-charts/LineChart';",
Expand Down
9 changes: 8 additions & 1 deletion docs/pages/x/api/charts/line-plot.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" }
},
"slots": [],
"slots": [
{
"class": null,
"name": "line",
"description": "The component that renders the root.",
"default": "LineElementPath"
}
],
"name": "LinePlot",
"imports": [
"import { LinePlot } from '@mui/x-charts/LineChart';",
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/mark-plot.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" }
},
"slots": [],
"slots": [{ "class": null, "name": "mark", "description": "" }],
"name": "MarkPlot",
"imports": [
"import { MarkPlot } from '@mui/x-charts/LineChart';",
Expand Down
5 changes: 4 additions & 1 deletion docs/pages/x/api/charts/pie-plot.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" }
},
"slots": [],
"slots": [
{ "class": null, "name": "pieArc", "description": "" },
{ "class": null, "name": "pieArcLabel", "description": "" }
],
"name": "PiePlot",
"imports": [
"import { PiePlot } from '@mui/x-charts/PieChart';",
Expand Down
12 changes: 11 additions & 1 deletion docs/pages/x/api/charts/scatter-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@
"default": "null"
}
},
"slots": [],
"slots": [
{ "class": null, "name": "axisContent", "description": "" },
{ "class": null, "name": "axisLabel", "description": "" },
{ "class": null, "name": "axisLine", "description": "" },
{ "class": null, "name": "axisTick", "description": "" },
{ "class": null, "name": "axisTickLabel", "description": "" },
{ "class": null, "name": "itemContent", "description": "" },
{ "class": null, "name": "legend", "description": "" },
{ "class": null, "name": "popper", "description": "" },
{ "class": null, "name": "scatter", "description": "" }
],
"name": "ScatterChart",
"imports": [
"import { ScatterChart } from '@mui/x-charts/ScatterChart';",
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/x/api/charts/scatter-plot.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" }
},
"slots": [],
"slots": [{ "class": null, "name": "scatter", "description": "" }],
"name": "ScatterPlot",
"imports": [
"import { ScatterPlot } from '@mui/x-charts/ScatterChart';",
Expand Down
11 changes: 10 additions & 1 deletion docs/pages/x/api/charts/spark-line-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@
}
}
},
"slots": [],
"slots": [
{ "class": null, "name": "area", "description": "" },
{ "class": null, "name": "axisContent", "description": "" },
{ "class": null, "name": "bar", "description": "" },
{ "class": null, "name": "itemContent", "description": "" },
{ "class": null, "name": "line", "description": "" },
{ "class": null, "name": "lineHighlight", "description": "" },
{ "class": null, "name": "mark", "description": "" },
{ "class": null, "name": "popper", "description": "" }
],
"name": "SparkLineChart",
"imports": [
"import { SparkLineChart } from '@mui/x-charts/SparkLineChart';",
Expand Down
51 changes: 50 additions & 1 deletion docs/pages/x/api/date-pickers/pickers-calendar-header.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
"props": {
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
"className": { "type": { "name": "string" } },
"components": {
"type": { "name": "object" },
"default": "{}",
"deprecated": true,
"deprecationInfo": "Please use <code>slots</code>."
},
"componentsProps": {
"type": { "name": "object" },
"default": "{}",
"deprecated": true,
"deprecationInfo": "Please use <code>slotProps</code>."
},
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" },
"sx": {
Expand All @@ -12,7 +24,44 @@
"additionalInfo": { "sx": true }
}
},
"slots": [],
"slots": [
{
"class": null,
"name": "leftArrowIcon",
"description": "Icon displayed in the left view switch button.",
"default": "ArrowLeft"
},
{
"class": null,
"name": "nextIconButton",
"description": "Button allowing to switch to the right view.",
"default": "IconButton"
},
{
"class": null,
"name": "previousIconButton",
"description": "Button allowing to switch to the left view.",
"default": "IconButton"
},
{
"class": null,
"name": "rightArrowIcon",
"description": "Icon displayed in the right view switch button.",
"default": "ArrowRight"
},
{
"class": null,
"name": "switchViewButton",
"description": "Button displayed to switch between different calendar views.",
"default": "IconButton"
},
{
"class": null,
"name": "switchViewIcon",
"description": "Icon displayed in the SwitchViewButton. Rotated by 180° when the open view is &#39;year&#39;.",
"default": "ArrowDropDown"
}
],
"name": "PickersCalendarHeader",
"imports": [
"import { PickersCalendarHeader } from '@mui/x-date-pickers/PickersCalendarHeader';",
Expand Down
14 changes: 10 additions & 4 deletions docs/scripts/api/buildComponentsDocumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ function extractSlots(options: {
project,
checkDeclarations: true,
shouldResolveObject: ({ name }) => {
return name === 'components';
// TODO v7: Remove the `components` fallback once `slots` is used everywhere
return name === 'slots' || name === 'components';
},
shouldInclude: ({ name, depth }) => {
// The keys allowed in the `components` prop have depth=2
return name === 'components' || depth === 2;
// TODO v7: Remove the `components` fallback once `slots` is used everywhere
return name === 'slots' || name === 'components' || depth === 2;
},
});

Expand All @@ -96,7 +98,10 @@ function extractSlots(options: {
throw new Error(`No proptypes found for \`${displayName}\``);
}

const componentsProps = props.types.find((type) => type.name === 'components')!;
const componentsProps = props.types.find(
// TODO v7: Remove the `components` fallback once `slots` is used everywhere
(type) => type.name === 'slots' || type.name === 'components',
)!;
if (!componentsProps) {
return slots;
}
Expand Down Expand Up @@ -481,7 +486,8 @@ const buildComponentDocumentation = async (options: {
/**
* Slot descriptions.
*/
if (componentApi.propDescriptions.components) {
// TODO v7: Remove the `components` fallback once `slots` is used everywhere
if (componentApi.propDescriptions.slots || componentApi.propDescriptions.components) {
const slots = extractSlots({
filename,
name: reactApi.name, // e.g. DataGrid
Expand Down
2 changes: 1 addition & 1 deletion docs/translations/api-docs/charts/area-element.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
"conditions": "faded"
}
},
"slotDescriptions": {}
"slotDescriptions": { "area": "The component that renders the root." }
}
2 changes: 1 addition & 1 deletion docs/translations/api-docs/charts/area-plot.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
}
},
"classDescriptions": {},
"slotDescriptions": {}
"slotDescriptions": { "area": "The component that renders the root." }
}
12 changes: 11 additions & 1 deletion docs/translations/api-docs/charts/bar-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,15 @@
}
},
"classDescriptions": {},
"slotDescriptions": {}
"slotDescriptions": {
"axisContent": "",
"axisLabel": "",
"axisLine": "",
"axisTick": "",
"axisTickLabel": "",
"bar": "",
"itemContent": "",
"legend": "",
"popper": ""
}
}
2 changes: 1 addition & 1 deletion docs/translations/api-docs/charts/bar-plot.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
}
},
"classDescriptions": {},
"slotDescriptions": {}
"slotDescriptions": { "bar": "The component that renders the root." }
}
2 changes: 1 addition & 1 deletion docs/translations/api-docs/charts/charts-axis.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@
"left": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the left axis" },
"right": { "description": "Styles applied to {{nodeName}}.", "nodeName": "the right axis" }
},
"slotDescriptions": {}
"slotDescriptions": { "axisLabel": "", "axisLine": "", "axisTick": "", "axisTickLabel": "" }
}
Loading

0 comments on commit 4295a7f

Please sign in to comment.