1 | import { createContext, useMemo, createElement, useContext } from 'react';
|
2 | import { func, oneOfType, object, string, element, arrayOf } from 'prop-types';
|
3 |
|
4 | var MuiPickersContext = createContext(null);
|
5 | var MuiPickersUtilsProvider = function MuiPickersUtilsProvider(_ref) {
|
6 | var Utils = _ref.utils,
|
7 | children = _ref.children,
|
8 | locale = _ref.locale,
|
9 | libInstance = _ref.libInstance;
|
10 | var utils = useMemo(function () {
|
11 | return new Utils({
|
12 | locale: locale,
|
13 | instance: libInstance
|
14 | });
|
15 | }, [Utils, libInstance, locale]);
|
16 | return createElement(MuiPickersContext.Provider, {
|
17 | value: utils,
|
18 | children: children
|
19 | });
|
20 | };
|
21 | process.env.NODE_ENV !== "production" ? MuiPickersUtilsProvider.propTypes = {
|
22 | utils: func.isRequired,
|
23 | locale: oneOfType([object, string]),
|
24 | children: oneOfType([element.isRequired, arrayOf(element.isRequired)]).isRequired
|
25 | } : void 0;
|
26 |
|
27 | var checkUtils = function checkUtils(utils) {
|
28 | if (!utils) {
|
29 |
|
30 | throw new Error('Can not find utils in context. You either a) forgot to wrap your component tree in MuiPickersUtilsProvider; or b) mixed named and direct file imports. Recommendation: use named imports from the module index.');
|
31 | }
|
32 | };
|
33 | function useUtils() {
|
34 | var utils = useContext(MuiPickersContext);
|
35 | checkUtils(utils);
|
36 | return utils;
|
37 | }
|
38 |
|
39 | export { MuiPickersUtilsProvider as M, MuiPickersContext as a, useUtils as u };
|
40 |
|