From f41119679571055ed05b793802b47072554f4d9f Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Tue, 26 Nov 2024 23:53:30 +0100 Subject: [PATCH 1/2] [docs][charts] Fix anchorEl API page --- .../api/charts/charts-tooltip-container.json | 2 +- docs/pages/x/api/charts/charts-tooltip.json | 2 +- .../src/Heatmap/HeatmapTooltip.tsx | 26 +++---------------- .../src/ChartsTooltip/ChartsTooltip.tsx | 26 +++---------------- .../ChartsTooltip/ChartsTooltipContainer.tsx | 26 +++---------------- 5 files changed, 14 insertions(+), 68 deletions(-) diff --git a/docs/pages/x/api/charts/charts-tooltip-container.json b/docs/pages/x/api/charts/charts-tooltip-container.json index 5eae783a77e0..9cd49bc06e0b 100644 --- a/docs/pages/x/api/charts/charts-tooltip-container.json +++ b/docs/pages/x/api/charts/charts-tooltip-container.json @@ -3,7 +3,7 @@ "anchorEl": { "type": { "name": "union", - "description": "(props, propName) => {\n if (props[propName] == null) {\n return new Error(`Prop '${propName}' is required but wasn't specified`);\n }\n if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {\n return new Error(`Expected prop '${propName}' to be of type Element`);\n }\n return null;\n}
| func
| { contextElement?: (props, propName) => {\n if (props[propName] == null) {\n return null;\n }\n if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {\n return new Error(`Expected prop '${propName}' to be of type Element`);\n }\n return null;\n}, getBoundingClientRect: func }" + "description": "HTML element
| object
| func" } }, "children": { "type": { "name": "node" } }, diff --git a/docs/pages/x/api/charts/charts-tooltip.json b/docs/pages/x/api/charts/charts-tooltip.json index 551707108abd..a93f7eb3ce17 100644 --- a/docs/pages/x/api/charts/charts-tooltip.json +++ b/docs/pages/x/api/charts/charts-tooltip.json @@ -3,7 +3,7 @@ "anchorEl": { "type": { "name": "union", - "description": "(props, propName) => {\n if (props[propName] == null) {\n return new Error(`Prop '${propName}' is required but wasn't specified`);\n }\n if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {\n return new Error(`Expected prop '${propName}' to be of type Element`);\n }\n return null;\n}
| func
| { contextElement?: (props, propName) => {\n if (props[propName] == null) {\n return null;\n }\n if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {\n return new Error(`Expected prop '${propName}' to be of type Element`);\n }\n return null;\n}, getBoundingClientRect: func }" + "description": "HTML element
| object
| func" } }, "classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } }, diff --git a/packages/x-charts-pro/src/Heatmap/HeatmapTooltip.tsx b/packages/x-charts-pro/src/Heatmap/HeatmapTooltip.tsx index 2f8a4233cb4b..58d00b0fd093 100644 --- a/packages/x-charts-pro/src/Heatmap/HeatmapTooltip.tsx +++ b/packages/x-charts-pro/src/Heatmap/HeatmapTooltip.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import PropTypes from 'prop-types'; import clsx from 'clsx'; +import HTMLElementType from '@mui/utils/HTMLElementType'; import composeClasses from '@mui/utils/composeClasses'; import { ChartsTooltipPaper, @@ -131,29 +132,10 @@ HeatmapTooltip.propTypes = { * It's used to set the position of the popper. * The return value will passed as the reference object of the Popper instance. */ - anchorEl: PropTypes.oneOfType([ - (props, propName) => { - if (props[propName] == null) { - return new Error(`Prop '${propName}' is required but wasn't specified`); - } - if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) { - return new Error(`Expected prop '${propName}' to be of type Element`); - } - return null; - }, + anchorEl: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([ + HTMLElementType, + PropTypes.object, PropTypes.func, - PropTypes.shape({ - contextElement: (props, propName) => { - if (props[propName] == null) { - return null; - } - if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) { - return new Error(`Expected prop '${propName}' to be of type Element`); - } - return null; - }, - getBoundingClientRect: PropTypes.func.isRequired, - }), ]), /** * Override or extend the styles applied to the component. diff --git a/packages/x-charts/src/ChartsTooltip/ChartsTooltip.tsx b/packages/x-charts/src/ChartsTooltip/ChartsTooltip.tsx index 6173a3f6bd2f..894ba438c9d2 100644 --- a/packages/x-charts/src/ChartsTooltip/ChartsTooltip.tsx +++ b/packages/x-charts/src/ChartsTooltip/ChartsTooltip.tsx @@ -1,6 +1,7 @@ 'use client'; import * as React from 'react'; import PropTypes from 'prop-types'; +import HTMLElementType from '@mui/utils/HTMLElementType'; import { ChartsItemTooltipContent } from './ChartsItemTooltipContent'; import { ChartsAxisTooltipContent } from './ChartsAxisTooltipContent'; import { ChartsTooltipContainer, ChartsTooltipContainerProps } from './ChartsTooltipContainer'; @@ -44,29 +45,10 @@ ChartsTooltip.propTypes = { * It's used to set the position of the popper. * The return value will passed as the reference object of the Popper instance. */ - anchorEl: PropTypes.oneOfType([ - (props, propName) => { - if (props[propName] == null) { - return new Error(`Prop '${propName}' is required but wasn't specified`); - } - if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) { - return new Error(`Expected prop '${propName}' to be of type Element`); - } - return null; - }, + anchorEl: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([ + HTMLElementType, + PropTypes.object, PropTypes.func, - PropTypes.shape({ - contextElement: (props, propName) => { - if (props[propName] == null) { - return null; - } - if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) { - return new Error(`Expected prop '${propName}' to be of type Element`); - } - return null; - }, - getBoundingClientRect: PropTypes.func.isRequired, - }), ]), /** * Override or extend the styles applied to the component. diff --git a/packages/x-charts/src/ChartsTooltip/ChartsTooltipContainer.tsx b/packages/x-charts/src/ChartsTooltip/ChartsTooltipContainer.tsx index 140bfb8f25c7..d48312ba337f 100644 --- a/packages/x-charts/src/ChartsTooltip/ChartsTooltipContainer.tsx +++ b/packages/x-charts/src/ChartsTooltip/ChartsTooltipContainer.tsx @@ -1,6 +1,7 @@ 'use client'; import * as React from 'react'; import PropTypes from 'prop-types'; +import HTMLElementType from '@mui/utils/HTMLElementType'; import useLazyRef from '@mui/utils/useLazyRef'; import { styled, useThemeProps } from '@mui/material/styles'; import Popper, { PopperProps } from '@mui/material/Popper'; @@ -153,29 +154,10 @@ ChartsTooltipContainer.propTypes = { * It's used to set the position of the popper. * The return value will passed as the reference object of the Popper instance. */ - anchorEl: PropTypes.oneOfType([ - (props, propName) => { - if (props[propName] == null) { - return new Error(`Prop '${propName}' is required but wasn't specified`); - } - if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) { - return new Error(`Expected prop '${propName}' to be of type Element`); - } - return null; - }, + anchorEl: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([ + HTMLElementType, + PropTypes.object, PropTypes.func, - PropTypes.shape({ - contextElement: (props, propName) => { - if (props[propName] == null) { - return null; - } - if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) { - return new Error(`Expected prop '${propName}' to be of type Element`); - } - return null; - }, - getBoundingClientRect: PropTypes.func.isRequired, - }), ]), /** * Popper render function or node. From 067dce639821991ce54c7c52f8a6836696af76d6 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Wed, 27 Nov 2024 11:32:32 +0100 Subject: [PATCH 2/2] pnpm docs:api --- docs/pages/x/api/charts/heatmap-tooltip.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/x/api/charts/heatmap-tooltip.json b/docs/pages/x/api/charts/heatmap-tooltip.json index be37a3064b5b..b33bacabfc5f 100644 --- a/docs/pages/x/api/charts/heatmap-tooltip.json +++ b/docs/pages/x/api/charts/heatmap-tooltip.json @@ -3,7 +3,7 @@ "anchorEl": { "type": { "name": "union", - "description": "(props, propName) => {\n if (props[propName] == null) {\n return new Error(`Prop '${propName}' is required but wasn't specified`);\n }\n if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {\n return new Error(`Expected prop '${propName}' to be of type Element`);\n }\n return null;\n}
| func
| { contextElement?: (props, propName) => {\n if (props[propName] == null) {\n return null;\n }\n if (typeof props[propName] !== 'object' || props[propName].nodeType !== 1) {\n return new Error(`Expected prop '${propName}' to be of type Element`);\n }\n return null;\n}, getBoundingClientRect: func }" + "description": "HTML element
| object
| func" } }, "classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },