UNPKG

@mui/x-charts

Version:

The community edition of MUI X Charts components.

36 lines (34 loc) 1.57 kB
'use client'; import _extends from "@babel/runtime/helpers/esm/extends"; import _formatErrorMessage from "@mui/x-internals/formatErrorMessage"; import * as React from 'react'; import { jsx as _jsx } from "react/jsx-runtime"; export const ChartsSlotsContext = /*#__PURE__*/React.createContext(null); /** * Get the slots and slotProps from the nearest `ChartsDataProvider` or `ChartsDataProviderPro`. * @returns {ChartsSlotsContextValue} The slots and slotProps from the context. */ if (process.env.NODE_ENV !== "production") ChartsSlotsContext.displayName = "ChartsSlotsContext"; export function useChartsSlots() { const context = React.useContext(ChartsSlotsContext); if (context == null) { throw new Error(process.env.NODE_ENV !== "production" ? 'MUI X Charts: Could not find the Charts Slots context. ' + 'This happens when the component is rendered outside of a ChartsDataProvider or ChartsContainer parent component, ' + 'which means the required context is not available. ' + 'Wrap your component in a ChartsDataProvider or ChartsContainer. ' + 'This can also happen if you are bundling multiple versions of the library.' : _formatErrorMessage(11)); } return context; } export function ChartsSlotsProvider(props) { const { slots, slotProps = {}, defaultSlots, children } = props; const value = React.useMemo(() => ({ slots: _extends({}, defaultSlots, slots), slotProps }), [defaultSlots, slots, slotProps]); return /*#__PURE__*/_jsx(ChartsSlotsContext.Provider, { value: value, children: children }); }