UNPKG

@mui/x-charts

Version:

The community edition of the charts components (MUI X).

55 lines 1.58 kB
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import _extends from "@babel/runtime/helpers/esm/extends"; import * as React from 'react'; import { jsx as _jsx } from "react/jsx-runtime"; var defaultScope = { highlighted: 'none', faded: 'none' }; export var HighlighContext = /*#__PURE__*/React.createContext({ item: null, scope: defaultScope, dispatch: function dispatch() { return null; } }); var dataReducer = function dataReducer(prevState, action) { switch (action.type) { case 'enterItem': return _extends({}, prevState, { item: action.item, scope: _extends({}, defaultScope, action.scope) }); case 'leaveItem': if (prevState.item === null || Object.keys(action.item).some(function (key) { return action.item[key] !== prevState.item[key]; })) { // The item is already something else return prevState; } return _extends({}, prevState, { item: null }); default: return prevState; } }; export function HighlightProvider(_ref) { var children = _ref.children; var _React$useReducer = React.useReducer(dataReducer, { item: null, scope: defaultScope }), _React$useReducer2 = _slicedToArray(_React$useReducer, 2), data = _React$useReducer2[0], dispatch = _React$useReducer2[1]; var value = React.useMemo(function () { return _extends({}, data, { dispatch: dispatch }); }, [data]); return /*#__PURE__*/_jsx(HighlighContext.Provider, { value: value, children: children }); }