@mui/x-data-grid-premium
Version:
The Premium plan edition of the MUI X Data Grid Components.
71 lines (70 loc) • 2.16 kB
JavaScript
'use client';
import _extends from "@babel/runtime/helpers/esm/extends";
import * as React from 'react';
import PropTypes from 'prop-types';
import { useGridChartsIntegrationContext } from "../hooks/utils/useGridChartIntegration.mjs";
import { EMPTY_CHART_INTEGRATION_CONTEXT_STATE } from "../hooks/features/chartsIntegration/useGridChartsIntegration.mjs";
import { jsx as _jsx } from "react/jsx-runtime";
function GridChartsRendererProxy(props) {
const {
renderer: Renderer,
id,
label,
onRender
} = props;
const {
chartStateLookup,
setChartState
} = useGridChartsIntegrationContext();
React.useEffect(() => {
if (!chartStateLookup[id]) {
// With this, the proxy "registers" the chart to the context
setChartState(id, _extends({}, EMPTY_CHART_INTEGRATION_CONTEXT_STATE, {
label
}));
}
return () => {
delete chartStateLookup[id];
};
}, [id, label, setChartState, chartStateLookup]);
if (!chartStateLookup[id]) {
return null;
}
const {
dimensions,
values,
type,
configuration
} = chartStateLookup[id];
return /*#__PURE__*/_jsx(Renderer, {
dimensions: dimensions,
values: values,
chartType: type,
configuration: configuration,
onRender: onRender
});
}
process.env.NODE_ENV !== "production" ? GridChartsRendererProxy.propTypes = {
// ----------------------------- Warning --------------------------------
// | These PropTypes are generated from the TypeScript type definitions |
// | To update them edit the TypeScript types and run "pnpm proptypes" |
// ----------------------------------------------------------------------
/**
* The unique identifier for the chart.
*/
id: PropTypes.string.isRequired,
/**
* The label for the chart.
*/
label: PropTypes.string,
/**
* Callback function called when the chart is about to be rendered.
* Use this to check and modify the chart props before it is rendered.
*/
onRender: PropTypes.func,
/**
* The renderer component that will render the chart.
*/
renderer: PropTypes.func.isRequired
} : void 0;
export { GridChartsRendererProxy };