-
Notifications
You must be signed in to change notification settings - Fork 832
/
LocalizationProvider.tsx
40 lines (34 loc) · 1.17 KB
/
LocalizationProvider.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import * as React from 'react';
import * as PropTypes from 'prop-types';
import { DateIOFormats } from '@date-io/core/IUtils';
import { MuiPickersAdapter } from './_shared/hooks/useUtils';
export const MuiPickersAdapterContext = React.createContext<MuiPickersAdapter | null>(null);
export interface LocalizationProviderProps {
dateAdapter: new (...args: any) => MuiPickersAdapter;
children: React.ReactNode;
locale?: any;
dateLibInstance?: any;
dateFormats?: Partial<DateIOFormats>;
}
export const LocalizationProvider: React.FC<LocalizationProviderProps> = ({
dateAdapter: Utils,
children,
locale,
dateFormats: libFormats,
dateLibInstance: libInstance,
}) => {
const utils = React.useMemo(
() => new Utils({ locale, formats: libFormats, instance: libInstance }),
[Utils, locale, libFormats, libInstance]
);
return <MuiPickersAdapterContext.Provider value={utils} children={children} />;
};
LocalizationProvider.propTypes = {
dateAdapter: PropTypes.func.isRequired,
locale: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
/**
* Your component tree.
*/
children: PropTypes.node.isRequired,
} as any;
export default LocalizationProvider;