UNPKG

3.15 kBSource Map (JSON)View Raw
1{"version":3,"file":"useUtils-cfb96ac9.js","sources":["../../src/MuiPickersUtilsProvider.tsx","../../src/_shared/hooks/useUtils.ts"],"sourcesContent":["import * as React from 'react';\nimport * as PropTypes from 'prop-types';\nimport { IUtils } from '@date-io/core/IUtils';\nimport { MaterialUiPickersDate } from './typings/date';\n\nexport const MuiPickersContext = React.createContext<IUtils<MaterialUiPickersDate> | null>(null);\n\nexport interface MuiPickersUtilsProviderProps {\n utils: any;\n children: React.ReactNode;\n locale?: any;\n libInstance?: any;\n}\n\nexport const MuiPickersUtilsProvider: React.FC<MuiPickersUtilsProviderProps> = ({\n utils: Utils,\n children,\n locale,\n libInstance,\n}) => {\n const utils = React.useMemo(() => new Utils({ locale, instance: libInstance }), [\n Utils,\n libInstance,\n locale,\n ]);\n\n return <MuiPickersContext.Provider value={utils} children={children} />;\n};\n\nMuiPickersUtilsProvider.propTypes = {\n utils: PropTypes.func.isRequired,\n locale: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),\n children: PropTypes.oneOfType([\n PropTypes.element.isRequired,\n PropTypes.arrayOf(PropTypes.element.isRequired),\n ]).isRequired,\n};\n\nexport default MuiPickersUtilsProvider;\n","import { useContext } from 'react';\nimport { IUtils } from '@date-io/core/IUtils';\nimport { MaterialUiPickersDate } from '../../typings/date';\nimport { MuiPickersContext } from '../../MuiPickersUtilsProvider';\n\nexport const checkUtils = (utils: IUtils<MaterialUiPickersDate> | null | undefined) => {\n if (!utils) {\n // tslint:disable-next-line\n throw new Error(\n '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.'\n );\n }\n};\n\nexport function useUtils() {\n const utils = useContext(MuiPickersContext);\n checkUtils(utils);\n\n return utils!;\n}\n"],"names":["MuiPickersContext","React","MuiPickersUtilsProvider","Utils","utils","children","locale","libInstance","instance","React.createElement","propTypes","PropTypes","isRequired","checkUtils","Error","useUtils","useContext"],"mappings":";;;IAKaA,iBAAiB,GAAGC,aAAA,CAA0D,IAA1D,CAA1B;AASP,AAAO,IAAMC,uBAA+D,GAAG,SAAlEA,uBAAkE,OAKzE;MAJGC,KAIH,QAJJC,KAII;MAHJC,QAGI,QAHJA,QAGI;MAFJC,MAEI,QAFJA,MAEI;MADJC,WACI,QADJA,WACI;MACEH,KAAK,GAAGH,OAAA,CAAc;WAAM,IAAIE,KAAJ,CAAU;MAAEG,MAAM,EAANA,MAAF;MAAUE,QAAQ,EAAED;KAA9B,CAAN;GAAd,EAAkE,CAC9EJ,KAD8E,EAE9EI,WAF8E,EAG9ED,MAH8E,CAAlE,CAAd;SAMOG,cAAC,iBAAD,CAAmB,QAAnB;IAA4B,KAAK,EAAEL,KAAnC;IAA0C,QAAQ,EAAEC;IAA3D;CAZK;AAeP,wCAAAH,uBAAuB,CAACQ,SAAxB,GAAoC;EAClCN,KAAK,EAAEO,IAAA,CAAeC,UADY;EAElCN,MAAM,EAAEK,SAAA,CAAoB,CAACA,MAAD,EAAmBA,MAAnB,CAApB,CAF0B;EAGlCN,QAAQ,EAAEM,SAAA,CAAoB,CAC5BA,OAAA,CAAkBC,UADU,EAE5BD,OAAA,CAAkBA,OAAA,CAAkBC,UAApC,CAF4B,CAApB,EAGPA;CANL;;ACxBO,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACT,KAAD,EAA6D;MACjF,CAACA,KAAL,EAAY;;UAEJ,IAAIU,KAAJ,CACJ,kNADI,CAAN;;CAHG;AASP,AAAO,SAASC,QAAT,GAAoB;MACnBX,KAAK,GAAGY,UAAU,CAAChB,iBAAD,CAAxB;EACAa,UAAU,CAACT,KAAD,CAAV;SAEOA,KAAP;;;;;"}
\No newline at end of file